ad1023b1ffcfe0e33c10c561522d6068c937b119
[platform/upstream/opencv.git] / modules / objdetect / src / _lsvm_matching.h
1 /*****************************************************************************/
2 /*                      Matching procedure API                               */
3 /*****************************************************************************/
4 //
5 #ifndef _LSVM_MATCHING_H_
6 #define _LSVM_MATCHING_H_
7
8 #include "_latentsvm.h"
9 #include "_lsvm_error.h"
10 #include "_lsvm_distancetransform.h"
11 #include "_lsvm_fft.h"
12 #include "_lsvm_routine.h"
13
14 #ifdef HAVE_TBB
15 #include "_lsvm_tbbversion.h"
16 #endif
17
18 //extern "C" {
19 /*
20 // Function for convolution computation
21 //
22 // API
23 // int convolution(const filterObject *Fi, const featureMap *map, float *f);
24 // INPUT
25 // Fi                - filter object
26 // map               - feature map
27 // OUTPUT
28 // f                 - the convolution
29 // RESULT
30 // Error status
31 */
32 int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float *f);
33
34 /*
35 // Computation multiplication of FFT images
36 //
37 // API
38 // int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
39                       float *multi);
40 // INPUT
41 // fftImage1         - first fft image
42 // fftImage2         - second fft image
43 // (numRows, numColls) - image dimesions
44 // OUTPUT
45 // multi             - multiplication
46 // RESULT
47 // Error status
48 */
49 int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
50                    float *multi);
51
52 /*
53 // Turnover filter matrix for the single feature
54 //
55 // API
56 // int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
57               int p, int shift);
58 // INPUT
59 // filter            - filter weight matrix
60 // (dimX, dimY)      - dimension of filter matrix
61 // p                 - number of features
62 // shift             - number of feature (or channel)
63 // OUTPUT
64 // rot2PIFilter      - rotated matrix
65 // RESULT
66 // Error status
67 */
68 int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
69            int p, int shift);
70
71 /*
72 // Addition nullable bars to the dimension of feature map (single feature)
73 //
74 // API
75 // int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
76                        float *newFilter, int newDimX, int newDimY);
77 // INPUT
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
81 // OUTPUT
82 // newFilter         - filter matrix with nullable bars
83 // RESULT
84 // Error status
85 */
86 int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
87                     float *newFilter, int newDimX, int newDimY);
88
89 /*
90 // Computation FFT image for filter object
91 //
92 // API
93 // int getFFTImageFilterObject(const filterObject *filter,
94                                int mapDimX, int mapDimY,
95                                fftImage **image);
96 // INPUT
97 // filter        - filter object
98 // (mapDimX, mapDimY)- dimension of feature map
99 // OUTPUT
100 // image         - fft image
101 // RESULT
102 // Error status
103 */
104 int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
105                             int mapDimX, int mapDimY,
106                             CvLSVMFftImage **image);
107
108 /*
109 // Computation FFT image for feature map
110 //
111 // API
112 // int getFFTImageFeatureMap(const featureMap *map, fftImage **image);
113 // INPUT
114 // OUTPUT
115 // RESULT
116 // Error status
117 */
118 int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image);
119
120 /*
121 // Function for convolution computation using FFT
122 //
123 // API
124 // int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,
125                      int filterDimX, int filterDimY, float **conv);
126 // INPUT
127 // featMapImage      - feature map image
128 // filterImage       - filter image
129 // (filterDimX,filterDimY) - filter dimension
130 // OUTPUT
131 // conv              - the convolution
132 // RESULT
133 // Error status
134 */
135 int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,
136                   int filterDimX, int filterDimY, float **conv);
137
138 /*
139 // Computation objective function D according the original paper
140 //
141 // API
142 // int filterDispositionLevel(const filterObject *Fi, const featureMap *pyramid,
143                               float **scoreFi,
144                               int **pointsX, int **pointsY);
145 // INPUT
146 // Fi                - filter object (weights and coefficients of penalty
147                        function that are used in this routine)
148 // pyramid           - feature map
149 // OUTPUT
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
153 // RESULT
154 // Error status
155 */
156 int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid,
157                            float **scoreFi,
158                            int **pointsX, int **pointsY);
159
160 /*
161 // Computation objective function D according the original paper using FFT
162 //
163 // API
164 // int filterDispositionLevelFFT(const filterObject *Fi, const fftImage *featMapImage,
165                                  float **scoreFi,
166                                  int **pointsX, int **pointsY);
167 // INPUT
168 // Fi                - filter object (weights and coefficients of penalty
169                        function that are used in this routine)
170 // featMapImage      - FFT image of feature map
171 // OUTPUT
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
175 // RESULT
176 // Error status
177 */
178 int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage,
179                               float **scoreFi,
180                               int **pointsX, int **pointsY);
181
182 /*
183 // Computation border size for feature map
184 //
185 // API
186 // int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
187 // INPUT
188 // maxXBorder        - the largest root filter size (X-direction)
189 // maxYBorder        - the largest root filter size (Y-direction)
190 // OUTPUT
191 // bx                - border size (X-direction)
192 // by                - border size (Y-direction)
193 // RESULT
194 // Error status
195 */
196 int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
197
198 /*
199 // Addition nullable border to the feature map
200 //
201 // API
202 // int addNullableBorder(featureMap *map, int bx, int by);
203 // INPUT
204 // map               - feature map
205 // bx                - border size (X-direction)
206 // by                - border size (Y-direction)
207 // OUTPUT
208 // RESULT
209 // Error status
210 */
211 int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by);
212
213 /*
214 // Computation the maximum of the score function at the level
215 //
216 // API
217 // int maxFunctionalScoreFixedLevel(const filterObject **all_F, int n,
218                                     const featurePyramid *H,
219                                     int level, float b,
220                                     int maxXBorder, int maxYBorder,
221                                     float *score, CvPoint **points, int *kPoints,
222                                     CvPoint ***partsDisplacement);
223 // INPUT
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)
232 // OUTPUT
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)
238 // RESULT
239 // Error status
240 */
241 int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
242                                  const CvLSVMFeaturePyramid *H,
243                                  int level, float b,
244                                  int maxXBorder, int maxYBorder,
245                                  float *score, CvPoint **points, int *kPoints,
246                                  CvPoint ***partsDisplacement);
247
248 /*
249 // Computation score function at the level that exceed threshold
250 //
251 // API
252 // int thresholdFunctionalScoreFixedLevel(const filterObject **all_F, int n,
253                                           const featurePyramid *H,
254                                           int level, float b,
255                                           int maxXBorder, int maxYBorder,
256                                           float scoreThreshold,
257                                           float **score, CvPoint **points, int *kPoints,
258                                           CvPoint ***partsDisplacement);
259 // INPUT
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
269 // OUTPUT
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)
275 // RESULT
276 // Error status
277 */
278 int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
279                                        const CvLSVMFeaturePyramid *H,
280                                        int level, float b,
281                                        int maxXBorder, int maxYBorder,
282                                        float scoreThreshold,
283                                        float **score, CvPoint **points, int *kPoints,
284                                        CvPoint ***partsDisplacement);
285
286 /*
287 // Computation the maximum of the score function
288 //
289 // API
290 // int maxFunctionalScore(const filterObject **all_F, int n,
291                           const featurePyramid *H, float b,
292                           int maxXBorder, int maxYBorder,
293                           float *score,
294                           CvPoint **points, int **levels, int *kPoints,
295                           CvPoint ***partsDisplacement);
296 // INPUT
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)
304 // OUTPUT
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)
310 // RESULT
311 // Error status
312 */
313 int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
314                        const CvLSVMFeaturePyramid *H, float b,
315                        int maxXBorder, int maxYBorder,
316                        float *score,
317                        CvPoint **points, int **levels, int *kPoints,
318                        CvPoint ***partsDisplacement);
319
320 /*
321 // Computation score function that exceed threshold
322 //
323 // API
324 // int thresholdFunctionalScore(const filterObject **all_F, int n,
325                                 const featurePyramid *H,
326                                 float b,
327                                 int maxXBorder, int maxYBorder,
328                                 float scoreThreshold,
329                                 float **score,
330                                 CvPoint **points, int **levels, int *kPoints,
331                                 CvPoint ***partsDisplacement);
332 // INPUT
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
341 // OUTPUT
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)
347 // RESULT
348 // Error status
349 */
350 int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
351                              const CvLSVMFeaturePyramid *H,
352                              float b,
353                              int maxXBorder, int maxYBorder,
354                              float scoreThreshold,
355                              float **score,
356                              CvPoint **points, int **levels, int *kPoints,
357                              CvPoint ***partsDisplacement);
358
359 #ifdef HAVE_TBB
360 /*
361 // int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
362                                    const CvLSVMFeaturePyramid *H,
363                                    const float b,
364                                    const int maxXBorder, const int maxYBorder,
365                                    const float scoreThreshold,
366                                    const int threadsNum,
367                                    float **score,
368                                    CvPoint **points, int **levels, int *kPoints,
369                                    CvPoint ***partsDisplacement);
370 // INPUT
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
380 // OUTPUT
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)
386 // RESULT
387 // Error status
388 */
389 int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
390                                 const CvLSVMFeaturePyramid *H,
391                                 const float b,
392                                 const int maxXBorder, const int maxYBorder,
393                                 const float scoreThreshold,
394                                 const int threadsNum,
395                                 float **score,
396                                 CvPoint **points, int **levels, int *kPoints,
397                                 CvPoint ***partsDisplacement);
398 #endif
399
400 /*
401 // Perform non-maximum suppression algorithm (described in original paper)
402 // to remove "similar" bounding boxes
403 //
404 // API
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);
410 // INPUT
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
417 // OUTPUT
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
422 // RESULT
423 // Error status
424 */
425 #ifdef __cplusplus
426 extern "C"
427 #endif
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);
433 #ifdef __cplusplus
434 extern "C"
435 #endif
436 int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents,
437                      const int *kPartFilters,
438                      unsigned int *maxXBorder, unsigned int *maxYBorder);
439 //}
440 #endif