ETRI IVCL 1.0.0
Acceleration SW Platform for Ondevice
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
ocl_SIFT.cpp File Reference
#include <iostream>
#include <algorithm>
#include "SIFT.hpp"
#include "__SIFT.hpp"
#include "ocl_SIFT.hpp"
#include "ocl_MathU.h"

Functions

void ocl_init ()
 
void ocl_extractSiftFeatures (const Mat &img, vector< KeyPoint > &keypoints, Mat &descriptor, int intervals, double sigma, double contrast_thres, int curvature_thres, bool img_dbl, int descr_width, int descr_hist_bins)
 
void ocl_convertGrayAndNormalize (const Mat &input, Mat &output)
 
Mat ocl_createInitImg (const Mat &img, double sigma)
 
void ocl_gaussianBlur (const Mat &src, Mat &output, int kSize, float *_gKernel)
 
void ocl_resizeHalf (const Mat &input, Mat &output, Size outSize)
 
void ocl_buildGaussPyramid (const Mat &base, vector< Mat > &gaussian_pyramid, int octaves, int intervals, double sigma)
 
void ocl_scaleSpaceExtrema2 (const vector< Mat > &dog_pyramid, vector< oclFeature > &feats, int octaves, int intervals, double contrast_thres, int curvature_thres)
 
void ocl_scaleSpaceExtrema (const vector< Mat > &dog_pyramid, vector< oclFeature > &feats, int octaves, int intervals, double contrast_thres, int curvature_thres)
 
bool ocl_isExtremum (float *prev_dog, float *dog, float *next_dog, int dog_width, int r, int c)
 
void ocl_derivative (float *dog, int dog_width, int r, int c, float *dD)
 
void ocl_hessian (float *prev_dog, float *dog, float *next_dog, int dog_width, int r, int c, float *H)
 
bool ocl_interpExtremum (float *prev_dog, float *dog, float *next_dog, int dog_width, int dog_height, oclFeature &feat, int idx, int r, int c, int intervals, double contrast_thres, int curvature_thres)
 
void ocl_calcFeatureScales (vector< oclFeature > &feats, double sigma, int intervals)
 
void ocl_oriHist (float *gaussian, int width, int height, float *hist, int hist_size, int r, int c, int rad, double sigma)
 
void ocl_constructGaussianPyrBuffer (vector< oclFeature > &feats, vector< Mat > &gaussian_pyramid, cl::Buffer &__feats, cl::Buffer &__gaussian_pyramid, cl::Buffer &__gauss_size_accum, cl::Buffer &__gauss_width, cl::Buffer &__gauss_height)
 
void ocl_ReleaseGaussianPyrBuffer (cl::Buffer &__feats, cl::Buffer &__gaussian_pyramid, cl::Buffer &__gauss_size_accum, cl::Buffer &__gauss_width, cl::Buffer &__gauss_height)
 
void ocl_calcFeatureOris2 (vector< oclFeature > &feats, vector< Mat > &gaussian_pyramid, int layer_per_octave, cl::Buffer &__feats, cl::Buffer &__gaussian_pyramid, cl::Buffer &__gauss_size_accum, cl::Buffer &__gauss_width, cl::Buffer &__gauss_height)
 
void ocl_calcFeatureOris (vector< oclFeature > &feats, vector< Mat > &gaussian_pyramid, int layer_per_octave)
 
void ocl_descriptorHist (Mat &gaussian, float *hist, int r, int c, float ori, float scl, int d, int n)
 
void ocl_computeDescriptors (vector< oclFeature > &feats, vector< Mat > &gaussian_pyramid, int layer_per_octave, int d, int n)
 
void ocl_normalizeDescriptor (float *descriptor, int cnt)
 
void ocl_hist2Descriptor (float *hist, oclFeature &feat, int d, int n)
 
void ocl_feats2KeyPoints (const vector< oclFeature > &feats, vector< KeyPoint > &keypoints)
 
void ocl_featsVec2Mat (const vector< oclFeature > &feats, Mat &mat)
 
void ocl_computeDescriptors2 (vector< oclFeature > &feats, vector< Mat > &gaussian_pyramid, int layer_per_octave, int d, int n, cl::Buffer &__feats, cl::Buffer &__gaussian_pyramid, cl::Buffer &__gauss_size_accum, cl::Buffer &__gauss_width, cl::Buffer &__gauss_height)
 

Variables

