1 /*****************************************************************************/
2 /* Matching procedure API */
3 /*****************************************************************************/
5 #ifndef _LSVM_MATCHING_H_
6 #define _LSVM_MATCHING_H_
8 #include "_latentsvm.h"
9 #include "_lsvm_error.h"
10 #include "_lsvm_distancetransform.h"
11 #include "_lsvm_fft.h"
12 #include "_lsvm_routine.h"
15 #include "_lsvm_tbbversion.h"
20 // Function for convolution computation
23 // int convolution(const filterObject *Fi, const featureMap *map, float *f);
28 // f - the convolution
32 int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float *f);
35 // Computation multiplication of FFT images
38 // int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
41 // fftImage1 - first fft image
42 // fftImage2 - second fft image
43 // (numRows, numColls) - image dimesions
45 // multi - multiplication
49 int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
53 // Turnover filter matrix for the single feature
56 // int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
59 // filter - filter weight matrix
60 // (dimX, dimY) - dimension of filter matrix
61 // p - number of features
62 // shift - number of feature (or channel)
64 // rot2PIFilter - rotated matrix
68 int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
72 // Addition nullable bars to the dimension of feature map (single feature)
75 // int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
76 float *newFilter, int newDimX, int newDimY);
78 // rot2PIFilter - filter matrix for the single feature that was rotated
79 // (dimX, dimY) - dimension rot2PIFilter
80 // (newDimX, newDimY)- dimension of feature map for the single feature
82 // newFilter - filter matrix with nullable bars
86 int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
87 float *newFilter, int newDimX, int newDimY);
90 // Computation FFT image for filter object
93 // int getFFTImageFilterObject(const filterObject *filter,
94 int mapDimX, int mapDimY,
97 // filter - filter object
98 // (mapDimX, mapDimY)- dimension of feature map
104 int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
105 int mapDimX, int mapDimY,
106 CvLSVMFftImage **image);
109 // Computation FFT image for feature map
112 // int getFFTImageFeatureMap(const featureMap *map, fftImage **image);
118 int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image);
121 // Function for convolution computation using FFT
124 // int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,
125 int filterDimX, int filterDimY, float **conv);
127 // featMapImage - feature map image
128 // filterImage - filter image
129 // (filterDimX,filterDimY) - filter dimension
131 // conv - the convolution
135 int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,
136 int filterDimX, int filterDimY, float **conv);
139 // Computation objective function D according the original paper
142 // int filterDispositionLevel(const filterObject *Fi, const featureMap *pyramid,
144 int **pointsX, int **pointsY);
146 // Fi - filter object (weights and coefficients of penalty
147 function that are used in this routine)
148 // pyramid - feature map
150 // scoreFi - values of distance transform on the level at all positions
151 // (pointsX, pointsY)- positions that correspond to the maximum value
152 of distance transform at all grid nodes
156 int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid,
158 int **pointsX, int **pointsY);
161 // Computation objective function D according the original paper using FFT
164 // int filterDispositionLevelFFT(const filterObject *Fi, const fftImage *featMapImage,
166 int **pointsX, int **pointsY);
168 // Fi - filter object (weights and coefficients of penalty
169 function that are used in this routine)
170 // featMapImage - FFT image of feature map
172 // scoreFi - values of distance transform on the level at all positions
173 // (pointsX, pointsY)- positions that correspond to the maximum value
174 of distance transform at all grid nodes
178 int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage,
180 int **pointsX, int **pointsY);
183 // Computation border size for feature map
186 // int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
188 // maxXBorder - the largest root filter size (X-direction)
189 // maxYBorder - the largest root filter size (Y-direction)
191 // bx - border size (X-direction)
192 // by - border size (Y-direction)
196 int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
199 // Addition nullable border to the feature map
202 // int addNullableBorder(featureMap *map, int bx, int by);
205 // bx - border size (X-direction)
206 // by - border size (Y-direction)
211 int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by);
214 // Computation the maximum of the score function at the level
217 // int maxFunctionalScoreFixedLevel(const filterObject **all_F, int n,
218 const featurePyramid *H,
220 int maxXBorder, int maxYBorder,
221 float *score, CvPoint **points, int *kPoints,
222 CvPoint ***partsDisplacement);
224 // all_F - the set of filters (the first element is root filter,
225 the other - part filters)
226 // n - the number of part filters
227 // H - feature pyramid
228 // level - feature pyramid level for computation maximum score
229 // b - linear term of the score function
230 // maxXBorder - the largest root filter size (X-direction)
231 // maxYBorder - the largest root filter size (Y-direction)
233 // score - the maximum of the score function at the level
234 // points - the set of root filter positions (in the block space)
235 // levels - the set of levels
236 // kPoints - number of root filter positions
237 // partsDisplacement - displacement of part filters (in the block space)
241 int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
242 const CvLSVMFeaturePyramid *H,
244 int maxXBorder, int maxYBorder,
245 float *score, CvPoint **points, int *kPoints,
246 CvPoint ***partsDisplacement);
249 // Computation score function at the level that exceed threshold
252 // int thresholdFunctionalScoreFixedLevel(const filterObject **all_F, int n,
253 const featurePyramid *H,
255 int maxXBorder, int maxYBorder,
256 float scoreThreshold,
257 float **score, CvPoint **points, int *kPoints,
258 CvPoint ***partsDisplacement);
260 // all_F - the set of filters (the first element is root filter,
261 the other - part filters)
262 // n - the number of part filters
263 // H - feature pyramid
264 // level - feature pyramid level for computation maximum score
265 // b - linear term of the score function
266 // maxXBorder - the largest root filter size (X-direction)
267 // maxYBorder - the largest root filter size (Y-direction)
268 // scoreThreshold - score threshold
270 // score - score function at the level that exceed threshold
271 // points - the set of root filter positions (in the block space)
272 // levels - the set of levels
273 // kPoints - number of root filter positions
274 // partsDisplacement - displacement of part filters (in the block space)
278 int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
279 const CvLSVMFeaturePyramid *H,
281 int maxXBorder, int maxYBorder,
282 float scoreThreshold,
283 float **score, CvPoint **points, int *kPoints,
284 CvPoint ***partsDisplacement);
287 // Computation the maximum of the score function
290 // int maxFunctionalScore(const filterObject **all_F, int n,
291 const featurePyramid *H, float b,
292 int maxXBorder, int maxYBorder,
294 CvPoint **points, int **levels, int *kPoints,
295 CvPoint ***partsDisplacement);
297 // all_F - the set of filters (the first element is root filter,
298 the other - part filters)
299 // n - the number of part filters
300 // H - feature pyramid
301 // b - linear term of the score function
302 // maxXBorder - the largest root filter size (X-direction)
303 // maxYBorder - the largest root filter size (Y-direction)
305 // score - the maximum of the score function
306 // points - the set of root filter positions (in the block space)
307 // levels - the set of levels
308 // kPoints - number of root filter positions
309 // partsDisplacement - displacement of part filters (in the block space)
313 int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
314 const CvLSVMFeaturePyramid *H, float b,
315 int maxXBorder, int maxYBorder,
317 CvPoint **points, int **levels, int *kPoints,
318 CvPoint ***partsDisplacement);
321 // Computation score function that exceed threshold
324 // int thresholdFunctionalScore(const filterObject **all_F, int n,
325 const featurePyramid *H,
327 int maxXBorder, int maxYBorder,
328 float scoreThreshold,
330 CvPoint **points, int **levels, int *kPoints,
331 CvPoint ***partsDisplacement);
333 // all_F - the set of filters (the first element is root filter,
334 the other - part filters)
335 // n - the number of part filters
336 // H - feature pyramid
337 // b - linear term of the score function
338 // maxXBorder - the largest root filter size (X-direction)
339 // maxYBorder - the largest root filter size (Y-direction)
340 // scoreThreshold - score threshold
342 // score - score function values that exceed threshold
343 // points - the set of root filter positions (in the block space)
344 // levels - the set of levels
345 // kPoints - number of root filter positions
346 // partsDisplacement - displacement of part filters (in the block space)
350 int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
351 const CvLSVMFeaturePyramid *H,
353 int maxXBorder, int maxYBorder,
354 float scoreThreshold,
356 CvPoint **points, int **levels, int *kPoints,
357 CvPoint ***partsDisplacement);
361 // int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
362 const CvLSVMFeaturePyramid *H,
364 const int maxXBorder, const int maxYBorder,
365 const float scoreThreshold,
366 const int threadsNum,
368 CvPoint **points, int **levels, int *kPoints,
369 CvPoint ***partsDisplacement);
371 // all_F - the set of filters (the first element is root filter,
372 the other - part filters)
373 // n - the number of part filters
374 // H - feature pyramid
375 // b - linear term of the score function
376 // maxXBorder - the largest root filter size (X-direction)
377 // maxYBorder - the largest root filter size (Y-direction)
378 // scoreThreshold - score threshold
379 // threadsNum - number of threads that will be created using TBB version
381 // score - score function values that exceed threshold
382 // points - the set of root filter positions (in the block space)
383 // levels - the set of levels
384 // kPoints - number of root filter positions
385 // partsDisplacement - displacement of part filters (in the block space)
389 int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
390 const CvLSVMFeaturePyramid *H,
392 const int maxXBorder, const int maxYBorder,
393 const float scoreThreshold,
394 const int threadsNum,
396 CvPoint **points, int **levels, int *kPoints,
397 CvPoint ***partsDisplacement);
401 // Perform non-maximum suppression algorithm (described in original paper)
402 // to remove "similar" bounding boxes
405 // int nonMaximumSuppression(int numBoxes, const CvPoint *points,
406 const CvPoint *oppositePoints, const float *score,
407 float overlapThreshold,
408 int *numBoxesout, CvPoint **pointsOut,
409 CvPoint **oppositePointsOut, float **scoreOut);
411 // numBoxes - number of bounding boxes
412 // points - array of left top corner coordinates
413 // oppositePoints - array of right bottom corner coordinates
414 // score - array of detection scores
415 // overlapThreshold - threshold: bounding box is removed if overlap part
416 is greater than passed value
418 // numBoxesOut - the number of bounding boxes algorithm returns
419 // pointsOut - array of left top corner coordinates
420 // oppositePointsOut - array of right bottom corner coordinates
421 // scoreOut - array of detection scores
428 int nonMaximumSuppression(int numBoxes, const CvPoint *points,
429 const CvPoint *oppositePoints, const float *score,
430 float overlapThreshold,
431 int *numBoxesOut, CvPoint **pointsOut,
432 CvPoint **oppositePointsOut, float **scoreOut);
436 int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents,
437 const int *kPartFilters,
438 unsigned int *maxXBorder, unsigned int *maxYBorder);