1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*****************************************************************************/
/* Matching procedure API */
/*****************************************************************************/
//
#ifndef _LSVM_MATCHING_H_
#define _LSVM_MATCHING_H_
#include "_latentsvm.h"
#include "_lsvm_error.h"
#include "_lsvm_distancetransform.h"
#include "_lsvm_fft.h"
#include "_lsvm_routine.h"
#ifdef HAVE_TBB
#include "_lsvm_tbbversion.h"
#endif
//extern "C" {
/*
// Function for convolution computation
//
// API
// int convolution(const filterObject *Fi, const featureMap *map, float *f);
// INPUT
// Fi - filter object
// map - feature map
// OUTPUT
// f - the convolution
// RESULT
// Error status
*/
int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float *f);
/*
// Computation multiplication of FFT images
//
// API
// int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
float *multi);
// INPUT
// fftImage1 - first fft image
// fftImage2 - second fft image
// (numRows, numColls) - image dimesions
// OUTPUT
// multi - multiplication
// RESULT
// Error status
*/
int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
float *multi);
/*
// Turnover filter matrix for the single feature
//
// API
// int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int p, int shift);
// INPUT
// filter - filter weight matrix
// (dimX, dimY) - dimension of filter matrix
// p - number of features
// shift - number of feature (or channel)
// OUTPUT
// rot2PIFilter - rotated matrix
// RESULT
// Error status
*/
int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int p, int shift);
/*
// Addition nullable bars to the dimension of feature map (single feature)
//
// API
// int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
float *newFilter, int newDimX, int newDimY);
// INPUT
// rot2PIFilter - filter matrix for the single feature that was rotated
// (dimX, dimY) - dimension rot2PIFilter
// (newDimX, newDimY)- dimension of feature map for the single feature
// OUTPUT
// newFilter - filter matrix with nullable bars
// RESULT
// Error status
*/
int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
float *newFilter, int newDimX, int newDimY);
/*
// Computation FFT image for filter object
//
// API
// int getFFTImageFilterObject(const filterObject *filter,
int mapDimX, int mapDimY,
fftImage **image);
// INPUT
// filter - filter object
// (mapDimX, mapDimY)- dimension of feature map
// OUTPUT
// image - fft image
// RESULT
// Error status
*/
int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
int mapDimX, int mapDimY,
CvLSVMFftImage **image);
/*
// Computation FFT image for feature map
//
// API
// int getFFTImageFeatureMap(const featureMap *map, fftImage **image);
// INPUT
// OUTPUT
// RESULT
// Error status
*/
int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image);
/*
// Function for convolution computation using FFT
//
// API
// int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,
int filterDimX, int filterDimY, float **conv);
// INPUT
// featMapImage - feature map image
// filterImage - filter image
// (filterDimX,filterDimY) - filter dimension
// OUTPUT
// conv - the convolution
// RESULT
// Error status
*/
int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,
int filterDimX, int filterDimY, float **conv);
/*
// Computation objective function D according the original paper
//
// API
// int filterDispositionLevel(const filterObject *Fi, const featureMap *pyramid,
float **scoreFi,
int **pointsX, int **pointsY);
// INPUT
// Fi - filter object (weights and coefficients of penalty
function that are used in this routine)
// pyramid - feature map
// OUTPUT
// scoreFi - values of distance transform on the level at all positions
// (pointsX, pointsY)- positions that correspond to the maximum value
of distance transform at all grid nodes
// RESULT
// Error status
*/
int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid,
float **scoreFi,
int **pointsX, int **pointsY);
/*
// Computation objective function D according the original paper using FFT
//
// API
// int filterDispositionLevelFFT(const filterObject *Fi, const fftImage *featMapImage,
float **scoreFi,
int **pointsX, int **pointsY);
// INPUT
// Fi - filter object (weights and coefficients of penalty
function that are used in this routine)
// featMapImage - FFT image of feature map
// OUTPUT
// scoreFi - values of distance transform on the level at all positions
// (pointsX, pointsY)- positions that correspond to the maximum value
of distance transform at all grid nodes
// RESULT
// Error status
*/
int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage,
float **scoreFi,
int **pointsX, int **pointsY);
/*
// Computation border size for feature map
//
// API
// int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
// INPUT
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// bx - border size (X-direction)
// by - border size (Y-direction)
// RESULT
// Error status
*/
int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
/*
// Addition nullable border to the feature map
//
// API
// int addNullableBorder(featureMap *map, int bx, int by);
// INPUT
// map - feature map
// bx - border size (X-direction)
// by - border size (Y-direction)
// OUTPUT
// RESULT
// Error status
*/
int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by);
/*
// Computation the maximum of the score function at the level
//
// API
// int maxFunctionalScoreFixedLevel(const filterObject **all_F, int n,
const featurePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float *score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// level - feature pyramid level for computation maximum score
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// score - the maximum of the score function at the level
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
// Error status
*/
int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float *score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
/*
// Computation score function at the level that exceed threshold
//
// API
// int thresholdFunctionalScoreFixedLevel(const filterObject **all_F, int n,
const featurePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// level - feature pyramid level for computation maximum score
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// OUTPUT
// score - score function at the level that exceed threshold
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
// Error status
*/
int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
/*
// Computation the maximum of the score function
//
// API
// int maxFunctionalScore(const filterObject **all_F, int n,
const featurePyramid *H, float b,
int maxXBorder, int maxYBorder,
float *score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// score - the maximum of the score function
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
// Error status
*/
int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, float b,
int maxXBorder, int maxYBorder,
float *score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
/*
// Computation score function that exceed threshold
//
// API
// int thresholdFunctionalScore(const filterObject **all_F, int n,
const featurePyramid *H,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// OUTPUT
// score - score function values that exceed threshold
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
// Error status
*/
int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
#ifdef HAVE_TBB
/*
// int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
const int threadsNum,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// threadsNum - number of threads that will be created using TBB version
// OUTPUT
// score - score function values that exceed threshold
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
// Error status
*/
int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
const int threadsNum,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
#endif
/*
// Perform non-maximum suppression algorithm (described in original paper)
// to remove "similar" bounding boxes
//
// API
// int nonMaximumSuppression(int numBoxes, const CvPoint *points,
const CvPoint *oppositePoints, const float *score,
float overlapThreshold,
int *numBoxesout, CvPoint **pointsOut,
CvPoint **oppositePointsOut, float **scoreOut);
// INPUT
// numBoxes - number of bounding boxes
// points - array of left top corner coordinates
// oppositePoints - array of right bottom corner coordinates
// score - array of detection scores
// overlapThreshold - threshold: bounding box is removed if overlap part
is greater than passed value
// OUTPUT
// numBoxesOut - the number of bounding boxes algorithm returns
// pointsOut - array of left top corner coordinates
// oppositePointsOut - array of right bottom corner coordinates
// scoreOut - array of detection scores
// RESULT
// Error status
*/
#ifdef __cplusplus
extern "C"
#endif
int nonMaximumSuppression(int numBoxes, const CvPoint *points,
const CvPoint *oppositePoints, const float *score,
float overlapThreshold,
int *numBoxesOut, CvPoint **pointsOut,
CvPoint **oppositePointsOut, float **scoreOut);
#ifdef __cplusplus
extern "C"
#endif
int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents,
const int *kPartFilters,
unsigned int *maxXBorder, unsigned int *maxYBorder);
//}
#endif