char platformChooser
 
vector< cl::Platform > platforms
 
cl::Context context
 
cl::CommandQueue commandQueue
 
cl::Program program
 
cl::Kernel cvtGrayNormKernel
 
cl::Kernel resizeKernel
 
cl::Kernel gaussianKernel
 
cl::Kernel scaleSpaceExtremaKernel
 
cl::Kernel calcFeatureOrisKernel
 
cl::Kernel computeDescriptorKernel
 
vector< cl::Device > devices
 
cl_int errNum
 
float * oclgKernel
 

Function Documentation

◆ ocl_buildGaussPyramid()

void ocl_buildGaussPyramid ( const Mat &  base,
vector< Mat > &  gaussian_pyramid,
int  octaves,
int  intervals,
double  sigma 
)

Build Gaussian pyramid

Parameters
basebase image for the pyramid
gaussian_pyramidreturned gaussian pyramid, size : octaves x (intervals + 3)
octavesnumber of octaves
intervalsnumber of intervals per octave
sigmasigma for gaussian smoothing

◆ ocl_calcFeatureOris()

void ocl_calcFeatureOris ( vector< oclFeature > &  feats,
vector< Mat > &  gaussian_pyramid,
int  layer_per_octave 
)

Computes a canonical orientation for each image feature (Native)

Parameters
featsfeature vector
gaussian_pyramidgaussian pyramid
layer_per_octavenumber of layers per octave

◆ ocl_calcFeatureOris2()

void ocl_calcFeatureOris2 ( vector< oclFeature > &  feats,
vector< Mat > &  gaussian_pyramid,
int  layer_per_octave,
cl::Buffer &  __feats,
cl::Buffer &  __gaussian_pyramid,
cl::Buffer &  __gauss_size_accum,
cl::Buffer &  __gauss_width,
cl::Buffer &  __gauss_height 
)

Computes a canonical orientation for each image feature (OpenCL)

Parameters
featsfeature vector
gaussian_pyramidgaussian pyramid
layer_per_octavenumber of layers per octave
__featsfeature OpenCL buffer
__gaussian_pyramidgaussian pyramid OpenCL buffer
__gauss_size_accumgaussian accumulated total size OpenCL buffer
__gauss_widthgaussian width OpenCL buffer
__gauss_heightgaussian height OpenCL buffer

◆ ocl_calcFeatureScales()

void ocl_calcFeatureScales ( vector< oclFeature > &  feats,
double  sigma,
int  intervals 
)

Calculates characteristic scale

Parameters
featsfeature vector
sigmasigma for Gaussian smoothing
intervalsintervals per octave

◆ ocl_computeDescriptors()

void ocl_computeDescriptors ( vector< oclFeature > &  feats,
vector< Mat > &  gaussian_pyramid,
int  layer_per_octave,
int  d,
int  n 
)

Computes feature descriptors (Native)

Parameters
featsfeature vector
gaussian_pyramidGaussian pyramid
layer_per_octavenumber of layers per octave in Gaussian pyramid
dwidth of 2d hist
nnumber of bins for descriptor

◆ ocl_computeDescriptors2()

void ocl_computeDescriptors2 ( vector< oclFeature > &  feats,
vector< Mat > &  gaussian_pyramid,
int  layer_per_octave,
int  d,
int  n,
cl::Buffer &  __feats,
cl::Buffer &  __gaussian_pyramid,
cl::Buffer &  __gauss_size_accum,
cl::Buffer &  __gauss_width,
cl::Buffer &  __gauss_height 
)

Computes feature descriptors (OpenCL)

Parameters
featsfeature vector
gaussian_pyramidGaussian pyramid
layer_per_octavenumber of layers per octave in Gaussian pyramid
dwidth of 2d hist
nnumber of bins for descriptor
__featsfeature OpenCL buffer
__gaussian_pyramidgaussian pyramid OpenCL buffer
__gauss_size_accumgaussian accumulated total size OpenCL buffer
__gauss_widthgaussian width OpenCL buffer
__gauss_heightgaussian height OpenCL buffer

◆ ocl_constructGaussianPyrBuffer()

void ocl_constructGaussianPyrBuffer ( vector< oclFeature > &  feats,
vector< Mat > &  gaussian_pyramid,
cl::Buffer &  __feats,
cl::Buffer &  __gaussian_pyramid,
cl::Buffer &  __gauss_size_accum,
cl::Buffer &  __gauss_width,
cl::Buffer &  __gauss_height 
)

