Fixed bug #1663
This commit is contained in:
parent
082e988173
commit
2ca6a50546
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,13 +207,13 @@ int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
|
|||||||
|
|
||||||
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);
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1713,7 +1713,7 @@ void sort(int n, const float* x, int* indices)
|
|||||||
// 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
|
||||||
@ -1729,73 +1729,73 @@ int nonMaximumSuppression(int numBoxes, const CvPoint *points,
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user