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 n1, m1, n2, m2, p, size, diff1, diff2;
|
||||
int i1, i2, j1, j2, k;
|
||||
float tmp_f1, tmp_f2, tmp_f3, tmp_f4;
|
||||
float *pMap = NULL;
|
||||
float *pH = NULL;
|
||||
int i1, i2, j1, j2, k;
|
||||
float tmp_f1, tmp_f2, tmp_f3, tmp_f4;
|
||||
float *pMap = NULL;
|
||||
float *pH = NULL;
|
||||
|
||||
n1 = map->sizeY;
|
||||
m1 = map->sizeX;
|
||||
n2 = Fi->sizeY;
|
||||
m2 = Fi->sizeX;
|
||||
p = map->numFeatures;
|
||||
n1 = map->sizeY;
|
||||
m1 = map->sizeX;
|
||||
n2 = Fi->sizeY;
|
||||
m2 = Fi->sizeX;
|
||||
p = map->numFeatures;
|
||||
|
||||
diff1 = n1 - n2 + 1;
|
||||
diff2 = m1 - m2 + 1;
|
||||
size = diff1 * diff2;
|
||||
for (j1 = diff2 - 1; j1 >= 0; j1--)
|
||||
{
|
||||
diff1 = n1 - n2 + 1;
|
||||
diff2 = m1 - m2 + 1;
|
||||
size = diff1 * diff2;
|
||||
for (j1 = diff2 - 1; j1 >= 0; j1--)
|
||||
{
|
||||
|
||||
for (i1 = diff1 - 1; i1 >= 0; i1--)
|
||||
{
|
||||
tmp_f1 = 0.0f;
|
||||
tmp_f2 = 0.0f;
|
||||
tmp_f3 = 0.0f;
|
||||
tmp_f4 = 0.0f;
|
||||
for (i2 = 0; i2 < n2; i2++)
|
||||
{
|
||||
for (j2 = 0; j2 < m2; j2++)
|
||||
{
|
||||
pMap = map->map + (i1 + i2) * m1 * p + (j1 + j2) * p;//sm2
|
||||
pH = Fi->H + (i2 * m2 + j2) * p;//sm2
|
||||
for (k = 0; k < p/4; k++)
|
||||
{
|
||||
for (i1 = diff1 - 1; i1 >= 0; i1--)
|
||||
{
|
||||
tmp_f1 = 0.0f;
|
||||
tmp_f2 = 0.0f;
|
||||
tmp_f3 = 0.0f;
|
||||
tmp_f4 = 0.0f;
|
||||
for (i2 = 0; i2 < n2; i2++)
|
||||
{
|
||||
for (j2 = 0; j2 < m2; j2++)
|
||||
{
|
||||
pMap = map->map + (i1 + i2) * m1 * p + (j1 + j2) * p;//sm2
|
||||
pH = Fi->H + (i2 * m2 + j2) * p;//sm2
|
||||
for (k = 0; k < p/4; k++)
|
||||
{
|
||||
|
||||
tmp_f1 += pMap[4*k]*pH[4*k];//sm2
|
||||
tmp_f2 += pMap[4*k+1]*pH[4*k+1];
|
||||
tmp_f3 += pMap[4*k+2]*pH[4*k+2];
|
||||
tmp_f4 += pMap[4*k+3]*pH[4*k+3];
|
||||
}
|
||||
tmp_f1 += pMap[4*k]*pH[4*k];//sm2
|
||||
tmp_f2 += pMap[4*k+1]*pH[4*k+1];
|
||||
tmp_f3 += pMap[4*k+2]*pH[4*k+2];
|
||||
tmp_f4 += pMap[4*k+3]*pH[4*k+3];
|
||||
}
|
||||
|
||||
if (p%4==1)
|
||||
{
|
||||
tmp_f1 += pH[p-1]*pMap[p-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p%4==2)
|
||||
{
|
||||
tmp_f1 += pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p%4==3)
|
||||
{
|
||||
tmp_f1 += pH[p-3]*pMap[p-3] + pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p%4==1)
|
||||
{
|
||||
tmp_f1 += pH[p-1]*pMap[p-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p%4==2)
|
||||
{
|
||||
tmp_f1 += pH[p-2]*pMap[p-2] + pH[p-1]*pMap[p-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p%4==3)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -207,13 +207,13 @@ int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
|
||||
|
||||
filterSize = filter->sizeX * filter->sizeY;
|
||||
mapSize = mapDimX * mapDimY;
|
||||
newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));
|
||||
rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);
|
||||
|
||||
res = allocFFTImage(image, filter->numFeatures, mapDimX, mapDimY);
|
||||
if (res != LATENT_SVM_OK)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));
|
||||
rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);
|
||||
for (i = 0; i < 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)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = i + 1; j < n; j++)
|
||||
{
|
||||
if (x[indices[j]] > x[indices[i]])
|
||||
{
|
||||
//float x_tmp = x[i];
|
||||
int index_tmp = indices[i];
|
||||
//x[i] = x[j];
|
||||
indices[i] = indices[j];
|
||||
//x[j] = x_tmp;
|
||||
indices[j] = index_tmp;
|
||||
}
|
||||
}
|
||||
int i, j;
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = i + 1; j < n; j++)
|
||||
{
|
||||
if (x[indices[j]] > x[indices[i]])
|
||||
{
|
||||
//float x_tmp = x[i];
|
||||
int index_tmp = indices[i];
|
||||
//x[i] = x[j];
|
||||
indices[i] = indices[j];
|
||||
//x[j] = x_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
|
||||
// score - array of detection scores
|
||||
// overlapThreshold - threshold: bounding box is removed if overlap part
|
||||
is greater than passed value
|
||||
is greater than passed value
|
||||
// OUTPUT
|
||||
// numBoxesOut - the number of bounding boxes algorithm returns
|
||||
// pointsOut - array of left top corner coordinates
|
||||
@ -1729,73 +1729,73 @@ int nonMaximumSuppression(int numBoxes, const CvPoint *points,
|
||||
CvPoint **oppositePointsOut, float **scoreOut)
|
||||
{
|
||||
int i, j, index;
|
||||
float* box_area = (float*)malloc(numBoxes * sizeof(float));
|
||||
int* indices = (int*)malloc(numBoxes * sizeof(int));
|
||||
int* is_suppressed = (int*)malloc(numBoxes * sizeof(int));
|
||||
float* box_area = (float*)malloc(numBoxes * sizeof(float));
|
||||
int* indices = (int*)malloc(numBoxes * sizeof(int));
|
||||
int* is_suppressed = (int*)malloc(numBoxes * sizeof(int));
|
||||
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
indices[i] = i;
|
||||
is_suppressed[i] = 0;
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
indices[i] = i;
|
||||
is_suppressed[i] = 0;
|
||||
box_area[i] = (float)( (oppositePoints[i].x - points[i].x + 1) *
|
||||
(oppositePoints[i].y - points[i].y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
sort(numBoxes, score, indices);
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
if (!is_suppressed[indices[i]])
|
||||
{
|
||||
for (j = i + 1; j < numBoxes; j++)
|
||||
{
|
||||
if (!is_suppressed[indices[j]])
|
||||
{
|
||||
sort(numBoxes, score, indices);
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
if (!is_suppressed[indices[i]])
|
||||
{
|
||||
for (j = i + 1; j < numBoxes; j++)
|
||||
{
|
||||
if (!is_suppressed[indices[j]])
|
||||
{
|
||||
int x1max = max(points[indices[i]].x, points[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 y2min = min(oppositePoints[indices[i]].y, oppositePoints[indices[j]].y);
|
||||
int overlapWidth = x2min - x1max + 1;
|
||||
int overlapHeight = y2min - y1max + 1;
|
||||
if (overlapWidth > 0 && overlapHeight > 0)
|
||||
{
|
||||
float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]];
|
||||
if (overlapPart > overlapThreshold)
|
||||
{
|
||||
is_suppressed[indices[j]] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int overlapWidth = x2min - x1max + 1;
|
||||
int overlapHeight = y2min - y1max + 1;
|
||||
if (overlapWidth > 0 && overlapHeight > 0)
|
||||
{
|
||||
float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]];
|
||||
if (overlapPart > overlapThreshold)
|
||||
{
|
||||
is_suppressed[indices[j]] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*numBoxesOut = 0;
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
if (!is_suppressed[i]) (*numBoxesOut)++;
|
||||
}
|
||||
*numBoxesOut = 0;
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
if (!is_suppressed[i]) (*numBoxesOut)++;
|
||||
}
|
||||
|
||||
*pointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint));
|
||||
*oppositePointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint));
|
||||
*scoreOut = (float *)malloc((*numBoxesOut) * sizeof(float));
|
||||
index = 0;
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
if (!is_suppressed[indices[i]])
|
||||
{
|
||||
index = 0;
|
||||
for (i = 0; i < numBoxes; i++)
|
||||
{
|
||||
if (!is_suppressed[indices[i]])
|
||||
{
|
||||
(*pointsOut)[index].x = points[indices[i]].x;
|
||||
(*pointsOut)[index].y = points[indices[i]].y;
|
||||
(*oppositePointsOut)[index].x = oppositePoints[indices[i]].x;
|
||||
(*oppositePointsOut)[index].y = oppositePoints[indices[i]].y;
|
||||
(*scoreOut)[index] = score[indices[i]];
|
||||
index++;
|
||||
}
|
||||
(*scoreOut)[index] = score[indices[i]];
|
||||
index++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
free(indices);
|
||||
free(box_area);
|
||||
free(is_suppressed);
|
||||
free(indices);
|
||||
free(box_area);
|
||||
free(is_suppressed);
|
||||
|
||||
return LATENT_SVM_OK;
|
||||
return LATENT_SVM_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user