Initialize OpenCL buffer

Parameters
featscalculated features
gaussian_pyramidcalculated gaussian pyramid
__featsfeature OpenCL buffer
__gaussian_pyramidgaussian pyramid OpenCL buffer
__gauss_size_accumgaussian accumulated total size OpenCL buffer
__gauss_widthgaussian width OpenCL buffer
__gauss_heightgaussian height OpenCL buffer

◆ ocl_convertGrayAndNormalize()

void ocl_convertGrayAndNormalize ( const Mat &  input,
Mat &  output 
)

Change 3Channel RGB image to normalized gray image.

Parameters
input3Channel RGB input image
outputnormalized grayscale output image with pixel values in 0.0f~1.0f

◆ ocl_createInitImg()

Mat ocl_createInitImg ( const Mat &  img,
double  sigma 
)

Create the initial image for builing gaussian pyramid, optionally double the image size before smoothing]

Parameters
imginput image
sigmasigma for gaussian smoothing
Returns
returned image

◆ ocl_derivative()

void ocl_derivative ( float *  dog,
int  dog_width,
int  r,
int  c,
float *  dD 
)

◆ ocl_descriptorHist()

void ocl_descriptorHist ( Mat &  gaussian,
float *  hist,
int  r,
int  c,
float  ori,
float  scl,
int  d,
int  n 
)

◆ ocl_extractSiftFeatures()

void ocl_extractSiftFeatures ( const Mat &  img,
vector< KeyPoint > &  keypoints,
Mat &  descriptor,
int  intervals = SIFT_INTERVALS,
double  sigma = SIFT_SIGMA,
double  contrast_thres = SIFT_CONTRAST_THRES,
int  curvature_thres = SIFT_CURVATURE_THRES,
bool  img_dbl = SIFT_IMG_DBL,
int  descr_width = SIFT_DESCR_WIDTH,
int  descr_hist_bins = SIFT_DESCR_HIST_BINS 
)

Detect & extract sift features for an image

Parameters
imgsource image for extract sift features : grayscale image with pixel values in 0.0f~1.0f
keypointsvector for store sift feature point
descriptorMat for store sift descriptor, each row for a keypoint
intervalsthe number of sampled intervals per octave
sigmasigma for initial gaussian smoothing
contrast_thresthreshold on keypoint contrast
curvature_thresthreshold on keypoint ratio of principle curvatures
img_dbldouble image size before pyramid construction?
descr_widthwidth of descriptor histogram array
descr_hist_binsnumber of bins per histogram in descriptor array

◆ ocl_feats2KeyPoints()

void ocl_feats2KeyPoints ( const vector< oclFeature > &  feats,
vector< KeyPoint > &  keypoints 
)

Convert features to keypoints

Parameters
featsfeatures in vector
keypointsreturned keypoint vector

◆ ocl_featsVec2Mat()

void ocl_featsVec2Mat ( const vector< oclFeature > &  feats,
Mat &  mat 
)

Convert features from vector to Mat

Parameters
featsfeatures in vector
matreturned Mat

◆ ocl_gaussianBlur()

void ocl_gaussianBlur ( const Mat &  src,
Mat &  output,
int  kSize,
float *  _gKernel 
)

Blurs an image using a Gaussian filter using padding.
Assume that dst already copy the data of src.

Parameters
srcinput image; Normalized grayscale input image
outputoutput image of the same size and type as src.
kSizewidth of the input image
gKernelGaussian kernel

◆ ocl_hessian()

void ocl_hessian ( float *  prev_dog,
float *  dog,
float *  next_dog,
int  dog_width,
int  r,
int  c,
float *  H 
)

◆ ocl_hist2Descriptor()

void ocl_hist2Descriptor ( float *  hist,
oclFeature feat,
int  d,
int  n 
)

converts 2d hist into 1d descriptor

Parameters
hist2d histogram
featfeature point
dwidth of 2d hist
nnumber of bins for descriptor

◆ ocl_init()

void ocl_init ( )

Declare for OpenCL code execution

◆ ocl_interpExtremum()

bool ocl_interpExtremum ( float *  prev_dog,
float *  dog,
float *  next_dog,
int  dog_width,
int  dog_height,
oclFeature feat,
int  idx,
int  r,
int  c,
int  intervals,
double  contrast_thres,
int  curvature_thres 
)

