Merge pull request #2887 from ilya-lavrenov:ipp_morph_fix
[platform/upstream/opencv.git] / modules / objdetect / src / _latentsvm.h
1 /*****************************************************************************/
2 /*                      Latent SVM prediction API                            */
3 /*****************************************************************************/
4
5 #ifndef _LATENTSVM_H_
6 #define _LATENTSVM_H_
7
8 #include <stdio.h>
9 #include "_lsvm_types.h"
10 #include "_lsvm_error.h"
11 #include "_lsvm_routine.h"
12
13 //////////////////////////////////////////////////////////////
14 // Building feature pyramid
15 // (pyramid constructed both contrast and non-contrast image)
16 //////////////////////////////////////////////////////////////
17
18 /*
19 // Getting feature pyramid
20 //
21 // API
22 // int getFeaturePyramid(IplImage * image, const filterObject **all_F,
23                       const int n_f,
24                       const int lambda, const int k,
25                       const int startX, const int startY,
26                       const int W, const int H, featurePyramid **maps);
27 // INPUT
28 // image             - image
29 // lambda            - resize scale
30 // k                 - size of cells
31 // startX            - X coordinate of the image rectangle to search
32 // startY            - Y coordinate of the image rectangle to search
33 // W                 - width of the image rectangle to search
34 // H                 - height of the image rectangle to search
35 // OUTPUT
36 // maps              - feature maps for all levels
37 // RESULT
38 // Error status
39 */
40 int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps);
41
42 /*
43 // Getting feature map for the selected subimage
44 //
45 // API
46 // int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
47 // INPUT
48 // image             - selected subimage
49 // k                 - size of cells
50 // OUTPUT
51 // map               - feature map
52 // RESULT
53 // Error status
54 */
55 int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMap **map);
56
57
58 /*
59 // Feature map Normalization and Truncation
60 //
61 // API
62 // int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa);
63 // INPUT
64 // map               - feature map
65 // alfa              - truncation threshold
66 // OUTPUT
67 // map               - truncated and normalized feature map
68 // RESULT
69 // Error status
70 */
71 int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa);
72
73 /*
74 // Feature map reduction
75 // In each cell we reduce dimension of the feature vector
76 // according to original paper special procedure
77 //
78 // API
79 // int PCAFeatureMaps(featureMap *map)
80 // INPUT
81 // map               - feature map
82 // OUTPUT
83 // map               - feature map
84 // RESULT
85 // Error status
86 */
87 int PCAFeatureMaps(CvLSVMFeatureMap *map);
88
89 //////////////////////////////////////////////////////////////
90 // search object
91 //////////////////////////////////////////////////////////////
92
93 /*
94 // Transformation filter displacement from the block space
95 // to the space of pixels at the initial image
96 //
97 // API
98 // int convertPoints(int countLevel, int lambda,
99                      int initialImageLevel,
100                      CvPoint *points, int *levels,
101                      CvPoint **partsDisplacement, int kPoints, int n,
102                      int maxXBorder,
103                      int maxYBorder);
104 // INPUT
105 // countLevel        - the number of levels in the feature pyramid
106 // lambda            - method parameter
107 // initialImageLevel - level of feature pyramid that contains feature map
108                        for initial image
109 // points            - the set of root filter positions (in the block space)
110 // levels            - the set of levels
111 // partsDisplacement - displacement of part filters (in the block space)
112 // kPoints           - number of root filter positions
113 // n                 - number of part filters
114 // maxXBorder        - the largest root filter size (X-direction)
115 // maxYBorder        - the largest root filter size (Y-direction)
116 // OUTPUT
117 // points            - the set of root filter positions (in the space of pixels)
118 // partsDisplacement - displacement of part filters (in the space of pixels)
119 // RESULT
120 // Error status
121 */
122 int convertPoints(int countLevel, int lambda,
123                   int initialImageLevel,
124                   CvPoint *points, int *levels,
125                   CvPoint **partsDisplacement, int kPoints, int n,
126                   int maxXBorder,
127                   int maxYBorder);
128
129 /*
130 // Elimination boxes that are outside the image boudaries
131 //
132 // API
133 // int clippingBoxes(int width, int height,
134                      CvPoint *points, int kPoints);
135 // INPUT
136 // width             - image wediht
137 // height            - image heigth
138 // points            - a set of points (coordinates of top left or
139                        bottom right corners)
140 // kPoints           - points number
141 // OUTPUT
142 // points            - updated points (if coordinates less than zero then
143                        set zero coordinate, if coordinates more than image
144                        size then set coordinates equal image size)
145 // RESULT
146 // Error status
147 */
148 #ifdef __cplusplus
149 extern "C"
150 #endif
151 int clippingBoxes(int width, int height,
152                   CvPoint *points, int kPoints);
153
154 /*
155 // Creation feature pyramid with nullable border
156 //
157 // API
158 // featurePyramid* createFeaturePyramidWithBorder(const IplImage *image,
159                                                   int maxXBorder, int maxYBorder);
160
161 // INPUT
162 // image             - initial image
163 // maxXBorder        - the largest root filter size (X-direction)
164 // maxYBorder        - the largest root filter size (Y-direction)
165 // OUTPUT
166 // RESULT
167 // Feature pyramid with nullable border
168 */
169 #ifdef __cplusplus
170 extern "C"
171 #endif
172 CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
173                                                int maxXBorder, int maxYBorder);
174
175 /*
176 // Computation of the root filter displacement and values of score function
177 //
178 // API
179 // int searchObject(const featurePyramid *H, const filterObject **all_F, int n,
180                     float b,
181                     int maxXBorder,
182                     int maxYBorder,
183                     CvPoint **points, int **levels, int *kPoints, float *score,
184                     CvPoint ***partsDisplacement);
185 // INPUT
186 // H                 - feature pyramid
187 // all_F             - the set of filters (the first element is root filter,
188                        other elements - part filters)
189 // n                 - the number of part filters
190 // b                 - linear term of the score function
191 // maxXBorder        - the largest root filter size (X-direction)
192 // maxYBorder        - the largest root filter size (Y-direction)
193 // OUTPUT
194 // points            - positions (x, y) of the upper-left corner
195                        of root filter frame
196 // levels            - levels that correspond to each position
197 // kPoints           - number of positions
198 // score             - value of the score function
199 // partsDisplacement - part filters displacement for each position
200                        of the root filter
201 // RESULT
202 // Error status
203 */
204 int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, int n,
205                  float b,
206                  int maxXBorder,
207                  int maxYBorder,
208                  CvPoint **points, int **levels, int *kPoints, float *score,
209                  CvPoint ***partsDisplacement);
210
211 /*
212 // Computation of the root filter displacement and values of score function
213 //
214 // API
215 // int searchObjectThreshold(const featurePyramid *H,
216                              const filterObject **all_F, int n,
217                              float b,
218                              int maxXBorder, int maxYBorder,
219                              float scoreThreshold,
220                              CvPoint **points, int **levels, int *kPoints,
221                              float **score, CvPoint ***partsDisplacement);
222 // INPUT
223 // H                 - feature pyramid
224 // all_F             - the set of filters (the first element is root filter,
225                        other elements - part filters)
226 // n                 - the number of part filters
227 // b                 - linear term of the score function
228 // maxXBorder        - the largest root filter size (X-direction)
229 // maxYBorder        - the largest root filter size (Y-direction)
230 // scoreThreshold    - score threshold
231 // OUTPUT
232 // points            - positions (x, y) of the upper-left corner
233                        of root filter frame
234 // levels            - levels that correspond to each position
235 // kPoints           - number of positions
236 // score             - values of the score function
237 // partsDisplacement - part filters displacement for each position
238                        of the root filter
239 // RESULT
240 // Error status
241 */
242 int searchObjectThreshold(const CvLSVMFeaturePyramid *H,
243                           const CvLSVMFilterObject **all_F, int n,
244                           float b,
245                           int maxXBorder, int maxYBorder,
246                           float scoreThreshold,
247                           CvPoint **points, int **levels, int *kPoints,
248                           float **score, CvPoint ***partsDisplacement,
249                           int numThreads CV_DEFAULT(-1));
250
251 /*
252 // Computation root filters displacement and values of score function
253 //
254 // API
255 // int searchObjectThresholdSomeComponents(const featurePyramid *H,
256                                            const filterObject **filters,
257                                            int kComponents, const int *kPartFilters,
258                                            const float *b, float scoreThreshold,
259                                            CvPoint **points, CvPoint **oppPoints,
260                                            float **score, int *kPoints);
261 // INPUT
262 // H                 - feature pyramid
263 // filters           - filters (root filter then it's part filters, etc.)
264 // kComponents       - root filters number
265 // kPartFilters      - array of part filters number for each component
266 // b                 - array of linear terms
267 // scoreThreshold    - score threshold
268 // OUTPUT
269 // points            - root filters displacement (top left corners)
270 // oppPoints         - root filters displacement (bottom right corners)
271 // score             - array of score values
272 // kPoints           - number of boxes
273 // RESULT
274 // Error status
275 */
276 #ifdef __cplusplus
277 extern "C"
278 #endif
279 int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H,
280                                         const CvLSVMFilterObject **filters,
281                                         int kComponents, const int *kPartFilters,
282                                         const float *b, float scoreThreshold,
283                                         CvPoint **points, CvPoint **oppPoints,
284                                         float **score, int *kPoints, int numThreads);
285
286 /*
287 // Compute opposite point for filter box
288 //
289 // API
290 // int getOppositePoint(CvPoint point,
291                         int sizeX, int sizeY,
292                         float step, int degree,
293                         CvPoint *oppositePoint);
294
295 // INPUT
296 // point             - coordinates of filter top left corner
297                        (in the space of pixels)
298 // (sizeX, sizeY)    - filter dimension in the block space
299 // step              - scaling factor
300 // degree            - degree of the scaling factor
301 // OUTPUT
302 // oppositePoint     - coordinates of filter bottom corner
303                        (in the space of pixels)
304 // RESULT
305 // Error status
306 */
307 int getOppositePoint(CvPoint point,
308                      int sizeX, int sizeY,
309                      float step, int degree,
310                      CvPoint *oppositePoint);
311
312 /*
313 // Drawing root filter boxes
314 //
315 // API
316 // int showRootFilterBoxes(const IplImage *image,
317                            const filterObject *filter,
318                            CvPoint *points, int *levels, int kPoints,
319                            CvScalar color, int thickness,
320                            int line_type, int shift);
321 // INPUT
322 // image             - initial image
323 // filter            - root filter object
324 // points            - a set of points
325 // levels            - levels of feature pyramid
326 // kPoints           - number of points
327 // color             - line color for each box
328 // thickness         - line thickness
329 // line_type         - line type
330 // shift             - shift
331 // OUTPUT
332 // window contained initial image and filter boxes
333 // RESULT
334 // Error status
335 */
336 int showRootFilterBoxes(IplImage *image,
337                         const CvLSVMFilterObject *filter,
338                         CvPoint *points, int *levels, int kPoints,
339                         CvScalar color, int thickness,
340                         int line_type, int shift);
341
342 /*
343 // Drawing part filter boxes
344 //
345 // API
346 // int showPartFilterBoxes(const IplImage *image,
347                            const filterObject *filter,
348                            CvPoint *points, int *levels, int kPoints,
349                            CvScalar color, int thickness,
350                            int line_type, int shift);
351 // INPUT
352 // image             - initial image
353 // filters           - a set of part filters
354 // n                 - number of part filters
355 // partsDisplacement - a set of points
356 // levels            - levels of feature pyramid
357 // kPoints           - number of foot filter positions
358 // color             - line color for each box
359 // thickness         - line thickness
360 // line_type         - line type
361 // shift             - shift
362 // OUTPUT
363 // window contained initial image and filter boxes
364 // RESULT
365 // Error status
366 */
367 int showPartFilterBoxes(IplImage *image,
368                         const CvLSVMFilterObject **filters,
369                         int n, CvPoint **partsDisplacement,
370                         int *levels, int kPoints,
371                         CvScalar color, int thickness,
372                         int line_type, int shift);
373
374 /*
375 // Drawing boxes
376 //
377 // API
378 // int showBoxes(const IplImage *img,
379                  const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
380                  CvScalar color, int thickness, int line_type, int shift);
381 // INPUT
382 // img               - initial image
383 // points            - top left corner coordinates
384 // oppositePoints    - right bottom corner coordinates
385 // kPoints           - points number
386 // color             - line color for each box
387 // thickness         - line thickness
388 // line_type         - line type
389 // shift             - shift
390 // OUTPUT
391 // RESULT
392 // Error status
393 */
394 int showBoxes(IplImage *img,
395               const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
396               CvScalar color, int thickness, int line_type, int shift);
397
398 #endif