1 /*****************************************************************************/
2 /* Latent SVM prediction API */
3 /*****************************************************************************/
9 #include "_lsvm_types.h"
10 #include "_lsvm_error.h"
11 #include "_lsvm_routine.h"
13 //////////////////////////////////////////////////////////////
14 // Building feature pyramid
15 // (pyramid constructed both contrast and non-contrast image)
16 //////////////////////////////////////////////////////////////
19 // Getting feature pyramid
22 // int getFeaturePyramid(IplImage * image, const filterObject **all_F,
24 const int lambda, const int k,
25 const int startX, const int startY,
26 const int W, const int H, featurePyramid **maps);
29 // lambda - resize scale
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
36 // maps - feature maps for all levels
40 int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps);
43 // Getting feature map for the selected subimage
46 // int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
48 // image - selected subimage
55 int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMap **map);
59 // Feature map Normalization and Truncation
62 // int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa);
65 // alfa - truncation threshold
67 // map - truncated and normalized feature map
71 int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa);
74 // Feature map reduction
75 // In each cell we reduce dimension of the feature vector
76 // according to original paper special procedure
79 // int PCAFeatureMaps(featureMap *map)
87 int PCAFeatureMaps(CvLSVMFeatureMap *map);
89 //////////////////////////////////////////////////////////////
91 //////////////////////////////////////////////////////////////
94 // Transformation filter displacement from the block space
95 // to the space of pixels at the initial image
98 // int convertPoints(int countLevel, int lambda,
99 int initialImageLevel,
100 CvPoint *points, int *levels,
101 CvPoint **partsDisplacement, int kPoints, int n,
105 // countLevel - the number of levels in the feature pyramid
106 // lambda - method parameter
107 // initialImageLevel - level of feature pyramid that contains feature map
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)
117 // points - the set of root filter positions (in the space of pixels)
118 // partsDisplacement - displacement of part filters (in the space of pixels)
122 int convertPoints(int countLevel, int lambda,
123 int initialImageLevel,
124 CvPoint *points, int *levels,
125 CvPoint **partsDisplacement, int kPoints, int n,
130 // Elimination boxes that are outside the image boudaries
133 // int clippingBoxes(int width, int height,
134 CvPoint *points, int kPoints);
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
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)
151 int clippingBoxes(int width, int height,
152 CvPoint *points, int kPoints);
155 // Creation feature pyramid with nullable border
158 // featurePyramid* createFeaturePyramidWithBorder(const IplImage *image,
159 int maxXBorder, int maxYBorder);
162 // image - initial image
163 // maxXBorder - the largest root filter size (X-direction)
164 // maxYBorder - the largest root filter size (Y-direction)
167 // Feature pyramid with nullable border
172 CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
173 int maxXBorder, int maxYBorder);
176 // Computation of the root filter displacement and values of score function
179 // int searchObject(const featurePyramid *H, const filterObject **all_F, int n,
183 CvPoint **points, int **levels, int *kPoints, float *score,
184 CvPoint ***partsDisplacement);
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)
194 // points - positions (x, y) of the upper-left corner
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
204 int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, int n,
208 CvPoint **points, int **levels, int *kPoints, float *score,
209 CvPoint ***partsDisplacement);
212 // Computation of the root filter displacement and values of score function
215 // int searchObjectThreshold(const featurePyramid *H,
216 const filterObject **all_F, int n,
218 int maxXBorder, int maxYBorder,
219 float scoreThreshold,
220 CvPoint **points, int **levels, int *kPoints,
221 float **score, CvPoint ***partsDisplacement);
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
232 // points - positions (x, y) of the upper-left corner
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
242 int searchObjectThreshold(const CvLSVMFeaturePyramid *H,
243 const CvLSVMFilterObject **all_F, int n,
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));
252 // Computation root filters displacement and values of score function
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);
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
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
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);
287 // Compute opposite point for filter box
290 // int getOppositePoint(CvPoint point,
291 int sizeX, int sizeY,
292 float step, int degree,
293 CvPoint *oppositePoint);
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
302 // oppositePoint - coordinates of filter bottom corner
303 (in the space of pixels)
307 int getOppositePoint(CvPoint point,
308 int sizeX, int sizeY,
309 float step, int degree,
310 CvPoint *oppositePoint);
313 // Drawing root filter boxes
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);
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
332 // window contained initial image and filter boxes
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);
343 // Drawing part filter boxes
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);
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
363 // window contained initial image and filter boxes
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);
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);
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
394 int showBoxes(IplImage *img,
395 const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
396 CvScalar color, int thickness, int line_type, int shift);