Interpolates a scale-space extremum's location

Parameters
prev_dogprevious Dog image
dogcurrent Dog image
next_dognext Dog image
dog_widthwidth of current Dog image
dog_heightheight of current Dog image
featreturned feature
idxindex of intervals
rpixel's image row
cpixel's image col
intervalsnumber of intervals per octave
contrast_threslow threshold on feature contrast
curvature_thresthreshold on feature curvature
Returns
is a feature?

◆ ocl_isExtremum()

bool ocl_isExtremum ( float *  prev_dog,
float *  dog,
float *  next_dog,
int  dog_width,
int  r,
int  c 
)

Determines whether a pixel is a scale-space extremum

Parameters
prev_dogprevious Dog image
dogcurrent Dog image
next_dognext Dog image
dog_widthwidth of current Dog image
rpixel's image row
cpixel's image col
Returns
is a extremum?

◆ ocl_normalizeDescriptor()

void ocl_normalizeDescriptor ( float *  descriptor,
int  cnt 
)

◆ ocl_oriHist()

void ocl_oriHist ( float *  gaussian,
int  width,
int  height,
float *  hist,
int  hist_size,
int  r,
int  c,
int  rad,
double  sigma 
)

◆ ocl_ReleaseGaussianPyrBuffer()

void ocl_ReleaseGaussianPyrBuffer ( cl::Buffer &  __feats,
cl::Buffer &  __gaussian_pyramid,
cl::Buffer &  __gauss_size_accum,
cl::Buffer &  __gauss_width,
cl::Buffer &  __gauss_height 
)

Release OpenCL buffer

Parameters
__featsfeature OpenCL buffer
__gaussian_pyramidgaussian pyramid OpenCL buffer
__gauss_size_accumgaussian accumulated total size OpenCL buffer
__gauss_widthgaussian width OpenCL buffer
__gauss_heightgaussian height OpenCL buffer

◆ ocl_resizeHalf()

void ocl_resizeHalf ( const Mat &  input,
Mat &  output,
Size  outSize 
)

Resize image using Nearest neighbor sampling. Reduce width and height in half.

Parameters
inputnormalized grayscale input image
outputresized output image
outSizeoutput image size

◆ ocl_scaleSpaceExtrema()

void ocl_scaleSpaceExtrema ( const vector< Mat > &  dog_pyramid,
vector< oclFeature > &  feats,
int  octaves,
int  intervals,
double  contrast_thres,
int  curvature_thres 
)

Detects features at extrema in DoG scale space (Native)

Parameters
dog_pyramidDog pyramid
featsDetected features with scales, origentations and descriptors to be determined
octavesnumber of octaves
intervalsnumber of intervals per octave
contrast_threslow threshold on feature contrast
curvature_threshigh threshold on feature ratio of principal curvatures

◆ ocl_scaleSpaceExtrema2()

void ocl_scaleSpaceExtrema2 ( const vector< Mat > &  dog_pyramid,
vector< oclFeature > &  feats,
int  octaves,
int  intervals,
double  contrast_thres,
int  curvature_thres 
)

Detects features at extrema in DoG scale space (OpenCL)

Parameters
dog_pyramidDog pyramid
featsDetected features with scales, origentations and descriptors to be determined
octavesnumber of octaves
intervalsnumber of intervals per octave
contrast_threslow threshold on feature contrast
curvature_threshigh threshold on feature ratio of principal curvatures

Variable Documentation

◆ calcFeatureOrisKernel

cl::Kernel calcFeatureOrisKernel

◆ commandQueue

cl::CommandQueue commandQueue

◆ computeDescriptorKernel

cl::Kernel computeDescriptorKernel

◆ context

cl::Context context

◆ cvtGrayNormKernel

cl::Kernel cvtGrayNormKernel

◆ devices

vector<cl::Device> devices

◆ errNum

cl_int errNum

◆ gaussianKernel

cl::Kernel gaussianKernel

◆ oclgKernel

float* oclgKernel

◆ platformChooser

char platformChooser

Choose Platform

0 for desktop or laptop with non-optimus
1 for laptop with optimus
2 for embedded board (e.g. Odroid-XU4)

◆ platforms

vector<cl::Platform> platforms

◆ program

cl::Program program

◆ resizeKernel

cl::Kernel resizeKernel

◆ scaleSpaceExtremaKernel

cl::Kernel scaleSpaceExtremaKernel