int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float *f)\r
{\r
int n1, m1, n2, m2, p, size, diff1, diff2;\r
- int i1, i2, j1, j2, k;\r
- float tmp_f1, tmp_f2, tmp_f3, tmp_f4;\r
- float *pMap = NULL;\r
- float *pH = NULL;\r
- \r
- n1 = map->sizeY;\r
- m1 = map->sizeX;\r
- n2 = Fi->sizeY;\r
- m2 = Fi->sizeX;\r
- p = map->numFeatures;\r
-\r
- diff1 = n1 - n2 + 1;\r
- diff2 = m1 - m2 + 1;\r
- size = diff1 * diff2;\r
- for (j1 = diff2 - 1; j1 >= 0; j1--)\r
- {\r
- \r
- for (i1 = diff1 - 1; i1 >= 0; i1--)\r
- {\r
- tmp_f1 = 0.0f;\r
- tmp_f2 = 0.0f;\r
- tmp_f3 = 0.0f;\r
- tmp_f4 = 0.0f;\r
- for (i2 = 0; i2 < n2; i2++)\r
- {\r
- for (j2 = 0; j2 < m2; j2++)\r
- {\r
- pMap = map->map + (i1 + i2) * m1 * p + (j1 + j2) * p;//sm2\r
- pH = Fi->H + (i2 * m2 + j2) * p;//sm2\r
- for (k = 0; k < p/4; k++)\r
- {\r
-\r
- tmp_f1 += pMap[4*k]*pH[4*k];//sm2\r
- tmp_f2 += pMap[4*k+1]*pH[4*k+1];\r
- tmp_f3 += pMap[4*k+2]*pH[4*k+2];\r
- tmp_f4 += pMap[4*k+3]*pH[4*k+3];\r
- }\r
- \r
- if (p%4==1)\r
- {\r
- tmp_f1 += pH[p-1]*pMap[p-1];\r
- }\r
- else\r
- {\r
- if (p%4==2)\r
- {\r
- tmp_f1 += pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];\r
- }\r
- else \r
- {\r
- if (p%4==3)\r
- {\r
- tmp_f1 += pH[p-3]*pMap[p-3] + pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];\r
- }\r
- }\r
- }\r
- \r
- }\r
- }\r
- f[i1 * diff2 + j1] = tmp_f1 + tmp_f2 + tmp_f3 + tmp_f4;//sm1\r
- }\r
- }\r
+ int i1, i2, j1, j2, k;\r
+ float tmp_f1, tmp_f2, tmp_f3, tmp_f4;\r
+ float *pMap = NULL;\r
+ float *pH = NULL;\r
+\r
+ n1 = map->sizeY;\r
+ m1 = map->sizeX;\r
+ n2 = Fi->sizeY;\r
+ m2 = Fi->sizeX;\r
+ p = map->numFeatures;\r
+\r
+ diff1 = n1 - n2 + 1;\r
+ diff2 = m1 - m2 + 1;\r
+ size = diff1 * diff2;\r
+ for (j1 = diff2 - 1; j1 >= 0; j1--)\r
+ {\r
+\r
+ for (i1 = diff1 - 1; i1 >= 0; i1--)\r
+ {\r
+ tmp_f1 = 0.0f;\r
+ tmp_f2 = 0.0f;\r
+ tmp_f3 = 0.0f;\r
+ tmp_f4 = 0.0f;\r
+ for (i2 = 0; i2 < n2; i2++)\r
+ {\r
+ for (j2 = 0; j2 < m2; j2++)\r
+ {\r
+ pMap = map->map + (i1 + i2) * m1 * p + (j1 + j2) * p;//sm2\r
+ pH = Fi->H + (i2 * m2 + j2) * p;//sm2\r
+ for (k = 0; k < p/4; k++)\r
+ {\r
+\r
+ tmp_f1 += pMap[4*k]*pH[4*k];//sm2\r
+ tmp_f2 += pMap[4*k+1]*pH[4*k+1];\r
+ tmp_f3 += pMap[4*k+2]*pH[4*k+2];\r
+ tmp_f4 += pMap[4*k+3]*pH[4*k+3];\r
+ }\r
+\r
+ if (p%4==1)\r
+ {\r
+ tmp_f1 += pH[p-1]*pMap[p-1];\r
+ }\r
+ else\r
+ {\r
+ if (p%4==2)\r
+ {\r
+ tmp_f1 += pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];\r
+ }\r
+ else\r
+ {\r
+ if (p%4==3)\r
+ {\r
+ tmp_f1 += pH[p-3]*pMap[p-3] + pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+ }\r
+ f[i1 * diff2 + j1] = tmp_f1 + tmp_f2 + tmp_f3 + tmp_f4;//sm1\r
+ }\r
+ }\r
return LATENT_SVM_OK;\r
}\r
\r
// Computation multiplication of FFT images\r
//\r
// API\r
-// int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls, \r
+// int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,\r
float *multi);\r
// INPUT\r
// fftImage1 - first fft image\r
// RESULT\r
// Error status\r
*/\r
-int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls, \r
+int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,\r
float *multi)\r
{\r
int i, index, size;\r
for (i = 0; i < size; i++)\r
{\r
index = 2 * i;\r
- multi[index] = fftImage1[index] * fftImage2[index] - \r
+ multi[index] = fftImage1[index] * fftImage2[index] -\r
fftImage1[index + 1] * fftImage2[index + 1];\r
multi[index + 1] = fftImage1[index] * fftImage2[index + 1] +\r
fftImage1[index + 1] * fftImage2[index];\r
// Turnover filter matrix for the single feature\r
//\r
// API\r
-// int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter, \r
+// int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,\r
int p, int shift);\r
// INPUT\r
// filter - filter weight matrix\r
// RESULT\r
// Error status\r
*/\r
-int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter, \r
+int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,\r
int p, int shift)\r
{\r
int i, size;\r
// Addition nullable bars to the dimension of feature map (single feature)\r
//\r
// API\r
-// int addNullableBars(float *rot2PIFilter, int dimX, int dimY, \r
+// int addNullableBars(float *rot2PIFilter, int dimX, int dimY,\r
float *newFilter, int newDimX, int newDimY);\r
// INPUT\r
// rot2PIFilter - filter matrix for the single feature that was rotated\r
// RESULT\r
// Error status\r
*/\r
-int addNullableBars(float *rot2PIFilter, int dimX, int dimY, \r
+int addNullableBars(float *rot2PIFilter, int dimX, int dimY,\r
float *newFilter, int newDimX, int newDimY)\r
{\r
int size, i, j;\r
// Computation FFT image for filter object\r
//\r
// API\r
-// int getFFTImageFilterObject(const CvLSVMFilterObject *filter, \r
+// int getFFTImageFilterObject(const CvLSVMFilterObject *filter,\r
int mapDimX, int mapDimY,\r
fftImage **image);\r
// INPUT\r
// RESULT\r
// Error status\r
*/\r
-int getFFTImageFilterObject(const CvLSVMFilterObject *filter, \r
+int getFFTImageFilterObject(const CvLSVMFilterObject *filter,\r
int mapDimX, int mapDimY,\r
CvLSVMFftImage **image)\r
{\r
int i, mapSize, filterSize, res;\r
- float *newFilter, *rot2PIFilter; \r
- \r
+ float *newFilter, *rot2PIFilter;\r
+\r
filterSize = filter->sizeX * filter->sizeY;\r
mapSize = mapDimX * mapDimY;\r
- newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));\r
- rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);\r
+\r
res = allocFFTImage(image, filter->numFeatures, mapDimX, mapDimY);\r
if (res != LATENT_SVM_OK)\r
- {\r
return res;\r
- }\r
+\r
+ newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));\r
+ rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);\r
for (i = 0; i < filter->numFeatures; i++)\r
- { \r
+ {\r
rot2PI(filter->H, filter->sizeX, filter->sizeY, rot2PIFilter, filter->numFeatures, i);\r
- addNullableBars(rot2PIFilter, filter->sizeX, filter->sizeY, \r
+ addNullableBars(rot2PIFilter, filter->sizeX, filter->sizeY,\r
newFilter, mapDimX, mapDimY);\r
fft2d(newFilter, (*image)->channels[i], mapDimY, mapDimX);\r
- } \r
+ }\r
free(newFilter);\r
free(rot2PIFilter);\r
return LATENT_SVM_OK;\r
int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image)\r
{\r
int i, j, size;\r
- float *buf; \r
+ float *buf;\r
allocFFTImage(image, map->numFeatures, map->sizeX, map->sizeY);\r
size = map->sizeX * map->sizeY;\r
buf = (float *)malloc(sizeof(float) * (2 * size));\r
\r
/*\r
// Function for convolution computation using FFT\r
-// \r
+//\r
// API\r
-// int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage, \r
+// int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,\r
int filterDimX, int filterDimY, float **conv);\r
// INPUT\r
// featMapImage - feature map image\r
// RESULT\r
// Error status\r
*/\r
-int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage, \r
+int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,\r
int filterDimX, int filterDimY, float **conv)\r
{\r
int i, j, size, diffX, diffY, index;\r
size = 2 * featMapImage->dimX * featMapImage->dimY;\r
imagesMult = (float *)malloc(sizeof(float) * size);\r
imagesMultRes = (float *)malloc(sizeof(float) * size);\r
- fftImagesMulti(featMapImage->channels[0], filterImage->channels[0], \r
+ fftImagesMulti(featMapImage->channels[0], filterImage->channels[0],\r
featMapImage->dimY, featMapImage->dimX, imagesMultRes);\r
for (i = 1; (i < (int)featMapImage->numFeatures) && (i < (int)filterImage->numFeatures); i++)\r
{\r
- fftImagesMulti(featMapImage->channels[i],filterImage->channels[i], \r
+ fftImagesMulti(featMapImage->channels[i],filterImage->channels[i],\r
featMapImage->dimY, featMapImage->dimX, imagesMult);\r
for (j = 0; j < size; j++)\r
{\r
{\r
for (j = 0; j < diffX; j++)\r
{\r
- index = (i + filterDimY - 1) * featMapImage->dimX + \r
+ index = (i + filterDimY - 1) * featMapImage->dimX +\r
(j + filterDimX - 1);\r
(*conv)[i * diffX + j] = fconv[2 * index];\r
}\r
// Computation objective function D according the original paper\r
//\r
// API\r
-// int filterDispositionLevel(const CvLSVMFilterObject *Fi, const featurePyramid *H, \r
- int level, float **scoreFi, \r
+// int filterDispositionLevel(const CvLSVMFilterObject *Fi, const featurePyramid *H,\r
+ int level, float **scoreFi,\r
int **pointsX, int **pointsY);\r
// INPUT\r
-// Fi - filter object (weights and coefficients of penalty \r
+// Fi - filter object (weights and coefficients of penalty\r
function that are used in this routine)\r
// H - feature pyramid\r
// level - level number\r
// OUTPUT\r
// scoreFi - values of distance transform on the level at all positions\r
-// (pointsX, pointsY)- positions that correspond to the maximum value \r
+// (pointsX, pointsY)- positions that correspond to the maximum value\r
of distance transform at all grid nodes\r
// RESULT\r
// Error status\r
*/\r
int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid,\r
- float **scoreFi, \r
+ float **scoreFi,\r
int **pointsX, int **pointsY)\r
{\r
int n1, m1, n2, m2, p, size, diff1, diff2;\r
- float *f; \r
+ float *f;\r
int i1, j1;\r
int res;\r
- \r
+\r
n1 = pyramid->sizeY;\r
m1 = pyramid->sizeX;\r
n2 = Fi->sizeY;\r
(*scoreFi) = NULL;\r
(*pointsX) = NULL;\r
(*pointsY) = NULL;\r
- \r
- // Processing the situation when part filter goes \r
+\r
+ // Processing the situation when part filter goes\r
// beyond the boundaries of the block set\r
if (n1 < n2 || m1 < m2)\r
{\r
size = diff1 * diff2;\r
\r
// Allocation memory for additional array (must be free in this function)\r
- f = (float *)malloc(sizeof(float) * size); \r
+ f = (float *)malloc(sizeof(float) * size);\r
// Allocation memory for arrays for saving decisions\r
(*scoreFi) = (float *)malloc(sizeof(float) * size);\r
(*pointsX) = (int *)malloc(sizeof(int) * size);\r
(*pointsY) = (int *)malloc(sizeof(int) * size);\r
\r
- // Consruction values of the array f \r
+ // Consruction values of the array f\r
// (a dot product vectors of feature map and weights of the filter)\r
- res = convolution(Fi, pyramid, f); \r
+ res = convolution(Fi, pyramid, f);\r
if (res != LATENT_SVM_OK)\r
{\r
free(f);\r
for (j1 = 0; j1 < diff2; j1++)\r
{\r
f[i1 * diff2 + j1] *= (-1);\r
- } \r
+ }\r
}\r
\r
- // Decision of the general distance transform task \r
- DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction, \r
+ // Decision of the general distance transform task\r
+ DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction,\r
(*scoreFi), (*pointsX), (*pointsY));\r
\r
// Release allocated memory\r
//\r
// API\r
// int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const fftImage *featMapImage,\r
- float **scoreFi, \r
+ float **scoreFi,\r
int **pointsX, int **pointsY);\r
// INPUT\r
-// Fi - filter object (weights and coefficients of penalty \r
+// Fi - filter object (weights and coefficients of penalty\r
function that are used in this routine)\r
// featMapImage - FFT image of feature map\r
// OUTPUT\r
// scoreFi - values of distance transform on the level at all positions\r
-// (pointsX, pointsY)- positions that correspond to the maximum value \r
+// (pointsX, pointsY)- positions that correspond to the maximum value\r
of distance transform at all grid nodes\r
// RESULT\r
// Error status\r
*/\r
int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage,\r
- float **scoreFi, \r
+ float **scoreFi,\r
int **pointsX, int **pointsY)\r
{\r
int n1, m1, n2, m2, p, size, diff1, diff2;\r
- float *f; \r
+ float *f;\r
int i1, j1;\r
int res;\r
CvLSVMFftImage *filterImage;\r
- \r
+\r
n1 = featMapImage->dimY;\r
m1 = featMapImage->dimX;\r
n2 = Fi->sizeY;\r
(*scoreFi) = NULL;\r
(*pointsX) = NULL;\r
(*pointsY) = NULL;\r
- \r
- // Processing the situation when part filter goes \r
+\r
+ // Processing the situation when part filter goes\r
// beyond the boundaries of the block set\r
if (n1 < n2 || m1 < m2)\r
{\r
// create filter image\r
getFFTImageFilterObject(Fi, featMapImage->dimX, featMapImage->dimY, &filterImage);\r
\r
- // Consruction values of the array f \r
+ // Consruction values of the array f\r
// (a dot product vectors of feature map and weights of the filter)\r
res = convFFTConv2d(featMapImage, filterImage, Fi->sizeX, Fi->sizeY, &f);\r
if (res != LATENT_SVM_OK)\r
for (j1 = 0; j1 < diff2; j1++)\r
{\r
f[i1 * diff2 + j1] *= (-1);\r
- } \r
+ }\r
}\r
\r
- // Decision of the general distance transform task \r
- DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction, \r
+ // Decision of the general distance transform task\r
+ DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction,\r
(*scoreFi), (*pointsX), (*pointsY));\r
\r
// Release allocated memory\r
{\r
for (k = 0; k < map->numFeatures; k++)\r
{\r
- new_map[(i * sizeX + j) * map->numFeatures + k] = \r
+ new_map[(i * sizeX + j) * map->numFeatures + k] =\r
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k];\r
}\r
}\r
return LATENT_SVM_OK;\r
}\r
\r
-CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map, \r
+CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,\r
int maxXBorder, int maxYBorder)\r
{\r
int bx, by;\r
int sizeX, sizeY, i, j, k;\r
CvLSVMFeatureMap *new_map;\r
- \r
+\r
computeBorderSize(maxXBorder, maxYBorder, &bx, &by);\r
sizeX = map->sizeX + 2 * bx;\r
sizeY = map->sizeY + 2 * by;\r
{\r
for (k = 0; k < map->numFeatures; k++)\r
{\r
- new_map->map[(i * sizeX + j) * map->numFeatures + k] = \r
+ new_map->map[(i * sizeX + j) * map->numFeatures + k] =\r
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k];\r
}\r
}\r
// Computation the maximum of the score function at the level\r
//\r
// API\r
-// int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, \r
- const featurePyramid *H, \r
- int level, float b, \r
- int maxXBorder, int maxYBorder, \r
+// int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,\r
+ const featurePyramid *H,\r
+ int level, float b,\r
+ int maxXBorder, int maxYBorder,\r
float *score, CvPoint **points, int *kPoints,\r
CvPoint ***partsDisplacement);\r
// INPUT\r
-// all_F - the set of filters (the first element is root filter, \r
+// all_F - the set of filters (the first element is root filter,\r
the other - part filters)\r
// n - the number of part filters\r
// H - feature pyramid\r
// RESULT\r
// Error status\r
*/\r
-int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, \r
- const CvLSVMFeaturePyramid *H, \r
- int level, float b, \r
- int maxXBorder, int maxYBorder, \r
- float *score, CvPoint **points, \r
+int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,\r
+ const CvLSVMFeaturePyramid *H,\r
+ int level, float b,\r
+ int maxXBorder, int maxYBorder,\r
+ float *score, CvPoint **points,\r
int *kPoints, CvPoint ***partsDisplacement)\r
{\r
int i, j, k, dimX, dimY, nF0, mF0, p;\r
\r
// Number of features\r
p = H->pyramid[level]->numFeatures;\r
- \r
+\r
// Getting dimension of root filter\r
nF0 = all_F[0]->sizeY;\r
mF0 = all_F[0]->sizeX;\r
- // Processing the situation when root filter goes \r
+ // Processing the situation when root filter goes\r
// beyond the boundaries of the block set\r
if (nF0 > dimY || mF0 > dimX)\r
{\r
return LATENT_SVM_FAILED_SUPERPOSITION;\r
}\r
- \r
+\r
diff1 = dimY - nF0 + 1;\r
- diff2 = dimX - mF0 + 1; \r
- \r
- // Allocation memory for saving values of function D \r
+ diff2 = dimX - mF0 + 1;\r
+\r
+ // Allocation memory for saving values of function D\r
// on the level for each part filter\r
disposition = (CvLSVMFilterDisposition **)malloc(sizeof(CvLSVMFilterDisposition *) * n);\r
for (i = 0; i < n; i++)\r
{\r
disposition[i] = (CvLSVMFilterDisposition *)malloc(sizeof(CvLSVMFilterDisposition));\r
- } \r
+ }\r
\r
// Allocation memory for values of score function for each block on the level\r
scores = (float *)malloc(sizeof(float) * (diff1 * diff2));\r
- \r
+\r
// A dot product vectors of feature map and weights of root filter\r
#ifdef FFT_CONV\r
getFFTImageFeatureMap(H->pyramid[level], &mapImage);\r
freeFFTImage(&mapImage);\r
freeFFTImage(&rootFilterImage);\r
#else\r
- // Allocation memory for saving a dot product vectors of feature map and \r
+ // Allocation memory for saving a dot product vectors of feature map and\r
// weights of root filter\r
f = (float *)malloc(sizeof(float) * (diff1 * diff2));\r
// A dot product vectors of feature map and weights of root filter\r
return res;\r
}\r
\r
- // Computation values of function D for each part filter \r
+ // Computation values of function D for each part filter\r
// on the level (level - LAMBDA)\r
partsLevel = level - LAMBDA;\r
// For feature map at the level 'partsLevel' add nullable border\r
- map = featureMapBorderPartFilter(H->pyramid[partsLevel], \r
+ map = featureMapBorderPartFilter(H->pyramid[partsLevel],\r
maxXBorder, maxYBorder);\r
- \r
+\r
// Computation the maximum of score function\r
sumScorePartDisposition = 0.0;\r
#ifdef FFT_CONV\r
getFFTImageFeatureMap(map, &mapImage);\r
for (k = 1; k <= n; k++)\r
- { \r
- filterDispositionLevelFFT(all_F[k], mapImage, \r
- &(disposition[k - 1]->score), \r
- &(disposition[k - 1]->x), \r
+ {\r
+ filterDispositionLevelFFT(all_F[k], mapImage,\r
+ &(disposition[k - 1]->score),\r
+ &(disposition[k - 1]->x),\r
&(disposition[k - 1]->y));\r
}\r
freeFFTImage(&mapImage);\r
#else\r
for (k = 1; k <= n; k++)\r
- { \r
- filterDispositionLevel(all_F[k], map, \r
- &(disposition[k - 1]->score), \r
- &(disposition[k - 1]->x), \r
+ {\r
+ filterDispositionLevel(all_F[k], map,\r
+ &(disposition[k - 1]->score),\r
+ &(disposition[k - 1]->x),\r
&(disposition[k - 1]->y));\r
}\r
#endif\r
{\r
sumScorePartDisposition = 0.0;\r
for (k = 1; k <= n; k++)\r
- { \r
+ {\r
// This condition takes on a value true\r
// when filter goes beyond the boundaries of block set\r
- if ((2 * i + all_F[k]->V.y < \r
+ if ((2 * i + all_F[k]->V.y <\r
map->sizeY - all_F[k]->sizeY + 1) &&\r
- (2 * j + all_F[k]->V.x < \r
+ (2 * j + all_F[k]->V.x <\r
map->sizeX - all_F[k]->sizeX + 1))\r
{\r
- index = (2 * i + all_F[k]->V.y) * \r
- (map->sizeX - all_F[k]->sizeX + 1) + \r
+ index = (2 * i + all_F[k]->V.y) *\r
+ (map->sizeX - all_F[k]->sizeX + 1) +\r
(2 * j + all_F[k]->V.x);\r
sumScorePartDisposition += disposition[k - 1]->score[index];\r
- } \r
+ }\r
}\r
scores[i * diff2 + j] = f[i * diff2 + j] - sumScorePartDisposition + b;\r
if (maxScore < scores[i * diff2 + j])\r
{\r
maxScore = scores[i * diff2 + j];\r
(*kPoints) = 1;\r
- } \r
- else if ((scores[i * diff2 + j] - maxScore) * \r
+ }\r
+ else if ((scores[i * diff2 + j] - maxScore) *\r
(scores[i * diff2 + j] - maxScore) <= EPS)\r
{\r
(*kPoints)++;\r
strcat(buf, tmp);\r
file = fopen(buf, "w+");\r
//*/\r
- // Construction of the set of positions for root filter \r
+ // Construction of the set of positions for root filter\r
// that correspond the maximum of score function on the level\r
(*score) = maxScore;\r
last = 0;\r
{\r
for (j = 0; j < diff2; j++)\r
{\r
- if ((scores[i * diff2 + j] - maxScore) * \r
+ if ((scores[i * diff2 + j] - maxScore) *\r
(scores[i * diff2 + j] - maxScore) <= EPS)\r
{\r
(*points)[last].y = i;\r
(*points)[last].x = j;\r
for (k = 1; k <= n; k++)\r
- { \r
- if ((2 * i + all_F[k]->V.y < \r
+ {\r
+ if ((2 * i + all_F[k]->V.y <\r
map->sizeY - all_F[k]->sizeY + 1) &&\r
- (2 * j + all_F[k]->V.x < \r
+ (2 * j + all_F[k]->V.x <\r
map->sizeX - all_F[k]->sizeX + 1))\r
{\r
- index = (2 * i + all_F[k]->V.y) * \r
- (map->sizeX - all_F[k]->sizeX + 1) + \r
+ index = (2 * i + all_F[k]->V.y) *\r
+ (map->sizeX - all_F[k]->sizeX + 1) +\r
(2 * j + all_F[k]->V.x);\r
- (*partsDisplacement)[last][k - 1].x = \r
+ (*partsDisplacement)[last][k - 1].x =\r
disposition[k - 1]->x[index];\r
- (*partsDisplacement)[last][k - 1].y = \r
+ (*partsDisplacement)[last][k - 1].y =\r
disposition[k - 1]->y[index];\r
- } \r
+ }\r
}\r
last++;\r
- } /* if ((scores[i * diff2 + j] - maxScore) * \r
+ } /* if ((scores[i * diff2 + j] - maxScore) *\r
(scores[i * diff2 + j] - maxScore) <= EPS) */\r
//fprintf(file, "%lf;", scores[i * diff2 + j]);\r
}\r
}\r
//fclose(file);\r
//free(tmp);\r
- \r
+\r
// Release allocated memory\r
for (i = 0; i < n ; i++)\r
{\r
// Computation score function at the level that exceed threshold\r
//\r
// API\r
-// int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, \r
- const featurePyramid *H, \r
- int level, float b, \r
+// int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,\r
+ const featurePyramid *H,\r
+ int level, float b,\r
int maxXBorder, int maxYBorder,\r
float scoreThreshold,\r
float **score, CvPoint **points, int *kPoints,\r
CvPoint ***partsDisplacement);\r
// INPUT\r
-// all_F - the set of filters (the first element is root filter, \r
+// all_F - the set of filters (the first element is root filter,\r
the other - part filters)\r
// n - the number of part filters\r
// H - feature pyramid\r
// RESULT\r
// Error status\r
*/\r
-int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, \r
- const CvLSVMFeaturePyramid *H, \r
- int level, float b, \r
+int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,\r
+ const CvLSVMFeaturePyramid *H,\r
+ int level, float b,\r
int maxXBorder, int maxYBorder,\r
float scoreThreshold,\r
float **score, CvPoint **points, int *kPoints,\r
\r
// Number of features\r
p = H->pyramid[level]->numFeatures;\r
- \r
+\r
// Getting dimension of root filter\r
nF0 = all_F[0]->sizeY;\r
mF0 = all_F[0]->sizeX;\r
- // Processing the situation when root filter goes \r
+ // Processing the situation when root filter goes\r
// beyond the boundaries of the block set\r
if (nF0 > dimY || mF0 > dimX)\r
{\r
return LATENT_SVM_FAILED_SUPERPOSITION;\r
}\r
- \r
+\r
diff1 = dimY - nF0 + 1;\r
- diff2 = dimX - mF0 + 1; \r
- \r
- // Allocation memory for saving values of function D \r
+ diff2 = dimX - mF0 + 1;\r
+\r
+ // Allocation memory for saving values of function D\r
// on the level for each part filter\r
disposition = (CvLSVMFilterDisposition **)malloc(sizeof(CvLSVMFilterDisposition *) * n);\r
for (i = 0; i < n; i++)\r
{\r
disposition[i] = (CvLSVMFilterDisposition *)malloc(sizeof(CvLSVMFilterDisposition));\r
- } \r
+ }\r
\r
// Allocation memory for values of score function for each block on the level\r
scores = (float *)malloc(sizeof(float) * (diff1 * diff2));\r
freeFFTImage(&mapImage);\r
freeFFTImage(&rootFilterImage);\r
#else\r
- // Allocation memory for saving a dot product vectors of feature map and \r
+ // Allocation memory for saving a dot product vectors of feature map and\r
// weights of root filter\r
f = (float *)malloc(sizeof(float) * (diff1 * diff2));\r
res = convolution(all_F[0], H->pyramid[level], f);\r
return res;\r
}\r
\r
- // Computation values of function D for each part filter \r
+ // Computation values of function D for each part filter\r
// on the level (level - LAMBDA)\r
partsLevel = level - LAMBDA;\r
// For feature map at the level 'partsLevel' add nullable border\r
- map = featureMapBorderPartFilter(H->pyramid[partsLevel], \r
+ map = featureMapBorderPartFilter(H->pyramid[partsLevel],\r
maxXBorder, maxYBorder);\r
- \r
+\r
// Computation the maximum of score function\r
sumScorePartDisposition = 0.0;\r
#ifdef FFT_CONV\r
getFFTImageFeatureMap(map, &mapImage);\r
for (k = 1; k <= n; k++)\r
- { \r
- filterDispositionLevelFFT(all_F[k], mapImage, \r
- &(disposition[k - 1]->score), \r
- &(disposition[k - 1]->x), \r
+ {\r
+ filterDispositionLevelFFT(all_F[k], mapImage,\r
+ &(disposition[k - 1]->score),\r
+ &(disposition[k - 1]->x),\r
&(disposition[k - 1]->y));\r
}\r
freeFFTImage(&mapImage);\r
#else\r
for (k = 1; k <= n; k++)\r
- { \r
- filterDispositionLevel(all_F[k], map, \r
- &(disposition[k - 1]->score), \r
- &(disposition[k - 1]->x), \r
+ {\r
+ filterDispositionLevel(all_F[k], map,\r
+ &(disposition[k - 1]->score),\r
+ &(disposition[k - 1]->x),\r
&(disposition[k - 1]->y));\r
}\r
#endif\r
{\r
sumScorePartDisposition = 0.0;\r
for (k = 1; k <= n; k++)\r
- { \r
+ {\r
// This condition takes on a value true\r
// when filter goes beyond the boundaries of block set\r
- if ((2 * i + all_F[k]->V.y < \r
+ if ((2 * i + all_F[k]->V.y <\r
map->sizeY - all_F[k]->sizeY + 1) &&\r
- (2 * j + all_F[k]->V.x < \r
+ (2 * j + all_F[k]->V.x <\r
map->sizeX - all_F[k]->sizeX + 1))\r
{\r
- index = (2 * i + all_F[k]->V.y) * \r
- (map->sizeX - all_F[k]->sizeX + 1) + \r
+ index = (2 * i + all_F[k]->V.y) *\r
+ (map->sizeX - all_F[k]->sizeX + 1) +\r
(2 * j + all_F[k]->V.x);\r
sumScorePartDisposition += disposition[k - 1]->score[index];\r
- } \r
+ }\r
}\r
scores[i * diff2 + j] = f[i * diff2 + j] - sumScorePartDisposition + b;\r
- if (scores[i * diff2 + j] > scoreThreshold) \r
+ if (scores[i * diff2 + j] > scoreThreshold)\r
{\r
(*kPoints)++;\r
}\r
strcat(buf, tmp);\r
file = fopen(buf, "w+");\r
//*/\r
- // Construction of the set of positions for root filter \r
+ // Construction of the set of positions for root filter\r
// that correspond score function on the level that exceed threshold\r
(*score) = (float *)malloc(sizeof(float) * (*kPoints));\r
last = 0;\r
{\r
for (j = 0; j < diff2; j++)\r
{\r
- if (scores[i * diff2 + j] > scoreThreshold) \r
+ if (scores[i * diff2 + j] > scoreThreshold)\r
{\r
(*score)[last] = scores[i * diff2 + j];\r
(*points)[last].y = i;\r
(*points)[last].x = j;\r
for (k = 1; k <= n; k++)\r
- { \r
- if ((2 * i + all_F[k]->V.y < \r
+ {\r
+ if ((2 * i + all_F[k]->V.y <\r
map->sizeY - all_F[k]->sizeY + 1) &&\r
- (2 * j + all_F[k]->V.x < \r
+ (2 * j + all_F[k]->V.x <\r
map->sizeX - all_F[k]->sizeX + 1))\r
{\r
- index = (2 * i + all_F[k]->V.y) * \r
- (map->sizeX - all_F[k]->sizeX + 1) + \r
+ index = (2 * i + all_F[k]->V.y) *\r
+ (map->sizeX - all_F[k]->sizeX + 1) +\r
(2 * j + all_F[k]->V.x);\r
- (*partsDisplacement)[last][k - 1].x = \r
+ (*partsDisplacement)[last][k - 1].x =\r
disposition[k - 1]->x[index];\r
- (*partsDisplacement)[last][k - 1].y = \r
+ (*partsDisplacement)[last][k - 1].y =\r
disposition[k - 1]->y[index];\r
- } \r
+ }\r
}\r
last++;\r
}\r
// Computation the maximum of the score function\r
//\r
// API\r
-// int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, \r
- const featurePyramid *H, float b, \r
+// int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,\r
+ const featurePyramid *H, float b,\r
int maxXBorder, int maxYBorder,\r
- float *score, \r
+ float *score,\r
CvPoint **points, int **levels, int *kPoints,\r
CvPoint ***partsDisplacement);\r
// INPUT\r
-// all_F - the set of filters (the first element is root filter, \r
+// all_F - the set of filters (the first element is root filter,\r
the other - part filters)\r
// n - the number of part filters\r
// H - feature pyramid\r
// RESULT\r
// Error status\r
*/\r
-int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, \r
- const CvLSVMFeaturePyramid *H, float b, \r
+int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,\r
+ const CvLSVMFeaturePyramid *H, float b,\r
int maxXBorder, int maxYBorder,\r
- float *score, \r
+ float *score,\r
CvPoint **points, int **levels, int *kPoints,\r
CvPoint ***partsDisplacement)\r
{\r
int l, i, j, k, s, f, level, numLevels;\r
float *tmpScore;\r
CvPoint ***tmpPoints;\r
- CvPoint ****tmpPartsDisplacement; \r
+ CvPoint ****tmpPartsDisplacement;\r
int *tmpKPoints;\r
float maxScore;\r
int res;\r
/* DEBUG\r
FILE *file;\r
//*/\r
- \r
+\r
// Computation the number of levels for seaching object,\r
// first lambda-levels are used for computation values\r
// of score function for each position of root filter\r
numLevels = H->numLevels - LAMBDA;\r
- \r
+\r
// Allocation memory for maximum value of score function for each level\r
- tmpScore = (float *)malloc(sizeof(float) * numLevels); \r
- // Allocation memory for the set of points that corresponds \r
+ tmpScore = (float *)malloc(sizeof(float) * numLevels);\r
+ // Allocation memory for the set of points that corresponds\r
// to the maximum of score function\r
tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels);\r
for (i = 0; i < numLevels; i++)\r
{\r
tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **));\r
}\r
- // Number of points that corresponds to the maximum \r
+ // Number of points that corresponds to the maximum\r
// of score function on each level\r
tmpKPoints = (int *)malloc(sizeof(int) * numLevels);\r
for (i = 0; i < numLevels; i++)\r
}\r
\r
// Set current value of the maximum of score function\r
- res = maxFunctionalScoreFixedLevel(all_F, n, H, LAMBDA, b, \r
+ res = maxFunctionalScoreFixedLevel(all_F, n, H, LAMBDA, b,\r
maxXBorder, maxYBorder,\r
- &(tmpScore[0]), \r
- tmpPoints[0], \r
- &(tmpKPoints[0]), \r
+ &(tmpScore[0]),\r
+ tmpPoints[0],\r
+ &(tmpKPoints[0]),\r
tmpPartsDisplacement[0]);\r
maxScore = tmpScore[0];\r
(*kPoints) = tmpKPoints[0];\r
// and getting the maximum on all levels\r
/* DEBUG: maxScore\r
file = fopen("maxScore.csv", "w+");\r
- fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]); \r
+ fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);\r
//*/\r
for (l = LAMBDA + 1; l < H->numLevels; l++)\r
- { \r
+ {\r
k = l - LAMBDA;\r
res = maxFunctionalScoreFixedLevel(all_F, n, H, l, b,\r
maxXBorder, maxYBorder,\r
- &(tmpScore[k]), \r
- tmpPoints[k], \r
- &(tmpKPoints[k]), \r
- tmpPartsDisplacement[k]); \r
- //fprintf(file, "%i;%lf;\n", l, tmpScore[k]); \r
+ &(tmpScore[k]),\r
+ tmpPoints[k],\r
+ &(tmpKPoints[k]),\r
+ tmpPartsDisplacement[k]);\r
+ //fprintf(file, "%i;%lf;\n", l, tmpScore[k]);\r
if (res != LATENT_SVM_OK)\r
{\r
continue;\r
// Allocation memory for levels\r
(*levels) = (int *)malloc(sizeof(int) * (*kPoints));\r
// Allocation memory for the set of points\r
- (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); \r
+ (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints));\r
// Allocation memory for parts displacement\r
(*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints));\r
\r
if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS)\r
{\r
// Computation the number of level\r
- level = i + LAMBDA; \r
+ level = i + LAMBDA;\r
\r
// Addition a set of points\r
f += tmpKPoints[i];\r
(*levels)[j] = level;\r
(*points)[j] = (*tmpPoints[i])[j - s];\r
(*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s];\r
- } \r
+ }\r
s = f;\r
} /* if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS) */\r
}\r
- (*score) = maxScore; \r
+ (*score) = maxScore;\r
\r
// Release allocated memory\r
for (i = 0; i < numLevels; i++)\r
free(tmpPoints);\r
free(tmpScore);\r
free(tmpKPoints);\r
- \r
- return LATENT_SVM_OK; \r
+\r
+ return LATENT_SVM_OK;\r
}\r
\r
/*\r
// Computation score function that exceed threshold\r
//\r
// API\r
-// int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, \r
- const featurePyramid *H, \r
- float b, \r
+// int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,\r
+ const featurePyramid *H,\r
+ float b,\r
int maxXBorder, int maxYBorder,\r
float scoreThreshold,\r
- float **score, \r
+ float **score,\r
CvPoint **points, int **levels, int *kPoints,\r
CvPoint ***partsDisplacement);\r
// INPUT\r
-// all_F - the set of filters (the first element is root filter, \r
+// all_F - the set of filters (the first element is root filter,\r
the other - part filters)\r
// n - the number of part filters\r
// H - feature pyramid\r
// RESULT\r
// Error status\r
*/\r
-int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, \r
- const CvLSVMFeaturePyramid *H, \r
- float b, \r
+int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,\r
+ const CvLSVMFeaturePyramid *H,\r
+ float b,\r
int maxXBorder, int maxYBorder,\r
float scoreThreshold,\r
- float **score, \r
+ float **score,\r
CvPoint **points, int **levels, int *kPoints,\r
CvPoint ***partsDisplacement)\r
{\r
int l, i, j, k, s, f, level, numLevels;\r
float **tmpScore;\r
CvPoint ***tmpPoints;\r
- CvPoint ****tmpPartsDisplacement; \r
+ CvPoint ****tmpPartsDisplacement;\r
int *tmpKPoints;\r
int res;\r
\r
/* DEBUG\r
FILE *file;\r
//*/\r
- \r
+\r
// Computation the number of levels for seaching object,\r
// first lambda-levels are used for computation values\r
// of score function for each position of root filter\r
numLevels = H->numLevels - LAMBDA;\r
- \r
+\r
// Allocation memory for values of score function for each level\r
// that exceed threshold\r
- tmpScore = (float **)malloc(sizeof(float*) * numLevels); \r
- // Allocation memory for the set of points that corresponds \r
+ tmpScore = (float **)malloc(sizeof(float*) * numLevels);\r
+ // Allocation memory for the set of points that corresponds\r
// to the maximum of score function\r
tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels);\r
for (i = 0; i < numLevels; i++)\r
{\r
tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **));\r
}\r
- // Number of points that corresponds to the maximum \r
+ // Number of points that corresponds to the maximum\r
// of score function on each level\r
tmpKPoints = (int *)malloc(sizeof(int) * numLevels);\r
for (i = 0; i < numLevels; i++)\r
// and getting the maximum on all levels\r
/* DEBUG: maxScore\r
file = fopen("maxScore.csv", "w+");\r
- fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]); \r
+ fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);\r
//*/\r
(*kPoints) = 0;\r
for (l = LAMBDA; l < H->numLevels; l++)\r
- { \r
+ {\r
k = l - LAMBDA;\r
//printf("Score at the level %i\n", l);\r
- res = thresholdFunctionalScoreFixedLevel(all_F, n, H, l, b, \r
+ res = thresholdFunctionalScoreFixedLevel(all_F, n, H, l, b,\r
maxXBorder, maxYBorder, scoreThreshold,\r
- &(tmpScore[k]), \r
- tmpPoints[k], \r
- &(tmpKPoints[k]), \r
+ &(tmpScore[k]),\r
+ tmpPoints[k],\r
+ &(tmpKPoints[k]),\r
tmpPartsDisplacement[k]);\r
- //fprintf(file, "%i;%lf;\n", l, tmpScore[k]); \r
+ //fprintf(file, "%i;%lf;\n", l, tmpScore[k]);\r
if (res != LATENT_SVM_OK)\r
{\r
continue;\r
(*kPoints) += tmpKPoints[k];\r
}\r
//fclose(file);\r
- \r
+\r
// Allocation memory for levels\r
(*levels) = (int *)malloc(sizeof(int) * (*kPoints));\r
// Allocation memory for the set of points\r
- (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); \r
+ (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints));\r
// Allocation memory for parts displacement\r
(*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints));\r
// Allocation memory for score function values\r
for (i = 0; i < numLevels; i++)\r
{\r
// Computation the number of level\r
- level = i + LAMBDA; \r
+ level = i + LAMBDA;\r
\r
// Addition a set of points\r
f += tmpKPoints[i];\r
(*points)[j] = (*tmpPoints[i])[j - s];\r
(*score)[j] = tmpScore[i][j - s];\r
(*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s];\r
- } \r
+ }\r
s = f;\r
}\r
\r
free(tmpScore);\r
free(tmpKPoints);\r
free(tmpPartsDisplacement);\r
- \r
- return LATENT_SVM_OK; \r
+\r
+ return LATENT_SVM_OK;\r
}\r
\r
/*\r
-// Creating schedule of pyramid levels processing \r
+// Creating schedule of pyramid levels processing\r
//\r
// API\r
// int createSchedule(const featurePyramid *H, const filterObject **all_F,\r
const int n, const int bx, const int by,\r
- const int threadsNum, int *kLevels, \r
+ const int threadsNum, int *kLevels,\r
int **processingLevels)\r
// INPUT\r
// H - feature pyramid\r
-// all_F - the set of filters (the first element is root filter, \r
+// all_F - the set of filters (the first element is root filter,\r
the other - part filters)\r
// n - the number of part filters\r
// bx - size of nullable border (X direction)\r
// by - size of nullable border (Y direction)\r
// threadsNum - number of threads that will be created in TBB version\r
// OUTPUT\r
-// kLevels - array that contains number of levels processed \r
+// kLevels - array that contains number of levels processed\r
by each thread\r
-// processingLevels - array that contains lists of levels processed \r
+// processingLevels - array that contains lists of levels processed\r
by each thread\r
// RESULT\r
// Error status\r
lambda = LAMBDA;\r
for (i = 0; i < numLevels; i++)\r
{\r
- dotProd[i] = H->pyramid[i + lambda]->sizeX * \r
+ dotProd[i] = H->pyramid[i + lambda]->sizeX *\r
H->pyramid[i + lambda]->sizeY * rootFilterDim +\r
- (H->pyramid[i]->sizeX + dbx) * \r
+ (H->pyramid[i]->sizeX + dbx) *\r
(H->pyramid[i]->sizeY + dby) * sumPartFiltersDim;\r
numDotProducts += dotProd[i];\r
}\r
\r
#ifdef HAVE_TBB\r
/*\r
-// int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, \r
- const CvLSVMFeaturePyramid *H, \r
- const float b, \r
+// int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,\r
+ const CvLSVMFeaturePyramid *H,\r
+ const float b,\r
const int maxXBorder, const int maxYBorder,\r
const float scoreThreshold,\r
const int threadsNum,\r
- float **score, \r
+ float **score,\r
CvPoint **points, int **levels, int *kPoints,\r
CvPoint ***partsDisplacement);\r
// INPUT\r
-// all_F - the set of filters (the first element is root filter, \r
+// all_F - the set of filters (the first element is root filter,\r
the other - part filters)\r
// n - the number of part filters\r
// H - feature pyramid\r
// RESULT\r
// Error status\r
*/\r
-int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, \r
- const CvLSVMFeaturePyramid *H, \r
- const float b, \r
+int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,\r
+ const CvLSVMFeaturePyramid *H,\r
+ const float b,\r
const int maxXBorder, const int maxYBorder,\r
const float scoreThreshold,\r
const int threadsNum,\r
- float **score, \r
+ float **score,\r
CvPoint **points, int **levels, int *kPoints,\r
CvPoint ***partsDisplacement)\r
{\r
int i, j, s, f, level, numLevels;\r
float **tmpScore;\r
CvPoint ***tmpPoints;\r
- CvPoint ****tmpPartsDisplacement; \r
+ CvPoint ****tmpPartsDisplacement;\r
int *tmpKPoints;\r
int res;\r
\r
int *kLevels, **procLevels;\r
int bx, by;\r
- \r
+\r
// Computation the number of levels for seaching object,\r
// first lambda-levels are used for computation values\r
// of score function for each position of root filter\r
{\r
for (i = 0; i < threadsNum; i++)\r
{\r
- if (procLevels[i] != NULL) \r
+ if (procLevels[i] != NULL)\r
{\r
free(procLevels[i]);\r
}\r
free(kLevels);\r
return res;\r
}\r
- \r
+\r
// Allocation memory for values of score function for each level\r
// that exceed threshold\r
- tmpScore = (float **)malloc(sizeof(float*) * numLevels); \r
- // Allocation memory for the set of points that corresponds \r
+ tmpScore = (float **)malloc(sizeof(float*) * numLevels);\r
+ // Allocation memory for the set of points that corresponds\r
// to the maximum of score function\r
tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels);\r
for (i = 0; i < numLevels; i++)\r
{\r
tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **));\r
}\r
- // Number of points that corresponds to the maximum \r
+ // Number of points that corresponds to the maximum\r
// of score function on each level\r
tmpKPoints = (int *)malloc(sizeof(int) * numLevels);\r
for (i = 0; i < numLevels; i++)\r
// Computation maxima of score function on each level\r
// and getting the maximum on all levels using TBB tasks\r
tbbTasksThresholdFunctionalScore(all_F, n, H, b, maxXBorder, maxYBorder,\r
- scoreThreshold, kLevels, procLevels, \r
- threadsNum, tmpScore, tmpPoints, \r
+ scoreThreshold, kLevels, procLevels,\r
+ threadsNum, tmpScore, tmpPoints,\r
tmpKPoints, tmpPartsDisplacement);\r
(*kPoints) = 0;\r
for (i = 0; i < numLevels; i++)\r
{\r
(*kPoints) += tmpKPoints[i];\r
}\r
- \r
+\r
// Allocation memory for levels\r
(*levels) = (int *)malloc(sizeof(int) * (*kPoints));\r
// Allocation memory for the set of points\r
- (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); \r
+ (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints));\r
// Allocation memory for parts displacement\r
(*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints));\r
// Allocation memory for score function values\r
for (i = 0; i < numLevels; i++)\r
{\r
// Computation the number of level\r
- level = i + LAMBDA;//H->lambda; \r
+ level = i + LAMBDA;//H->lambda;\r
\r
// Addition a set of points\r
f += tmpKPoints[i];\r
(*points)[j] = (*tmpPoints[i])[j - s];\r
(*score)[j] = tmpScore[i][j - s];\r
(*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s];\r
- } \r
+ }\r
s = f;\r
}\r
\r
\r
void sort(int n, const float* x, int* indices)\r
{\r
- int i, j;\r
- for (i = 0; i < n; i++)\r
- for (j = i + 1; j < n; j++)\r
- {\r
- if (x[indices[j]] > x[indices[i]])\r
- {\r
- //float x_tmp = x[i];\r
- int index_tmp = indices[i];\r
- //x[i] = x[j];\r
- indices[i] = indices[j];\r
- //x[j] = x_tmp;\r
- indices[j] = index_tmp;\r
- }\r
- }\r
+ int i, j;\r
+ for (i = 0; i < n; i++)\r
+ for (j = i + 1; j < n; j++)\r
+ {\r
+ if (x[indices[j]] > x[indices[i]])\r
+ {\r
+ //float x_tmp = x[i];\r
+ int index_tmp = indices[i];\r
+ //x[i] = x[j];\r
+ indices[i] = indices[j];\r
+ //x[j] = x_tmp;\r
+ indices[j] = index_tmp;\r
+ }\r
+ }\r
}\r
\r
/*\r
// to remove "similar" bounding boxes\r
//\r
// API\r
-// int nonMaximumSuppression(int numBoxes, const CvPoint *points, \r
+// int nonMaximumSuppression(int numBoxes, const CvPoint *points,\r
const CvPoint *oppositePoints, const float *score,\r
- float overlapThreshold, \r
- int *numBoxesOut, CvPoint **pointsOut, \r
+ float overlapThreshold,\r
+ int *numBoxesOut, CvPoint **pointsOut,\r
CvPoint **oppositePointsOut, float **scoreOut);\r
// INPUT\r
// numBoxes - number of bounding boxes\r
// points - array of left top corner coordinates\r
// oppositePoints - array of right bottom corner coordinates\r
// score - array of detection scores\r
-// overlapThreshold - threshold: bounding box is removed if overlap part \r
- is greater than passed value\r
+// overlapThreshold - threshold: bounding box is removed if overlap part\r
+ is greater than passed value\r
// OUTPUT\r
// numBoxesOut - the number of bounding boxes algorithm returns\r
// pointsOut - array of left top corner coordinates\r
// RESULT\r
// Error status\r
*/\r
-int nonMaximumSuppression(int numBoxes, const CvPoint *points, \r
+int nonMaximumSuppression(int numBoxes, const CvPoint *points,\r
const CvPoint *oppositePoints, const float *score,\r
- float overlapThreshold, \r
- int *numBoxesOut, CvPoint **pointsOut, \r
+ float overlapThreshold,\r
+ int *numBoxesOut, CvPoint **pointsOut,\r
CvPoint **oppositePointsOut, float **scoreOut)\r
{\r
int i, j, index;\r
- float* box_area = (float*)malloc(numBoxes * sizeof(float));\r
- int* indices = (int*)malloc(numBoxes * sizeof(int));\r
- int* is_suppressed = (int*)malloc(numBoxes * sizeof(int));\r
- \r
- for (i = 0; i < numBoxes; i++)\r
- {\r
- indices[i] = i;\r
- is_suppressed[i] = 0;\r
- box_area[i] = (float)( (oppositePoints[i].x - points[i].x + 1) * \r
+ float* box_area = (float*)malloc(numBoxes * sizeof(float));\r
+ int* indices = (int*)malloc(numBoxes * sizeof(int));\r
+ int* is_suppressed = (int*)malloc(numBoxes * sizeof(int));\r
+\r
+ for (i = 0; i < numBoxes; i++)\r
+ {\r
+ indices[i] = i;\r
+ is_suppressed[i] = 0;\r
+ box_area[i] = (float)( (oppositePoints[i].x - points[i].x + 1) *\r
(oppositePoints[i].y - points[i].y + 1));\r
- }\r
-\r
- sort(numBoxes, score, indices);\r
- for (i = 0; i < numBoxes; i++)\r
- {\r
- if (!is_suppressed[indices[i]])\r
- {\r
- for (j = i + 1; j < numBoxes; j++)\r
- {\r
- if (!is_suppressed[indices[j]])\r
- {\r
+ }\r
+\r
+ sort(numBoxes, score, indices);\r
+ for (i = 0; i < numBoxes; i++)\r
+ {\r
+ if (!is_suppressed[indices[i]])\r
+ {\r
+ for (j = i + 1; j < numBoxes; j++)\r
+ {\r
+ if (!is_suppressed[indices[j]])\r
+ {\r
int x1max = max(points[indices[i]].x, points[indices[j]].x);\r
int x2min = min(oppositePoints[indices[i]].x, oppositePoints[indices[j]].x);\r
int y1max = max(points[indices[i]].y, points[indices[j]].y);\r
int y2min = min(oppositePoints[indices[i]].y, oppositePoints[indices[j]].y);\r
- int overlapWidth = x2min - x1max + 1;\r
- int overlapHeight = y2min - y1max + 1;\r
- if (overlapWidth > 0 && overlapHeight > 0)\r
- {\r
- float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]];\r
- if (overlapPart > overlapThreshold)\r
- {\r
- is_suppressed[indices[j]] = 1;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- *numBoxesOut = 0;\r
- for (i = 0; i < numBoxes; i++)\r
- {\r
- if (!is_suppressed[i]) (*numBoxesOut)++;\r
- }\r
+ int overlapWidth = x2min - x1max + 1;\r
+ int overlapHeight = y2min - y1max + 1;\r
+ if (overlapWidth > 0 && overlapHeight > 0)\r
+ {\r
+ float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]];\r
+ if (overlapPart > overlapThreshold)\r
+ {\r
+ is_suppressed[indices[j]] = 1;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ *numBoxesOut = 0;\r
+ for (i = 0; i < numBoxes; i++)\r
+ {\r
+ if (!is_suppressed[i]) (*numBoxesOut)++;\r
+ }\r
\r
*pointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint));\r
*oppositePointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint));\r
*scoreOut = (float *)malloc((*numBoxesOut) * sizeof(float));\r
- index = 0;\r
- for (i = 0; i < numBoxes; i++)\r
- {\r
- if (!is_suppressed[indices[i]])\r
- {\r
+ index = 0;\r
+ for (i = 0; i < numBoxes; i++)\r
+ {\r
+ if (!is_suppressed[indices[i]])\r
+ {\r
(*pointsOut)[index].x = points[indices[i]].x;\r
(*pointsOut)[index].y = points[indices[i]].y;\r
(*oppositePointsOut)[index].x = oppositePoints[indices[i]].x;\r
(*oppositePointsOut)[index].y = oppositePoints[indices[i]].y;\r
- (*scoreOut)[index] = score[indices[i]];\r
- index++;\r
- }\r
+ (*scoreOut)[index] = score[indices[i]];\r
+ index++;\r
+ }\r
\r
- }\r
+ }\r
\r
- free(indices);\r
- free(box_area);\r
- free(is_suppressed);\r
+ free(indices);\r
+ free(box_area);\r
+ free(is_suppressed);\r
\r
- return LATENT_SVM_OK;\r
+ return LATENT_SVM_OK;\r
}\r