Commit 2ca6a505 authored by Marina Kolpakova's avatar Marina Kolpakova

Fixed bug #1663

parent 082e9881
...@@ -24,68 +24,68 @@ ...@@ -24,68 +24,68 @@
int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float *f) int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float *f)
{ {
int n1, m1, n2, m2, p, size, diff1, diff2; int n1, m1, n2, m2, p, size, diff1, diff2;
int i1, i2, j1, j2, k; int i1, i2, j1, j2, k;
float tmp_f1, tmp_f2, tmp_f3, tmp_f4; float tmp_f1, tmp_f2, tmp_f3, tmp_f4;
float *pMap = NULL; float *pMap = NULL;
float *pH = NULL; float *pH = NULL;
n1 = map->sizeY; n1 = map->sizeY;
m1 = map->sizeX; m1 = map->sizeX;
n2 = Fi->sizeY; n2 = Fi->sizeY;
m2 = Fi->sizeX; m2 = Fi->sizeX;
p = map->numFeatures; p = map->numFeatures;
diff1 = n1 - n2 + 1; diff1 = n1 - n2 + 1;
diff2 = m1 - m2 + 1; diff2 = m1 - m2 + 1;
size = diff1 * diff2; size = diff1 * diff2;
for (j1 = diff2 - 1; j1 >= 0; j1--) for (j1 = diff2 - 1; j1 >= 0; j1--)
{ {
for (i1 = diff1 - 1; i1 >= 0; i1--) for (i1 = diff1 - 1; i1 >= 0; i1--)
{ {
tmp_f1 = 0.0f; tmp_f1 = 0.0f;
tmp_f2 = 0.0f; tmp_f2 = 0.0f;
tmp_f3 = 0.0f; tmp_f3 = 0.0f;
tmp_f4 = 0.0f; tmp_f4 = 0.0f;
for (i2 = 0; i2 < n2; i2++) for (i2 = 0; i2 < n2; i2++)
{ {
for (j2 = 0; j2 < m2; j2++) for (j2 = 0; j2 < m2; j2++)
{ {
pMap = map->map + (i1 + i2) * m1 * p + (j1 + j2) * p;//sm2 pMap = map->map + (i1 + i2) * m1 * p + (j1 + j2) * p;//sm2
pH = Fi->H + (i2 * m2 + j2) * p;//sm2 pH = Fi->H + (i2 * m2 + j2) * p;//sm2
for (k = 0; k < p/4; k++) for (k = 0; k < p/4; k++)
{ {
tmp_f1 += pMap[4*k]*pH[4*k];//sm2 tmp_f1 += pMap[4*k]*pH[4*k];//sm2
tmp_f2 += pMap[4*k+1]*pH[4*k+1]; tmp_f2 += pMap[4*k+1]*pH[4*k+1];
tmp_f3 += pMap[4*k+2]*pH[4*k+2]; tmp_f3 += pMap[4*k+2]*pH[4*k+2];
tmp_f4 += pMap[4*k+3]*pH[4*k+3]; tmp_f4 += pMap[4*k+3]*pH[4*k+3];
} }
if (p%4==1) if (p%4==1)
{ {
tmp_f1 += pH[p-1]*pMap[p-1]; tmp_f1 += pH[p-1]*pMap[p-1];
} }
else else
{ {
if (p%4==2) if (p%4==2)
{ {
tmp_f1 += pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1]; tmp_f1 += pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];
} }
else else
{ {
if (p%4==3) if (p%4==3)
{ {
tmp_f1 += pH[p-3]*pMap[p-3] + pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1]; tmp_f1 += pH[p-3]*pMap[p-3] + pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];
} }
} }
} }
} }
} }
f[i1 * diff2 + j1] = tmp_f1 + tmp_f2 + tmp_f3 + tmp_f4;//sm1 f[i1 * diff2 + j1] = tmp_f1 + tmp_f2 + tmp_f3 + tmp_f4;//sm1
} }
} }
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
...@@ -93,7 +93,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float ...@@ -93,7 +93,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
// Computation multiplication of FFT images // Computation multiplication of FFT images
// //
// API // API
// int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls, // int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
float *multi); float *multi);
// INPUT // INPUT
// fftImage1 - first fft image // fftImage1 - first fft image
...@@ -104,7 +104,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float ...@@ -104,7 +104,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
// RESULT // RESULT
// Error status // Error status
*/ */
int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls, int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
float *multi) float *multi)
{ {
int i, index, size; int i, index, size;
...@@ -112,7 +112,7 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls ...@@ -112,7 +112,7 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
index = 2 * i; index = 2 * i;
multi[index] = fftImage1[index] * fftImage2[index] - multi[index] = fftImage1[index] * fftImage2[index] -
fftImage1[index + 1] * fftImage2[index + 1]; fftImage1[index + 1] * fftImage2[index + 1];
multi[index + 1] = fftImage1[index] * fftImage2[index + 1] + multi[index + 1] = fftImage1[index] * fftImage2[index + 1] +
fftImage1[index + 1] * fftImage2[index]; fftImage1[index + 1] * fftImage2[index];
...@@ -124,7 +124,7 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls ...@@ -124,7 +124,7 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls
// Turnover filter matrix for the single feature // Turnover filter matrix for the single feature
// //
// API // API
// int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter, // int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int p, int shift); int p, int shift);
// INPUT // INPUT
// filter - filter weight matrix // filter - filter weight matrix
...@@ -136,7 +136,7 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls ...@@ -136,7 +136,7 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls
// RESULT // RESULT
// Error status // Error status
*/ */
int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter, int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int p, int shift) int p, int shift)
{ {
int i, size; int i, size;
...@@ -152,7 +152,7 @@ int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter, ...@@ -152,7 +152,7 @@ int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
// Addition nullable bars to the dimension of feature map (single feature) // Addition nullable bars to the dimension of feature map (single feature)
// //
// API // API
// int addNullableBars(float *rot2PIFilter, int dimX, int dimY, // int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
float *newFilter, int newDimX, int newDimY); float *newFilter, int newDimX, int newDimY);
// INPUT // INPUT
// rot2PIFilter - filter matrix for the single feature that was rotated // rot2PIFilter - filter matrix for the single feature that was rotated
...@@ -163,7 +163,7 @@ int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter, ...@@ -163,7 +163,7 @@ int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
// RESULT // RESULT
// Error status // Error status
*/ */
int addNullableBars(float *rot2PIFilter, int dimX, int dimY, int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
float *newFilter, int newDimX, int newDimY) float *newFilter, int newDimX, int newDimY)
{ {
int size, i, j; int size, i, j;
...@@ -187,7 +187,7 @@ int addNullableBars(float *rot2PIFilter, int dimX, int dimY, ...@@ -187,7 +187,7 @@ int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
// Computation FFT image for filter object // Computation FFT image for filter object
// //
// API // API
// int getFFTImageFilterObject(const CvLSVMFilterObject *filter, // int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
int mapDimX, int mapDimY, int mapDimX, int mapDimY,
fftImage **image); fftImage **image);
// INPUT // INPUT
...@@ -198,29 +198,29 @@ int addNullableBars(float *rot2PIFilter, int dimX, int dimY, ...@@ -198,29 +198,29 @@ int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
// RESULT // RESULT
// Error status // Error status
*/ */
int getFFTImageFilterObject(const CvLSVMFilterObject *filter, int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
int mapDimX, int mapDimY, int mapDimX, int mapDimY,
CvLSVMFftImage **image) CvLSVMFftImage **image)
{ {
int i, mapSize, filterSize, res; int i, mapSize, filterSize, res;
float *newFilter, *rot2PIFilter; float *newFilter, *rot2PIFilter;
filterSize = filter->sizeX * filter->sizeY; filterSize = filter->sizeX * filter->sizeY;
mapSize = mapDimX * mapDimY; mapSize = mapDimX * mapDimY;
newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));
rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);
res = allocFFTImage(image, filter->numFeatures, mapDimX, mapDimY); res = allocFFTImage(image, filter->numFeatures, mapDimX, mapDimY);
if (res != LATENT_SVM_OK) if (res != LATENT_SVM_OK)
{
return res; return res;
}
newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));
rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);
for (i = 0; i < filter->numFeatures; i++) for (i = 0; i < filter->numFeatures; i++)
{ {
rot2PI(filter->H, filter->sizeX, filter->sizeY, rot2PIFilter, filter->numFeatures, i); rot2PI(filter->H, filter->sizeX, filter->sizeY, rot2PIFilter, filter->numFeatures, i);
addNullableBars(rot2PIFilter, filter->sizeX, filter->sizeY, addNullableBars(rot2PIFilter, filter->sizeX, filter->sizeY,
newFilter, mapDimX, mapDimY); newFilter, mapDimX, mapDimY);
fft2d(newFilter, (*image)->channels[i], mapDimY, mapDimX); fft2d(newFilter, (*image)->channels[i], mapDimY, mapDimX);
} }
free(newFilter); free(newFilter);
free(rot2PIFilter); free(rot2PIFilter);
return LATENT_SVM_OK; return LATENT_SVM_OK;
...@@ -239,7 +239,7 @@ int getFFTImageFilterObject(const CvLSVMFilterObject *filter, ...@@ -239,7 +239,7 @@ int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image) int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image)
{ {
int i, j, size; int i, j, size;
float *buf; float *buf;
allocFFTImage(image, map->numFeatures, map->sizeX, map->sizeY); allocFFTImage(image, map->numFeatures, map->sizeX, map->sizeY);
size = map->sizeX * map->sizeY; size = map->sizeX * map->sizeY;
buf = (float *)malloc(sizeof(float) * (2 * size)); buf = (float *)malloc(sizeof(float) * (2 * size));
...@@ -258,9 +258,9 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image) ...@@ -258,9 +258,9 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image)
/* /*
// Function for convolution computation using FFT // Function for convolution computation using FFT
// //
// API // API
// int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage, // int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,
int filterDimX, int filterDimY, float **conv); int filterDimX, int filterDimY, float **conv);
// INPUT // INPUT
// featMapImage - feature map image // featMapImage - feature map image
...@@ -271,7 +271,7 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image) ...@@ -271,7 +271,7 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image)
// RESULT // RESULT
// Error status // Error status
*/ */
int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage, int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,
int filterDimX, int filterDimY, float **conv) int filterDimX, int filterDimY, float **conv)
{ {
int i, j, size, diffX, diffY, index; int i, j, size, diffX, diffY, index;
...@@ -279,11 +279,11 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt ...@@ -279,11 +279,11 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt
size = 2 * featMapImage->dimX * featMapImage->dimY; size = 2 * featMapImage->dimX * featMapImage->dimY;
imagesMult = (float *)malloc(sizeof(float) * size); imagesMult = (float *)malloc(sizeof(float) * size);
imagesMultRes = (float *)malloc(sizeof(float) * size); imagesMultRes = (float *)malloc(sizeof(float) * size);
fftImagesMulti(featMapImage->channels[0], filterImage->channels[0], fftImagesMulti(featMapImage->channels[0], filterImage->channels[0],
featMapImage->dimY, featMapImage->dimX, imagesMultRes); featMapImage->dimY, featMapImage->dimX, imagesMultRes);
for (i = 1; (i < (int)featMapImage->numFeatures) && (i < (int)filterImage->numFeatures); i++) for (i = 1; (i < (int)featMapImage->numFeatures) && (i < (int)filterImage->numFeatures); i++)
{ {
fftImagesMulti(featMapImage->channels[i],filterImage->channels[i], fftImagesMulti(featMapImage->channels[i],filterImage->channels[i],
featMapImage->dimY, featMapImage->dimX, imagesMult); featMapImage->dimY, featMapImage->dimX, imagesMult);
for (j = 0; j < size; j++) for (j = 0; j < size; j++)
{ {
...@@ -299,7 +299,7 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt ...@@ -299,7 +299,7 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt
{ {
for (j = 0; j < diffX; j++) for (j = 0; j < diffX; j++)
{ {
index = (i + filterDimY - 1) * featMapImage->dimX + index = (i + filterDimY - 1) * featMapImage->dimX +
(j + filterDimX - 1); (j + filterDimX - 1);
(*conv)[i * diffX + j] = fconv[2 * index]; (*conv)[i * diffX + j] = fconv[2 * index];
} }
...@@ -314,30 +314,30 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt ...@@ -314,30 +314,30 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt
// Computation objective function D according the original paper // Computation objective function D according the original paper
// //
// API // API
// int filterDispositionLevel(const CvLSVMFilterObject *Fi, const featurePyramid *H, // int filterDispositionLevel(const CvLSVMFilterObject *Fi, const featurePyramid *H,
int level, float **scoreFi, int level, float **scoreFi,
int **pointsX, int **pointsY); int **pointsX, int **pointsY);
// INPUT // INPUT
// Fi - filter object (weights and coefficients of penalty // Fi - filter object (weights and coefficients of penalty
function that are used in this routine) function that are used in this routine)
// H - feature pyramid // H - feature pyramid
// level - level number // level - level number
// OUTPUT // OUTPUT
// scoreFi - values of distance transform on the level at all positions // scoreFi - values of distance transform on the level at all positions
// (pointsX, pointsY)- positions that correspond to the maximum value // (pointsX, pointsY)- positions that correspond to the maximum value
of distance transform at all grid nodes of distance transform at all grid nodes
// RESULT // RESULT
// Error status // Error status
*/ */
int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid, int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid,
float **scoreFi, float **scoreFi,
int **pointsX, int **pointsY) int **pointsX, int **pointsY)
{ {
int n1, m1, n2, m2, p, size, diff1, diff2; int n1, m1, n2, m2, p, size, diff1, diff2;
float *f; float *f;
int i1, j1; int i1, j1;
int res; int res;
n1 = pyramid->sizeY; n1 = pyramid->sizeY;
m1 = pyramid->sizeX; m1 = pyramid->sizeX;
n2 = Fi->sizeY; n2 = Fi->sizeY;
...@@ -346,8 +346,8 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap ...@@ -346,8 +346,8 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
(*scoreFi) = NULL; (*scoreFi) = NULL;
(*pointsX) = NULL; (*pointsX) = NULL;
(*pointsY) = NULL; (*pointsY) = NULL;
// Processing the situation when part filter goes // Processing the situation when part filter goes
// beyond the boundaries of the block set // beyond the boundaries of the block set
if (n1 < n2 || m1 < m2) if (n1 < n2 || m1 < m2)
{ {
...@@ -360,15 +360,15 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap ...@@ -360,15 +360,15 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
size = diff1 * diff2; size = diff1 * diff2;
// Allocation memory for additional array (must be free in this function) // Allocation memory for additional array (must be free in this function)
f = (float *)malloc(sizeof(float) * size); f = (float *)malloc(sizeof(float) * size);
// Allocation memory for arrays for saving decisions // Allocation memory for arrays for saving decisions
(*scoreFi) = (float *)malloc(sizeof(float) * size); (*scoreFi) = (float *)malloc(sizeof(float) * size);
(*pointsX) = (int *)malloc(sizeof(int) * size); (*pointsX) = (int *)malloc(sizeof(int) * size);
(*pointsY) = (int *)malloc(sizeof(int) * size); (*pointsY) = (int *)malloc(sizeof(int) * size);
// Consruction values of the array f // Consruction values of the array f
// (a dot product vectors of feature map and weights of the filter) // (a dot product vectors of feature map and weights of the filter)
res = convolution(Fi, pyramid, f); res = convolution(Fi, pyramid, f);
if (res != LATENT_SVM_OK) if (res != LATENT_SVM_OK)
{ {
free(f); free(f);
...@@ -384,11 +384,11 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap ...@@ -384,11 +384,11 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
for (j1 = 0; j1 < diff2; j1++) for (j1 = 0; j1 < diff2; j1++)
{ {
f[i1 * diff2 + j1] *= (-1); f[i1 * diff2 + j1] *= (-1);
} }
} }
// Decision of the general distance transform task // Decision of the general distance transform task
DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction, DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction,
(*scoreFi), (*pointsX), (*pointsY)); (*scoreFi), (*pointsX), (*pointsY));
// Release allocated memory // Release allocated memory
...@@ -401,29 +401,29 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap ...@@ -401,29 +401,29 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
// //
// API // API
// int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const fftImage *featMapImage, // int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const fftImage *featMapImage,
float **scoreFi, float **scoreFi,
int **pointsX, int **pointsY); int **pointsX, int **pointsY);
// INPUT // INPUT
// Fi - filter object (weights and coefficients of penalty // Fi - filter object (weights and coefficients of penalty
function that are used in this routine) function that are used in this routine)
// featMapImage - FFT image of feature map // featMapImage - FFT image of feature map
// OUTPUT // OUTPUT
// scoreFi - values of distance transform on the level at all positions // scoreFi - values of distance transform on the level at all positions
// (pointsX, pointsY)- positions that correspond to the maximum value // (pointsX, pointsY)- positions that correspond to the maximum value
of distance transform at all grid nodes of distance transform at all grid nodes
// RESULT // RESULT
// Error status // Error status
*/ */
int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage, int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage,
float **scoreFi, float **scoreFi,
int **pointsX, int **pointsY) int **pointsX, int **pointsY)
{ {
int n1, m1, n2, m2, p, size, diff1, diff2; int n1, m1, n2, m2, p, size, diff1, diff2;
float *f; float *f;
int i1, j1; int i1, j1;
int res; int res;
CvLSVMFftImage *filterImage; CvLSVMFftImage *filterImage;
n1 = featMapImage->dimY; n1 = featMapImage->dimY;
m1 = featMapImage->dimX; m1 = featMapImage->dimX;
n2 = Fi->sizeY; n2 = Fi->sizeY;
...@@ -432,8 +432,8 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage ...@@ -432,8 +432,8 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage
(*scoreFi) = NULL; (*scoreFi) = NULL;
(*pointsX) = NULL; (*pointsX) = NULL;
(*pointsY) = NULL; (*pointsY) = NULL;
// Processing the situation when part filter goes // Processing the situation when part filter goes
// beyond the boundaries of the block set // beyond the boundaries of the block set
if (n1 < n2 || m1 < m2) if (n1 < n2 || m1 < m2)
{ {
...@@ -453,7 +453,7 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage ...@@ -453,7 +453,7 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage
// create filter image // create filter image
getFFTImageFilterObject(Fi, featMapImage->dimX, featMapImage->dimY, &filterImage); getFFTImageFilterObject(Fi, featMapImage->dimX, featMapImage->dimY, &filterImage);
// Consruction values of the array f // Consruction values of the array f
// (a dot product vectors of feature map and weights of the filter) // (a dot product vectors of feature map and weights of the filter)
res = convFFTConv2d(featMapImage, filterImage, Fi->sizeX, Fi->sizeY, &f); res = convFFTConv2d(featMapImage, filterImage, Fi->sizeX, Fi->sizeY, &f);
if (res != LATENT_SVM_OK) if (res != LATENT_SVM_OK)
...@@ -471,11 +471,11 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage ...@@ -471,11 +471,11 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage
for (j1 = 0; j1 < diff2; j1++) for (j1 = 0; j1 < diff2; j1++)
{ {
f[i1 * diff2 + j1] *= (-1); f[i1 * diff2 + j1] *= (-1);
} }
} }
// Decision of the general distance transform task // Decision of the general distance transform task
DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction, DistanceTransformTwoDimensionalProblem(f, diff1, diff2, Fi->fineFunction,
(*scoreFi), (*pointsX), (*pointsY)); (*scoreFi), (*pointsX), (*pointsY));
// Release allocated memory // Release allocated memory
...@@ -535,7 +535,7 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by) ...@@ -535,7 +535,7 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by)
{ {
for (k = 0; k < map->numFeatures; k++) for (k = 0; k < map->numFeatures; k++)
{ {
new_map[(i * sizeX + j) * map->numFeatures + k] = new_map[(i * sizeX + j) * map->numFeatures + k] =
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k]; map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k];
} }
} }
...@@ -547,13 +547,13 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by) ...@@ -547,13 +547,13 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by)
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map, CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,
int maxXBorder, int maxYBorder) int maxXBorder, int maxYBorder)
{ {
int bx, by; int bx, by;
int sizeX, sizeY, i, j, k; int sizeX, sizeY, i, j, k;
CvLSVMFeatureMap *new_map; CvLSVMFeatureMap *new_map;
computeBorderSize(maxXBorder, maxYBorder, &bx, &by); computeBorderSize(maxXBorder, maxYBorder, &bx, &by);
sizeX = map->sizeX + 2 * bx; sizeX = map->sizeX + 2 * bx;
sizeY = map->sizeY + 2 * by; sizeY = map->sizeY + 2 * by;
...@@ -568,7 +568,7 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map, ...@@ -568,7 +568,7 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,
{ {
for (k = 0; k < map->numFeatures; k++) for (k = 0; k < map->numFeatures; k++)
{ {
new_map->map[(i * sizeX + j) * map->numFeatures + k] = new_map->map[(i * sizeX + j) * map->numFeatures + k] =
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k]; map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k];
} }
} }
...@@ -580,14 +580,14 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map, ...@@ -580,14 +580,14 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,
// Computation the maximum of the score function at the level // Computation the maximum of the score function at the level
// //
// API // API
// int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, // int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const featurePyramid *H, const featurePyramid *H,
int level, float b, int level, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float *score, CvPoint **points, int *kPoints, float *score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement); CvPoint ***partsDisplacement);
// INPUT // INPUT
// all_F - the set of filters (the first element is root filter, // all_F - the set of filters (the first element is root filter,
the other - part filters) the other - part filters)
// n - the number of part filters // n - the number of part filters
// H - feature pyramid // H - feature pyramid
...@@ -604,11 +604,11 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map, ...@@ -604,11 +604,11 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,
// RESULT // RESULT
// Error status // Error status
*/ */
int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, const CvLSVMFeaturePyramid *H,
int level, float b, int level, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float *score, CvPoint **points, float *score, CvPoint **points,
int *kPoints, CvPoint ***partsDisplacement) int *kPoints, CvPoint ***partsDisplacement)
{ {
int i, j, k, dimX, dimY, nF0, mF0, p; int i, j, k, dimX, dimY, nF0, mF0, p;
...@@ -640,31 +640,31 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -640,31 +640,31 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// Number of features // Number of features
p = H->pyramid[level]->numFeatures; p = H->pyramid[level]->numFeatures;
// Getting dimension of root filter // Getting dimension of root filter
nF0 = all_F[0]->sizeY; nF0 = all_F[0]->sizeY;
mF0 = all_F[0]->sizeX; mF0 = all_F[0]->sizeX;
// Processing the situation when root filter goes // Processing the situation when root filter goes
// beyond the boundaries of the block set // beyond the boundaries of the block set
if (nF0 > dimY || mF0 > dimX) if (nF0 > dimY || mF0 > dimX)
{ {
return LATENT_SVM_FAILED_SUPERPOSITION; return LATENT_SVM_FAILED_SUPERPOSITION;
} }
diff1 = dimY - nF0 + 1; diff1 = dimY - nF0 + 1;
diff2 = dimX - mF0 + 1; diff2 = dimX - mF0 + 1;
// Allocation memory for saving values of function D // Allocation memory for saving values of function D
// on the level for each part filter // on the level for each part filter
disposition = (CvLSVMFilterDisposition **)malloc(sizeof(CvLSVMFilterDisposition *) * n); disposition = (CvLSVMFilterDisposition **)malloc(sizeof(CvLSVMFilterDisposition *) * n);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
disposition[i] = (CvLSVMFilterDisposition *)malloc(sizeof(CvLSVMFilterDisposition)); disposition[i] = (CvLSVMFilterDisposition *)malloc(sizeof(CvLSVMFilterDisposition));
} }
// Allocation memory for values of score function for each block on the level // Allocation memory for values of score function for each block on the level
scores = (float *)malloc(sizeof(float) * (diff1 * diff2)); scores = (float *)malloc(sizeof(float) * (diff1 * diff2));
// A dot product vectors of feature map and weights of root filter // A dot product vectors of feature map and weights of root filter
#ifdef FFT_CONV #ifdef FFT_CONV
getFFTImageFeatureMap(H->pyramid[level], &mapImage); getFFTImageFeatureMap(H->pyramid[level], &mapImage);
...@@ -673,7 +673,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -673,7 +673,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
freeFFTImage(&mapImage); freeFFTImage(&mapImage);
freeFFTImage(&rootFilterImage); freeFFTImage(&rootFilterImage);
#else #else
// Allocation memory for saving a dot product vectors of feature map and // Allocation memory for saving a dot product vectors of feature map and
// weights of root filter // weights of root filter
f = (float *)malloc(sizeof(float) * (diff1 * diff2)); f = (float *)malloc(sizeof(float) * (diff1 * diff2));
// A dot product vectors of feature map and weights of root filter // A dot product vectors of feature map and weights of root filter
...@@ -691,31 +691,31 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -691,31 +691,31 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
return res; return res;
} }
// Computation values of function D for each part filter // Computation values of function D for each part filter
// on the level (level - LAMBDA) // on the level (level - LAMBDA)
partsLevel = level - LAMBDA; partsLevel = level - LAMBDA;
// For feature map at the level 'partsLevel' add nullable border // For feature map at the level 'partsLevel' add nullable border
map = featureMapBorderPartFilter(H->pyramid[partsLevel], map = featureMapBorderPartFilter(H->pyramid[partsLevel],
maxXBorder, maxYBorder); maxXBorder, maxYBorder);
// Computation the maximum of score function // Computation the maximum of score function
sumScorePartDisposition = 0.0; sumScorePartDisposition = 0.0;
#ifdef FFT_CONV #ifdef FFT_CONV
getFFTImageFeatureMap(map, &mapImage); getFFTImageFeatureMap(map, &mapImage);
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
filterDispositionLevelFFT(all_F[k], mapImage, filterDispositionLevelFFT(all_F[k], mapImage,
&(disposition[k - 1]->score), &(disposition[k - 1]->score),
&(disposition[k - 1]->x), &(disposition[k - 1]->x),
&(disposition[k - 1]->y)); &(disposition[k - 1]->y));
} }
freeFFTImage(&mapImage); freeFFTImage(&mapImage);
#else #else
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
filterDispositionLevel(all_F[k], map, filterDispositionLevel(all_F[k], map,
&(disposition[k - 1]->score), &(disposition[k - 1]->score),
&(disposition[k - 1]->x), &(disposition[k - 1]->x),
&(disposition[k - 1]->y)); &(disposition[k - 1]->y));
} }
#endif #endif
...@@ -728,27 +728,27 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -728,27 +728,27 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
{ {
sumScorePartDisposition = 0.0; sumScorePartDisposition = 0.0;
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
// This condition takes on a value true // This condition takes on a value true
// when filter goes beyond the boundaries of block set // when filter goes beyond the boundaries of block set
if ((2 * i + all_F[k]->V.y < if ((2 * i + all_F[k]->V.y <
map->sizeY - all_F[k]->sizeY + 1) && map->sizeY - all_F[k]->sizeY + 1) &&
(2 * j + all_F[k]->V.x < (2 * j + all_F[k]->V.x <
map->sizeX - all_F[k]->sizeX + 1)) map->sizeX - all_F[k]->sizeX + 1))
{ {
index = (2 * i + all_F[k]->V.y) * index = (2 * i + all_F[k]->V.y) *
(map->sizeX - all_F[k]->sizeX + 1) + (map->sizeX - all_F[k]->sizeX + 1) +
(2 * j + all_F[k]->V.x); (2 * j + all_F[k]->V.x);
sumScorePartDisposition += disposition[k - 1]->score[index]; sumScorePartDisposition += disposition[k - 1]->score[index];
} }
} }
scores[i * diff2 + j] = f[i * diff2 + j] - sumScorePartDisposition + b; scores[i * diff2 + j] = f[i * diff2 + j] - sumScorePartDisposition + b;
if (maxScore < scores[i * diff2 + j]) if (maxScore < scores[i * diff2 + j])
{ {
maxScore = scores[i * diff2 + j]; maxScore = scores[i * diff2 + j];
(*kPoints) = 1; (*kPoints) = 1;
} }
else if ((scores[i * diff2 + j] - maxScore) * else if ((scores[i * diff2 + j] - maxScore) *
(scores[i * diff2 + j] - maxScore) <= EPS) (scores[i * diff2 + j] - maxScore) <= EPS)
{ {
(*kPoints)++; (*kPoints)++;
...@@ -768,7 +768,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -768,7 +768,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
strcat(buf, tmp); strcat(buf, tmp);
file = fopen(buf, "w+"); file = fopen(buf, "w+");
//*/ //*/
// Construction of the set of positions for root filter // Construction of the set of positions for root filter
// that correspond the maximum of score function on the level // that correspond the maximum of score function on the level
(*score) = maxScore; (*score) = maxScore;
last = 0; last = 0;
...@@ -776,29 +776,29 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -776,29 +776,29 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
{ {
for (j = 0; j < diff2; j++) for (j = 0; j < diff2; j++)
{ {
if ((scores[i * diff2 + j] - maxScore) * if ((scores[i * diff2 + j] - maxScore) *
(scores[i * diff2 + j] - maxScore) <= EPS) (scores[i * diff2 + j] - maxScore) <= EPS)
{ {
(*points)[last].y = i; (*points)[last].y = i;
(*points)[last].x = j; (*points)[last].x = j;
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
if ((2 * i + all_F[k]->V.y < if ((2 * i + all_F[k]->V.y <
map->sizeY - all_F[k]->sizeY + 1) && map->sizeY - all_F[k]->sizeY + 1) &&
(2 * j + all_F[k]->V.x < (2 * j + all_F[k]->V.x <
map->sizeX - all_F[k]->sizeX + 1)) map->sizeX - all_F[k]->sizeX + 1))
{ {
index = (2 * i + all_F[k]->V.y) * index = (2 * i + all_F[k]->V.y) *
(map->sizeX - all_F[k]->sizeX + 1) + (map->sizeX - all_F[k]->sizeX + 1) +
(2 * j + all_F[k]->V.x); (2 * j + all_F[k]->V.x);
(*partsDisplacement)[last][k - 1].x = (*partsDisplacement)[last][k - 1].x =
disposition[k - 1]->x[index]; disposition[k - 1]->x[index];
(*partsDisplacement)[last][k - 1].y = (*partsDisplacement)[last][k - 1].y =
disposition[k - 1]->y[index]; disposition[k - 1]->y[index];
} }
} }
last++; last++;
} /* if ((scores[i * diff2 + j] - maxScore) * } /* if ((scores[i * diff2 + j] - maxScore) *
(scores[i * diff2 + j] - maxScore) <= EPS) */ (scores[i * diff2 + j] - maxScore) <= EPS) */
//fprintf(file, "%lf;", scores[i * diff2 + j]); //fprintf(file, "%lf;", scores[i * diff2 + j]);
} }
...@@ -806,7 +806,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -806,7 +806,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
} }
//fclose(file); //fclose(file);
//free(tmp); //free(tmp);
// Release allocated memory // Release allocated memory
for (i = 0; i < n ; i++) for (i = 0; i < n ; i++)
{ {
...@@ -826,15 +826,15 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -826,15 +826,15 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// Computation score function at the level that exceed threshold // Computation score function at the level that exceed threshold
// //
// API // API
// int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, // int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const featurePyramid *H, const featurePyramid *H,
int level, float b, int level, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float scoreThreshold, float scoreThreshold,
float **score, CvPoint **points, int *kPoints, float **score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement); CvPoint ***partsDisplacement);
// INPUT // INPUT
// all_F - the set of filters (the first element is root filter, // all_F - the set of filters (the first element is root filter,
the other - part filters) the other - part filters)
// n - the number of part filters // n - the number of part filters
// H - feature pyramid // H - feature pyramid
...@@ -852,9 +852,9 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -852,9 +852,9 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// RESULT // RESULT
// Error status // Error status
*/ */
int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, const CvLSVMFeaturePyramid *H,
int level, float b, int level, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float scoreThreshold, float scoreThreshold,
float **score, CvPoint **points, int *kPoints, float **score, CvPoint **points, int *kPoints,
...@@ -888,27 +888,27 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -888,27 +888,27 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// Number of features // Number of features
p = H->pyramid[level]->numFeatures; p = H->pyramid[level]->numFeatures;
// Getting dimension of root filter // Getting dimension of root filter
nF0 = all_F[0]->sizeY; nF0 = all_F[0]->sizeY;
mF0 = all_F[0]->sizeX; mF0 = all_F[0]->sizeX;
// Processing the situation when root filter goes // Processing the situation when root filter goes
// beyond the boundaries of the block set // beyond the boundaries of the block set
if (nF0 > dimY || mF0 > dimX) if (nF0 > dimY || mF0 > dimX)
{ {
return LATENT_SVM_FAILED_SUPERPOSITION; return LATENT_SVM_FAILED_SUPERPOSITION;
} }
diff1 = dimY - nF0 + 1; diff1 = dimY - nF0 + 1;
diff2 = dimX - mF0 + 1; diff2 = dimX - mF0 + 1;
// Allocation memory for saving values of function D // Allocation memory for saving values of function D
// on the level for each part filter // on the level for each part filter
disposition = (CvLSVMFilterDisposition **)malloc(sizeof(CvLSVMFilterDisposition *) * n); disposition = (CvLSVMFilterDisposition **)malloc(sizeof(CvLSVMFilterDisposition *) * n);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
disposition[i] = (CvLSVMFilterDisposition *)malloc(sizeof(CvLSVMFilterDisposition)); disposition[i] = (CvLSVMFilterDisposition *)malloc(sizeof(CvLSVMFilterDisposition));
} }
// Allocation memory for values of score function for each block on the level // Allocation memory for values of score function for each block on the level
scores = (float *)malloc(sizeof(float) * (diff1 * diff2)); scores = (float *)malloc(sizeof(float) * (diff1 * diff2));
...@@ -920,7 +920,7 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -920,7 +920,7 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
freeFFTImage(&mapImage); freeFFTImage(&mapImage);
freeFFTImage(&rootFilterImage); freeFFTImage(&rootFilterImage);
#else #else
// Allocation memory for saving a dot product vectors of feature map and // Allocation memory for saving a dot product vectors of feature map and
// weights of root filter // weights of root filter
f = (float *)malloc(sizeof(float) * (diff1 * diff2)); f = (float *)malloc(sizeof(float) * (diff1 * diff2));
res = convolution(all_F[0], H->pyramid[level], f); res = convolution(all_F[0], H->pyramid[level], f);
...@@ -937,31 +937,31 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -937,31 +937,31 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
return res; return res;
} }
// Computation values of function D for each part filter // Computation values of function D for each part filter
// on the level (level - LAMBDA) // on the level (level - LAMBDA)
partsLevel = level - LAMBDA; partsLevel = level - LAMBDA;
// For feature map at the level 'partsLevel' add nullable border // For feature map at the level 'partsLevel' add nullable border
map = featureMapBorderPartFilter(H->pyramid[partsLevel], map = featureMapBorderPartFilter(H->pyramid[partsLevel],
maxXBorder, maxYBorder); maxXBorder, maxYBorder);
// Computation the maximum of score function // Computation the maximum of score function
sumScorePartDisposition = 0.0; sumScorePartDisposition = 0.0;
#ifdef FFT_CONV #ifdef FFT_CONV
getFFTImageFeatureMap(map, &mapImage); getFFTImageFeatureMap(map, &mapImage);
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
filterDispositionLevelFFT(all_F[k], mapImage, filterDispositionLevelFFT(all_F[k], mapImage,
&(disposition[k - 1]->score), &(disposition[k - 1]->score),
&(disposition[k - 1]->x), &(disposition[k - 1]->x),
&(disposition[k - 1]->y)); &(disposition[k - 1]->y));
} }
freeFFTImage(&mapImage); freeFFTImage(&mapImage);
#else #else
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
filterDispositionLevel(all_F[k], map, filterDispositionLevel(all_F[k], map,
&(disposition[k - 1]->score), &(disposition[k - 1]->score),
&(disposition[k - 1]->x), &(disposition[k - 1]->x),
&(disposition[k - 1]->y)); &(disposition[k - 1]->y));
} }
#endif #endif
...@@ -972,22 +972,22 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -972,22 +972,22 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
{ {
sumScorePartDisposition = 0.0; sumScorePartDisposition = 0.0;
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
// This condition takes on a value true // This condition takes on a value true
// when filter goes beyond the boundaries of block set // when filter goes beyond the boundaries of block set
if ((2 * i + all_F[k]->V.y < if ((2 * i + all_F[k]->V.y <
map->sizeY - all_F[k]->sizeY + 1) && map->sizeY - all_F[k]->sizeY + 1) &&
(2 * j + all_F[k]->V.x < (2 * j + all_F[k]->V.x <
map->sizeX - all_F[k]->sizeX + 1)) map->sizeX - all_F[k]->sizeX + 1))
{ {
index = (2 * i + all_F[k]->V.y) * index = (2 * i + all_F[k]->V.y) *
(map->sizeX - all_F[k]->sizeX + 1) + (map->sizeX - all_F[k]->sizeX + 1) +
(2 * j + all_F[k]->V.x); (2 * j + all_F[k]->V.x);
sumScorePartDisposition += disposition[k - 1]->score[index]; sumScorePartDisposition += disposition[k - 1]->score[index];
} }
} }
scores[i * diff2 + j] = f[i * diff2 + j] - sumScorePartDisposition + b; scores[i * diff2 + j] = f[i * diff2 + j] - sumScorePartDisposition + b;
if (scores[i * diff2 + j] > scoreThreshold) if (scores[i * diff2 + j] > scoreThreshold)
{ {
(*kPoints)++; (*kPoints)++;
} }
...@@ -1006,7 +1006,7 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -1006,7 +1006,7 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
strcat(buf, tmp); strcat(buf, tmp);
file = fopen(buf, "w+"); file = fopen(buf, "w+");
//*/ //*/
// Construction of the set of positions for root filter // Construction of the set of positions for root filter
// that correspond score function on the level that exceed threshold // that correspond score function on the level that exceed threshold
(*score) = (float *)malloc(sizeof(float) * (*kPoints)); (*score) = (float *)malloc(sizeof(float) * (*kPoints));
last = 0; last = 0;
...@@ -1014,26 +1014,26 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -1014,26 +1014,26 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
{ {
for (j = 0; j < diff2; j++) for (j = 0; j < diff2; j++)
{ {
if (scores[i * diff2 + j] > scoreThreshold) if (scores[i * diff2 + j] > scoreThreshold)
{ {
(*score)[last] = scores[i * diff2 + j]; (*score)[last] = scores[i * diff2 + j];
(*points)[last].y = i; (*points)[last].y = i;
(*points)[last].x = j; (*points)[last].x = j;
for (k = 1; k <= n; k++) for (k = 1; k <= n; k++)
{ {
if ((2 * i + all_F[k]->V.y < if ((2 * i + all_F[k]->V.y <
map->sizeY - all_F[k]->sizeY + 1) && map->sizeY - all_F[k]->sizeY + 1) &&
(2 * j + all_F[k]->V.x < (2 * j + all_F[k]->V.x <
map->sizeX - all_F[k]->sizeX + 1)) map->sizeX - all_F[k]->sizeX + 1))
{ {
index = (2 * i + all_F[k]->V.y) * index = (2 * i + all_F[k]->V.y) *
(map->sizeX - all_F[k]->sizeX + 1) + (map->sizeX - all_F[k]->sizeX + 1) +
(2 * j + all_F[k]->V.x); (2 * j + all_F[k]->V.x);
(*partsDisplacement)[last][k - 1].x = (*partsDisplacement)[last][k - 1].x =
disposition[k - 1]->x[index]; disposition[k - 1]->x[index];
(*partsDisplacement)[last][k - 1].y = (*partsDisplacement)[last][k - 1].y =
disposition[k - 1]->y[index]; disposition[k - 1]->y[index];
} }
} }
last++; last++;
} }
...@@ -1063,14 +1063,14 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -1063,14 +1063,14 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// Computation the maximum of the score function // Computation the maximum of the score function
// //
// API // API
// int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, // int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const featurePyramid *H, float b, const featurePyramid *H, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float *score, float *score,
CvPoint **points, int **levels, int *kPoints, CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement); CvPoint ***partsDisplacement);
// INPUT // INPUT
// all_F - the set of filters (the first element is root filter, // all_F - the set of filters (the first element is root filter,
the other - part filters) the other - part filters)
// n - the number of part filters // n - the number of part filters
// H - feature pyramid // H - feature pyramid
...@@ -1086,17 +1086,17 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n, ...@@ -1086,17 +1086,17 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// RESULT // RESULT
// Error status // Error status
*/ */
int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, float b, const CvLSVMFeaturePyramid *H, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float *score, float *score,
CvPoint **points, int **levels, int *kPoints, CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement) CvPoint ***partsDisplacement)
{ {
int l, i, j, k, s, f, level, numLevels; int l, i, j, k, s, f, level, numLevels;
float *tmpScore; float *tmpScore;
CvPoint ***tmpPoints; CvPoint ***tmpPoints;
CvPoint ****tmpPartsDisplacement; CvPoint ****tmpPartsDisplacement;
int *tmpKPoints; int *tmpKPoints;
float maxScore; float maxScore;
int res; int res;
...@@ -1104,15 +1104,15 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1104,15 +1104,15 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
/* DEBUG /* DEBUG
FILE *file; FILE *file;
//*/ //*/
// Computation the number of levels for seaching object, // Computation the number of levels for seaching object,
// first lambda-levels are used for computation values // first lambda-levels are used for computation values
// of score function for each position of root filter // of score function for each position of root filter
numLevels = H->numLevels - LAMBDA; numLevels = H->numLevels - LAMBDA;
// Allocation memory for maximum value of score function for each level // Allocation memory for maximum value of score function for each level
tmpScore = (float *)malloc(sizeof(float) * numLevels); tmpScore = (float *)malloc(sizeof(float) * numLevels);
// Allocation memory for the set of points that corresponds // Allocation memory for the set of points that corresponds
// to the maximum of score function // to the maximum of score function
tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels); tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels);
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1125,7 +1125,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1125,7 +1125,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
{ {
tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **)); tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **));
} }
// Number of points that corresponds to the maximum // Number of points that corresponds to the maximum
// of score function on each level // of score function on each level
tmpKPoints = (int *)malloc(sizeof(int) * numLevels); tmpKPoints = (int *)malloc(sizeof(int) * numLevels);
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1134,11 +1134,11 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1134,11 +1134,11 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
} }
// Set current value of the maximum of score function // Set current value of the maximum of score function
res = maxFunctionalScoreFixedLevel(all_F, n, H, LAMBDA, b, res = maxFunctionalScoreFixedLevel(all_F, n, H, LAMBDA, b,
maxXBorder, maxYBorder, maxXBorder, maxYBorder,
&(tmpScore[0]), &(tmpScore[0]),
tmpPoints[0], tmpPoints[0],
&(tmpKPoints[0]), &(tmpKPoints[0]),
tmpPartsDisplacement[0]); tmpPartsDisplacement[0]);
maxScore = tmpScore[0]; maxScore = tmpScore[0];
(*kPoints) = tmpKPoints[0]; (*kPoints) = tmpKPoints[0];
...@@ -1147,18 +1147,18 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1147,18 +1147,18 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// and getting the maximum on all levels // and getting the maximum on all levels
/* DEBUG: maxScore /* DEBUG: maxScore
file = fopen("maxScore.csv", "w+"); file = fopen("maxScore.csv", "w+");
fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]); fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);
//*/ //*/
for (l = LAMBDA + 1; l < H->numLevels; l++) for (l = LAMBDA + 1; l < H->numLevels; l++)
{ {
k = l - LAMBDA; k = l - LAMBDA;
res = maxFunctionalScoreFixedLevel(all_F, n, H, l, b, res = maxFunctionalScoreFixedLevel(all_F, n, H, l, b,
maxXBorder, maxYBorder, maxXBorder, maxYBorder,
&(tmpScore[k]), &(tmpScore[k]),
tmpPoints[k], tmpPoints[k],
&(tmpKPoints[k]), &(tmpKPoints[k]),
tmpPartsDisplacement[k]); tmpPartsDisplacement[k]);
//fprintf(file, "%i;%lf;\n", l, tmpScore[k]); //fprintf(file, "%i;%lf;\n", l, tmpScore[k]);
if (res != LATENT_SVM_OK) if (res != LATENT_SVM_OK)
{ {
continue; continue;
...@@ -1178,7 +1178,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1178,7 +1178,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Allocation memory for levels // Allocation memory for levels
(*levels) = (int *)malloc(sizeof(int) * (*kPoints)); (*levels) = (int *)malloc(sizeof(int) * (*kPoints));
// Allocation memory for the set of points // Allocation memory for the set of points
(*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints));
// Allocation memory for parts displacement // Allocation memory for parts displacement
(*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints)); (*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints));
...@@ -1190,7 +1190,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1190,7 +1190,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS) if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS)
{ {
// Computation the number of level // Computation the number of level
level = i + LAMBDA; level = i + LAMBDA;
// Addition a set of points // Addition a set of points
f += tmpKPoints[i]; f += tmpKPoints[i];
...@@ -1199,11 +1199,11 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1199,11 +1199,11 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
(*levels)[j] = level; (*levels)[j] = level;
(*points)[j] = (*tmpPoints[i])[j - s]; (*points)[j] = (*tmpPoints[i])[j - s];
(*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s]; (*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s];
} }
s = f; s = f;
} /* if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS) */ } /* if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS) */
} }
(*score) = maxScore; (*score) = maxScore;
// Release allocated memory // Release allocated memory
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1214,24 +1214,24 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1214,24 +1214,24 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
free(tmpPoints); free(tmpPoints);
free(tmpScore); free(tmpScore);
free(tmpKPoints); free(tmpKPoints);
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
/* /*
// Computation score function that exceed threshold // Computation score function that exceed threshold
// //
// API // API
// int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, // int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const featurePyramid *H, const featurePyramid *H,
float b, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float scoreThreshold, float scoreThreshold,
float **score, float **score,
CvPoint **points, int **levels, int *kPoints, CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement); CvPoint ***partsDisplacement);
// INPUT // INPUT
// all_F - the set of filters (the first element is root filter, // all_F - the set of filters (the first element is root filter,
the other - part filters) the other - part filters)
// n - the number of part filters // n - the number of part filters
// H - feature pyramid // H - feature pyramid
...@@ -1248,35 +1248,35 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1248,35 +1248,35 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// RESULT // RESULT
// Error status // Error status
*/ */
int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, const CvLSVMFeaturePyramid *H,
float b, float b,
int maxXBorder, int maxYBorder, int maxXBorder, int maxYBorder,
float scoreThreshold, float scoreThreshold,
float **score, float **score,
CvPoint **points, int **levels, int *kPoints, CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement) CvPoint ***partsDisplacement)
{ {
int l, i, j, k, s, f, level, numLevels; int l, i, j, k, s, f, level, numLevels;
float **tmpScore; float **tmpScore;
CvPoint ***tmpPoints; CvPoint ***tmpPoints;
CvPoint ****tmpPartsDisplacement; CvPoint ****tmpPartsDisplacement;
int *tmpKPoints; int *tmpKPoints;
int res; int res;
/* DEBUG /* DEBUG
FILE *file; FILE *file;
//*/ //*/
// Computation the number of levels for seaching object, // Computation the number of levels for seaching object,
// first lambda-levels are used for computation values // first lambda-levels are used for computation values
// of score function for each position of root filter // of score function for each position of root filter
numLevels = H->numLevels - LAMBDA; numLevels = H->numLevels - LAMBDA;
// Allocation memory for values of score function for each level // Allocation memory for values of score function for each level
// that exceed threshold // that exceed threshold
tmpScore = (float **)malloc(sizeof(float*) * numLevels); tmpScore = (float **)malloc(sizeof(float*) * numLevels);
// Allocation memory for the set of points that corresponds // Allocation memory for the set of points that corresponds
// to the maximum of score function // to the maximum of score function
tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels); tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels);
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1289,7 +1289,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1289,7 +1289,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
{ {
tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **)); tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **));
} }
// Number of points that corresponds to the maximum // Number of points that corresponds to the maximum
// of score function on each level // of score function on each level
tmpKPoints = (int *)malloc(sizeof(int) * numLevels); tmpKPoints = (int *)malloc(sizeof(int) * numLevels);
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1301,20 +1301,20 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1301,20 +1301,20 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// and getting the maximum on all levels // and getting the maximum on all levels
/* DEBUG: maxScore /* DEBUG: maxScore
file = fopen("maxScore.csv", "w+"); file = fopen("maxScore.csv", "w+");
fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]); fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);
//*/ //*/
(*kPoints) = 0; (*kPoints) = 0;
for (l = LAMBDA; l < H->numLevels; l++) for (l = LAMBDA; l < H->numLevels; l++)
{ {
k = l - LAMBDA; k = l - LAMBDA;
//printf("Score at the level %i\n", l); //printf("Score at the level %i\n", l);
res = thresholdFunctionalScoreFixedLevel(all_F, n, H, l, b, res = thresholdFunctionalScoreFixedLevel(all_F, n, H, l, b,
maxXBorder, maxYBorder, scoreThreshold, maxXBorder, maxYBorder, scoreThreshold,
&(tmpScore[k]), &(tmpScore[k]),
tmpPoints[k], tmpPoints[k],
&(tmpKPoints[k]), &(tmpKPoints[k]),
tmpPartsDisplacement[k]); tmpPartsDisplacement[k]);
//fprintf(file, "%i;%lf;\n", l, tmpScore[k]); //fprintf(file, "%i;%lf;\n", l, tmpScore[k]);
if (res != LATENT_SVM_OK) if (res != LATENT_SVM_OK)
{ {
continue; continue;
...@@ -1322,11 +1322,11 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1322,11 +1322,11 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
(*kPoints) += tmpKPoints[k]; (*kPoints) += tmpKPoints[k];
} }
//fclose(file); //fclose(file);
// Allocation memory for levels // Allocation memory for levels
(*levels) = (int *)malloc(sizeof(int) * (*kPoints)); (*levels) = (int *)malloc(sizeof(int) * (*kPoints));
// Allocation memory for the set of points // Allocation memory for the set of points
(*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints));
// Allocation memory for parts displacement // Allocation memory for parts displacement
(*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints)); (*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints));
// Allocation memory for score function values // Allocation memory for score function values
...@@ -1338,7 +1338,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1338,7 +1338,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
{ {
// Computation the number of level // Computation the number of level
level = i + LAMBDA; level = i + LAMBDA;
// Addition a set of points // Addition a set of points
f += tmpKPoints[i]; f += tmpKPoints[i];
...@@ -1348,7 +1348,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1348,7 +1348,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
(*points)[j] = (*tmpPoints[i])[j - s]; (*points)[j] = (*tmpPoints[i])[j - s];
(*score)[j] = tmpScore[i][j - s]; (*score)[j] = tmpScore[i][j - s];
(*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s]; (*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s];
} }
s = f; s = f;
} }
...@@ -1362,30 +1362,30 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1362,30 +1362,30 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
free(tmpScore); free(tmpScore);
free(tmpKPoints); free(tmpKPoints);
free(tmpPartsDisplacement); free(tmpPartsDisplacement);
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
/* /*
// Creating schedule of pyramid levels processing // Creating schedule of pyramid levels processing
// //
// API // API
// int createSchedule(const featurePyramid *H, const filterObject **all_F, // int createSchedule(const featurePyramid *H, const filterObject **all_F,
const int n, const int bx, const int by, const int n, const int bx, const int by,
const int threadsNum, int *kLevels, const int threadsNum, int *kLevels,
int **processingLevels) int **processingLevels)
// INPUT // INPUT
// H - feature pyramid // H - feature pyramid
// all_F - the set of filters (the first element is root filter, // all_F - the set of filters (the first element is root filter,
the other - part filters) the other - part filters)
// n - the number of part filters // n - the number of part filters
// bx - size of nullable border (X direction) // bx - size of nullable border (X direction)
// by - size of nullable border (Y direction) // by - size of nullable border (Y direction)
// threadsNum - number of threads that will be created in TBB version // threadsNum - number of threads that will be created in TBB version
// OUTPUT // OUTPUT
// kLevels - array that contains number of levels processed // kLevels - array that contains number of levels processed
by each thread by each thread
// processingLevels - array that contains lists of levels processed // processingLevels - array that contains lists of levels processed
by each thread by each thread
// RESULT // RESULT
// Error status // Error status
...@@ -1423,9 +1423,9 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all ...@@ -1423,9 +1423,9 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
lambda = LAMBDA; lambda = LAMBDA;
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
{ {
dotProd[i] = H->pyramid[i + lambda]->sizeX * dotProd[i] = H->pyramid[i + lambda]->sizeX *
H->pyramid[i + lambda]->sizeY * rootFilterDim + H->pyramid[i + lambda]->sizeY * rootFilterDim +
(H->pyramid[i]->sizeX + dbx) * (H->pyramid[i]->sizeX + dbx) *
(H->pyramid[i]->sizeY + dby) * sumPartFiltersDim; (H->pyramid[i]->sizeY + dby) * sumPartFiltersDim;
numDotProducts += dotProd[i]; numDotProducts += dotProd[i];
} }
...@@ -1523,17 +1523,17 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all ...@@ -1523,17 +1523,17 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
#ifdef HAVE_TBB #ifdef HAVE_TBB
/* /*
// int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, // int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, const CvLSVMFeaturePyramid *H,
const float b, const float b,
const int maxXBorder, const int maxYBorder, const int maxXBorder, const int maxYBorder,
const float scoreThreshold, const float scoreThreshold,
const int threadsNum, const int threadsNum,
float **score, float **score,
CvPoint **points, int **levels, int *kPoints, CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement); CvPoint ***partsDisplacement);
// INPUT // INPUT
// all_F - the set of filters (the first element is root filter, // all_F - the set of filters (the first element is root filter,
the other - part filters) the other - part filters)
// n - the number of part filters // n - the number of part filters
// H - feature pyramid // H - feature pyramid
...@@ -1551,26 +1551,26 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all ...@@ -1551,26 +1551,26 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
// RESULT // RESULT
// Error status // Error status
*/ */
int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, const CvLSVMFeaturePyramid *H,
const float b, const float b,
const int maxXBorder, const int maxYBorder, const int maxXBorder, const int maxYBorder,
const float scoreThreshold, const float scoreThreshold,
const int threadsNum, const int threadsNum,
float **score, float **score,
CvPoint **points, int **levels, int *kPoints, CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement) CvPoint ***partsDisplacement)
{ {
int i, j, s, f, level, numLevels; int i, j, s, f, level, numLevels;
float **tmpScore; float **tmpScore;
CvPoint ***tmpPoints; CvPoint ***tmpPoints;
CvPoint ****tmpPartsDisplacement; CvPoint ****tmpPartsDisplacement;
int *tmpKPoints; int *tmpKPoints;
int res; int res;
int *kLevels, **procLevels; int *kLevels, **procLevels;
int bx, by; int bx, by;
// Computation the number of levels for seaching object, // Computation the number of levels for seaching object,
// first lambda-levels are used for computation values // first lambda-levels are used for computation values
// of score function for each position of root filter // of score function for each position of root filter
...@@ -1583,7 +1583,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1583,7 +1583,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
{ {
for (i = 0; i < threadsNum; i++) for (i = 0; i < threadsNum; i++)
{ {
if (procLevels[i] != NULL) if (procLevels[i] != NULL)
{ {
free(procLevels[i]); free(procLevels[i]);
} }
...@@ -1592,11 +1592,11 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1592,11 +1592,11 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
free(kLevels); free(kLevels);
return res; return res;
} }
// Allocation memory for values of score function for each level // Allocation memory for values of score function for each level
// that exceed threshold // that exceed threshold
tmpScore = (float **)malloc(sizeof(float*) * numLevels); tmpScore = (float **)malloc(sizeof(float*) * numLevels);
// Allocation memory for the set of points that corresponds // Allocation memory for the set of points that corresponds
// to the maximum of score function // to the maximum of score function
tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels); tmpPoints = (CvPoint ***)malloc(sizeof(CvPoint **) * numLevels);
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1609,7 +1609,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1609,7 +1609,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
{ {
tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **)); tmpPartsDisplacement[i] = (CvPoint ***)malloc(sizeof(CvPoint **));
} }
// Number of points that corresponds to the maximum // Number of points that corresponds to the maximum
// of score function on each level // of score function on each level
tmpKPoints = (int *)malloc(sizeof(int) * numLevels); tmpKPoints = (int *)malloc(sizeof(int) * numLevels);
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
...@@ -1620,19 +1620,19 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1620,19 +1620,19 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Computation maxima of score function on each level // Computation maxima of score function on each level
// and getting the maximum on all levels using TBB tasks // and getting the maximum on all levels using TBB tasks
tbbTasksThresholdFunctionalScore(all_F, n, H, b, maxXBorder, maxYBorder, tbbTasksThresholdFunctionalScore(all_F, n, H, b, maxXBorder, maxYBorder,
scoreThreshold, kLevels, procLevels, scoreThreshold, kLevels, procLevels,
threadsNum, tmpScore, tmpPoints, threadsNum, tmpScore, tmpPoints,
tmpKPoints, tmpPartsDisplacement); tmpKPoints, tmpPartsDisplacement);
(*kPoints) = 0; (*kPoints) = 0;
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
{ {
(*kPoints) += tmpKPoints[i]; (*kPoints) += tmpKPoints[i];
} }
// Allocation memory for levels // Allocation memory for levels
(*levels) = (int *)malloc(sizeof(int) * (*kPoints)); (*levels) = (int *)malloc(sizeof(int) * (*kPoints));
// Allocation memory for the set of points // Allocation memory for the set of points
(*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); (*points) = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints));
// Allocation memory for parts displacement // Allocation memory for parts displacement
(*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints)); (*partsDisplacement) = (CvPoint **)malloc(sizeof(CvPoint *) * (*kPoints));
// Allocation memory for score function values // Allocation memory for score function values
...@@ -1644,7 +1644,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1644,7 +1644,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
for (i = 0; i < numLevels; i++) for (i = 0; i < numLevels; i++)
{ {
// Computation the number of level // Computation the number of level
level = i + LAMBDA;//H->lambda; level = i + LAMBDA;//H->lambda;
// Addition a set of points // Addition a set of points
f += tmpKPoints[i]; f += tmpKPoints[i];
...@@ -1654,7 +1654,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1654,7 +1654,7 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
(*points)[j] = (*tmpPoints[i])[j - s]; (*points)[j] = (*tmpPoints[i])[j - s];
(*score)[j] = tmpScore[i][j - s]; (*score)[j] = tmpScore[i][j - s];
(*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s]; (*partsDisplacement)[j] = (*(tmpPartsDisplacement[i]))[j - s];
} }
s = f; s = f;
} }
...@@ -1681,20 +1681,20 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n, ...@@ -1681,20 +1681,20 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
void sort(int n, const float* x, int* indices) void sort(int n, const float* x, int* indices)
{ {
int i, j; int i, j;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) for (j = i + 1; j < n; j++)
{ {
if (x[indices[j]] > x[indices[i]]) if (x[indices[j]] > x[indices[i]])
{ {
//float x_tmp = x[i]; //float x_tmp = x[i];
int index_tmp = indices[i]; int index_tmp = indices[i];
//x[i] = x[j]; //x[i] = x[j];
indices[i] = indices[j]; indices[i] = indices[j];
//x[j] = x_tmp; //x[j] = x_tmp;
indices[j] = index_tmp; indices[j] = index_tmp;
} }
} }
} }
/* /*
...@@ -1702,18 +1702,18 @@ void sort(int n, const float* x, int* indices) ...@@ -1702,18 +1702,18 @@ void sort(int n, const float* x, int* indices)
// to remove "similar" bounding boxes // to remove "similar" bounding boxes
// //
// API // API
// int nonMaximumSuppression(int numBoxes, const CvPoint *points, // int nonMaximumSuppression(int numBoxes, const CvPoint *points,
const CvPoint *oppositePoints, const float *score, const CvPoint *oppositePoints, const float *score,
float overlapThreshold, float overlapThreshold,
int *numBoxesOut, CvPoint **pointsOut, int *numBoxesOut, CvPoint **pointsOut,
CvPoint **oppositePointsOut, float **scoreOut); CvPoint **oppositePointsOut, float **scoreOut);
// INPUT // INPUT
// numBoxes - number of bounding boxes // numBoxes - number of bounding boxes
// points - array of left top corner coordinates // points - array of left top corner coordinates
// oppositePoints - array of right bottom corner coordinates // oppositePoints - array of right bottom corner coordinates
// score - array of detection scores // score - array of detection scores
// overlapThreshold - threshold: bounding box is removed if overlap part // overlapThreshold - threshold: bounding box is removed if overlap part
is greater than passed value is greater than passed value
// OUTPUT // OUTPUT
// numBoxesOut - the number of bounding boxes algorithm returns // numBoxesOut - the number of bounding boxes algorithm returns
// pointsOut - array of left top corner coordinates // pointsOut - array of left top corner coordinates
...@@ -1722,80 +1722,80 @@ void sort(int n, const float* x, int* indices) ...@@ -1722,80 +1722,80 @@ void sort(int n, const float* x, int* indices)
// RESULT // RESULT
// Error status // Error status
*/ */
int nonMaximumSuppression(int numBoxes, const CvPoint *points, int nonMaximumSuppression(int numBoxes, const CvPoint *points,
const CvPoint *oppositePoints, const float *score, const CvPoint *oppositePoints, const float *score,
float overlapThreshold, float overlapThreshold,
int *numBoxesOut, CvPoint **pointsOut, int *numBoxesOut, CvPoint **pointsOut,
CvPoint **oppositePointsOut, float **scoreOut) CvPoint **oppositePointsOut, float **scoreOut)
{ {
int i, j, index; int i, j, index;
float* box_area = (float*)malloc(numBoxes * sizeof(float)); float* box_area = (float*)malloc(numBoxes * sizeof(float));
int* indices = (int*)malloc(numBoxes * sizeof(int)); int* indices = (int*)malloc(numBoxes * sizeof(int));
int* is_suppressed = (int*)malloc(numBoxes * sizeof(int)); int* is_suppressed = (int*)malloc(numBoxes * sizeof(int));
for (i = 0; i < numBoxes; i++) for (i = 0; i < numBoxes; i++)
{ {
indices[i] = i; indices[i] = i;
is_suppressed[i] = 0; is_suppressed[i] = 0;
box_area[i] = (float)( (oppositePoints[i].x - points[i].x + 1) * box_area[i] = (float)( (oppositePoints[i].x - points[i].x + 1) *
(oppositePoints[i].y - points[i].y + 1)); (oppositePoints[i].y - points[i].y + 1));
} }
sort(numBoxes, score, indices); sort(numBoxes, score, indices);
for (i = 0; i < numBoxes; i++) for (i = 0; i < numBoxes; i++)
{ {
if (!is_suppressed[indices[i]]) if (!is_suppressed[indices[i]])
{ {
for (j = i + 1; j < numBoxes; j++) for (j = i + 1; j < numBoxes; j++)
{ {
if (!is_suppressed[indices[j]]) if (!is_suppressed[indices[j]])
{ {
int x1max = max(points[indices[i]].x, points[indices[j]].x); int x1max = max(points[indices[i]].x, points[indices[j]].x);
int x2min = min(oppositePoints[indices[i]].x, oppositePoints[indices[j]].x); int x2min = min(oppositePoints[indices[i]].x, oppositePoints[indices[j]].x);
int y1max = max(points[indices[i]].y, points[indices[j]].y); int y1max = max(points[indices[i]].y, points[indices[j]].y);
int y2min = min(oppositePoints[indices[i]].y, oppositePoints[indices[j]].y); int y2min = min(oppositePoints[indices[i]].y, oppositePoints[indices[j]].y);
int overlapWidth = x2min - x1max + 1; int overlapWidth = x2min - x1max + 1;
int overlapHeight = y2min - y1max + 1; int overlapHeight = y2min - y1max + 1;
if (overlapWidth > 0 && overlapHeight > 0) if (overlapWidth > 0 && overlapHeight > 0)
{ {
float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]]; float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]];
if (overlapPart > overlapThreshold) if (overlapPart > overlapThreshold)
{ {
is_suppressed[indices[j]] = 1; is_suppressed[indices[j]] = 1;
} }
} }
} }
} }
} }
} }
*numBoxesOut = 0; *numBoxesOut = 0;
for (i = 0; i < numBoxes; i++) for (i = 0; i < numBoxes; i++)
{ {
if (!is_suppressed[i]) (*numBoxesOut)++; if (!is_suppressed[i]) (*numBoxesOut)++;
} }
*pointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint)); *pointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint));
*oppositePointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint)); *oppositePointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint));
*scoreOut = (float *)malloc((*numBoxesOut) * sizeof(float)); *scoreOut = (float *)malloc((*numBoxesOut) * sizeof(float));
index = 0; index = 0;
for (i = 0; i < numBoxes; i++) for (i = 0; i < numBoxes; i++)
{ {
if (!is_suppressed[indices[i]]) if (!is_suppressed[indices[i]])
{ {
(*pointsOut)[index].x = points[indices[i]].x; (*pointsOut)[index].x = points[indices[i]].x;
(*pointsOut)[index].y = points[indices[i]].y; (*pointsOut)[index].y = points[indices[i]].y;
(*oppositePointsOut)[index].x = oppositePoints[indices[i]].x; (*oppositePointsOut)[index].x = oppositePoints[indices[i]].x;
(*oppositePointsOut)[index].y = oppositePoints[indices[i]].y; (*oppositePointsOut)[index].y = oppositePoints[indices[i]].y;
(*scoreOut)[index] = score[indices[i]]; (*scoreOut)[index] = score[indices[i]];
index++; index++;
} }
} }
free(indices); free(indices);
free(box_area); free(box_area);
free(is_suppressed); free(is_suppressed);
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment