refactoring latentSVM

This commit is contained in:
Evgeniy Kozinov 2011-07-12 18:43:41 +00:00
parent ea8e27961e
commit 07eed8c489
10 changed files with 354 additions and 409 deletions

View File

@ -160,9 +160,9 @@ CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
// (x, y) - coordinate in level l
typedef struct
{
unsigned int x;
unsigned int y;
unsigned int l;
int x;
int y;
int l;
} CvLSVMFilterPosition;
// DataType: STRUCT filterObject
@ -179,16 +179,12 @@ typedef struct
// used formula H[(j * sizeX + i) * p + k], where
// k - component of feature vector in cell (i, j)
// END OF FILTER DESCRIPTION
// xp - auxillary parameter for internal use
// size of row in feature vectors
// (yp = (int) (p / xp); p = xp * yp)
typedef struct{
CvLSVMFilterPosition V;
float fineFunction[4];
unsigned int sizeX;
unsigned int sizeY;
unsigned int p;
unsigned int xp;
int sizeX;
int sizeY;
int numFeatures;
float *H;
} CvLSVMFilterObject;

View File

@ -37,10 +37,7 @@
// RESULT
// Error status
*/
int getFeaturePyramid(IplImage * image,
const int lambda, const int k,
const int startX, const int startY,
const int W, const int H, CvLSVMFeaturePyramid **maps);
int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps);
/*
// Getting feature map for the selected subimage
@ -55,7 +52,7 @@ int getFeaturePyramid(IplImage * image,
// RESULT
// Error status
*/
int getFeatureMaps_dp(const IplImage * image, const int k, CvLSVMFeatureMap **map);
int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMap **map);
/*
@ -71,7 +68,7 @@ int getFeatureMaps_dp(const IplImage * image, const int k, CvLSVMFeatureMap **ma
// RESULT
// Error status
*/
int normalizationAndTruncationFeatureMaps(CvLSVMFeatureMap *map, const float alfa);
int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa);
/*
// Feature map reduction

View File

@ -2,6 +2,7 @@
#define LSVM_ERROR
#define LATENT_SVM_OK 0
#define LATENT_SVM_MEM_NULL 2
#define DISTANCE_TRANSFORM_OK 1
#define DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR -1
#define DISTANCE_TRANSFORM_ERROR -2

View File

@ -13,18 +13,18 @@
// Error status is return value
//////////////////////////////////////////////////////////////
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX, const int sizeY,
const int p, const int xp);
const int p);
int freeFilterObject (CvLSVMFilterObject **obj);
int allocFeatureMapObject(CvLSVMFeatureMap **obj, const int sizeX, const int sizeY,
const int p, const int xp);
const int p);
int freeFeatureMapObject (CvLSVMFeatureMap **obj);
#ifdef __cplusplus
extern "C"
#endif
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj,
const int lambda, const int countLevel);
const int countLevel);
#ifdef __cplusplus
extern "C"

View File

@ -14,7 +14,7 @@
// The number of elements in bin
// The number of sectors in gradient histogram building
#define CNTPARTION 9
#define NUM_SECTOR 9
// The number of levels in image resize procedure
// We need Lambda levels to resize image twice
@ -23,6 +23,8 @@
// Block size. Used in feature pyramid building procedure
#define SIDE_LENGTH 8
#define VAL_OF_TRUNCATE 0.2f
//////////////////////////////////////////////////////////////
// main data structures //
//////////////////////////////////////////////////////////////
@ -30,31 +32,24 @@
// DataType: STRUCT featureMap
// FEATURE MAP DESCRIPTION
// Rectangular map (sizeX x sizeY),
// every cell stores feature vector (dimension = p)
// H - matrix of feature vectors
// every cell stores feature vector (dimension = numFeatures)
// map - matrix of feature vectors
// to set and get feature vectors (i,j)
// used formula Map[(j * sizeX + i) * p + k], where
// used formula map[(j * sizeX + i) * p + k], where
// k - component of feature vector in cell (i, j)
// END OF FEATURE MAP DESCRIPTION
// xp - auxillary parameter for internal use
// size of row in feature vectors
// (yp = (int) (p / xp); p = xp * yp)
typedef struct{
int sizeX;
int sizeY;
int p;
int xp;
float *Map;
int numFeatures;
float *map;
} CvLSVMFeatureMap;
// DataType: STRUCT featurePyramid
//
// countLevel - number of levels in the feature pyramid
// lambda - resize scale coefficient
// numLevels - number of levels in the feature pyramid
// pyramid - array of pointers to feature map at different levels
typedef struct{
int countLevel;
int lambda;
int numLevels;
CvLSVMFeatureMap **pyramid;
} CvLSVMFeaturePyramid;
@ -74,14 +69,14 @@ typedef struct{
// DataType: STRUCT fftImage
// The structure stores FFT image
//
// p - number of channels
// numFeatures - number of channels
// x - array of FFT images for 2d signals
// n - number of rows
// m - number of collums
typedef struct{
unsigned int p;
unsigned int dimX;
unsigned int dimY;
int numFeatures;
int dimX;
int dimY;
float **channels;
} CvLSVMFftImage;

View File

@ -10,13 +10,6 @@
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
static inline int sign(float r)
{
if(r > 0.0001f) return 1;
if(r < -0.0001f) return -1;
return 0;
}
/*
// Getting feature map for the selected subimage
//
@ -30,115 +23,132 @@ static inline int sign(float r)
// RESULT
// Error status
*/
int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map)
{
int sizeX, sizeY;
int p, px, strsz;
int height, width, channels;
int p, px, stringSize;
int height, width, numChannels;
int i, j, kk, c, ii, jj, d;
float * datadx, * datady;
float tmp, x, y, tx, ty;
//íîìåð êàíàëà â öèêëå
int ch;
//ïåðåìåííûå âû÷èñëåíèÿ ìàãíèòóäû
float magnitude, x, y, tx, ty;
IplImage * dx, * dy;
int *nearest_x, *nearest_y;
int *nearest;
float *w, a_x, b_x;
// ÿäðî äëÿ âû÷èñëåíèÿ ãðàäèåíòîâ èçîáðàæåíèå ïî îñÿì x è y
float kernel[3] = {-1.f, 0.f, 1.f};
CvMat kernel_dx = cvMat(1, 3, CV_32F, kernel);
CvMat kernel_dy = cvMat(3, 1, CV_32F, kernel);
// ãðà÷åíèå ãðàäèåíòà
float * r;
int * alfa;
// íîâåð ñåêòîðà êóäà ïîïàëî çíà÷åíèå ãðàäèåíòà
// ÷åòíûå èííåêñû íå êîíòðàñòíîå èçîáðàæåíèå
// íå ÷åòíûå èííåêñû êîíòðàñòíîå èçîáðàæåíèå
int * alfa;
float boundary_x[CNTPARTION+1];
float boundary_y[CNTPARTION+1];
float max, tmp_scal;
int maxi;
// âåêòîðû ãðàíèö ñåêòîðîâ
float boundary_x[NUM_SECTOR + 1];
float boundary_y[NUM_SECTOR + 1];
float max, dotProd;
int maxi;
height = image->height;
width = image->width ;
height = image->height;
width = image->width ;
channels = image->nChannels;
numChannels = image->nChannels;
dx = cvCreateImage(cvSize(image->width , image->height) , IPL_DEPTH_32F , 3);
dy = cvCreateImage(cvSize(image->width , image->height) , IPL_DEPTH_32F , 3);
dx = cvCreateImage(cvSize(image->width, image->height),
IPL_DEPTH_32F, 3);
dy = cvCreateImage(cvSize(image->width, image->height),
IPL_DEPTH_32F, 3);
sizeX = width / k;
sizeY = height / k;
px = CNTPARTION + 2 * CNTPARTION; // êîíòðàñòíîå è íå êîíòðàñòíîå èçîáðàæåíèå
px = 3 * NUM_SECTOR; // êîíòðàñòíîå è íå êîíòðàñòíîå èçîáðàæåíèå
p = px;
strsz = sizeX * p;
allocFeatureMapObject(map, sizeX, sizeY, p, px);
stringSize = sizeX * p;
allocFeatureMapObject(map, sizeX, sizeY, p);
cvFilter2D(image, dx, &kernel_dx, cvPoint(-1, 0));
cvFilter2D(image, dy, &kernel_dy, cvPoint(0, -1));
cvFilter2D(image, dx, &kernel_dx, cvPoint(-1, 0));
cvFilter2D(image, dy, &kernel_dy, cvPoint(0, -1));
for(i = 0; i <= CNTPARTION; i++)
float arg_vector;
for(i = 0; i <= NUM_SECTOR; i++)
{
boundary_x[i] = cosf((((float)i) * (((float)PI) / (float) (CNTPARTION))));
boundary_y[i] = sinf((((float)i) * (((float)PI) / (float) (CNTPARTION))));
}/*for(i = 0; i <= CNTPARTION; i++) */
arg_vector = ( (float) i ) * ( (float)(PI) / (float)(NUM_SECTOR) );
boundary_x[i] = cosf(arg_vector);
boundary_y[i] = sinf(arg_vector);
}/*for(i = 0; i <= NUM_SECTOR; i++) */
r = (float *)malloc( sizeof(float) * (width * height));
alfa = (int *)malloc( sizeof(int ) * (width * height * 2));
for(j = 1; j < height-1; j++)
for(j = 1; j < height - 1; j++)
{
datadx = (float*)(dx->imageData + dx->widthStep *j);
datady = (float*)(dy->imageData + dy->widthStep *j);
for(i = 1; i < width-1; i++)
datadx = (float*)(dx->imageData + dx->widthStep * j);
datady = (float*)(dy->imageData + dy->widthStep * j);
for(i = 1; i < width - 1; i++)
{
c = 0;
x = (datadx[i*channels+c]);
y = (datady[i*channels+c]);
c = 0;
x = (datadx[i * numChannels + c]);
y = (datady[i * numChannels + c]);
r[j * width + i] =sqrtf(x*x + y*y);
for(kk = 1; kk < channels; kk++)
r[j * width + i] =sqrtf(x * x + y * y);
for(ch = 1; ch < numChannels; ch++)
{
tx = (datadx[i*channels+kk]);
ty = (datady[i*channels+kk]);
tmp =sqrtf(tx*tx + ty*ty);
if(tmp > r[j * width + i])
tx = (datadx[i * numChannels + ch]);
ty = (datady[i * numChannels + ch]);
magnitude = sqrtf(tx * tx + ty * ty);
if(magnitude > r[j * width + i])
{
r[j * width + i] = tmp;
c = kk;
r[j * width + i] = magnitude;
c = ch;
x = tx;
y = ty;
}
}/*for(kk = 1; kk < channels; kk++)*/
}/*for(ch = 1; ch < numChannels; ch++)*/
max = boundary_x[0]*x + boundary_y[0]*y;
max = boundary_x[0] * x + boundary_y[0] * y;
maxi = 0;
for (kk = 0; kk < CNTPARTION; kk++) {
tmp_scal = boundary_x[kk]*x + boundary_y[kk]*y;
if (tmp_scal> max) {
max = tmp_scal;
for (kk = 0; kk < NUM_SECTOR; kk++)
{
dotProd = boundary_x[kk] * x + boundary_y[kk] * y;
if (dotProd > max)
{
max = dotProd;
maxi = kk;
}else if (-tmp_scal> max) {
max = -tmp_scal;
maxi = kk + CNTPARTION;
}
else
{
if (-dotProd > max)
{
max = -dotProd;
maxi = kk + NUM_SECTOR;
}
}
}
alfa[j * width * 2 + i * 2 ] = maxi % CNTPARTION;
alfa[j * width * 2 + i * 2 ] = maxi % NUM_SECTOR;
alfa[j * width * 2 + i * 2 + 1] = maxi;
}/*for(i = 0; i < width; i++)*/
}/*for(j = 0; j < height; j++)*/
//ïîäñ÷åò âåñîâ è ñìåùåíèé
nearest_x = (int *)malloc(sizeof(int) * k);
nearest_y = (int *)malloc(sizeof(int) * k);
w = (float*)malloc(sizeof(float) * (k * 2));
nearest = (int *)malloc(sizeof(int ) * k);
w = (float*)malloc(sizeof(float) * (k * 2));
for(i = 0; i < k / 2; i++)
{
nearest_x[i] = -1;
nearest_y[i] = -1;
nearest[i] = -1;
}/*for(i = 0; i < k / 2; i++)*/
for(i = k / 2; i < k; i++)
{
nearest_x[i] = 1;
nearest_y[i] = 1;
nearest[i] = 1;
}/*for(i = k / 2; i < k; i++)*/
for(j = 0; j < k / 2; j++)
@ -160,44 +170,52 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
//èíòåðïîëÿöèÿ
for(i = 0; i < sizeY; i++)
{
for(j = 0; j < sizeX; j++)
for(j = 0; j < sizeX; j++)
{
for(ii = 0; ii < k; ii++)
{
for(ii = 0; ii < k; ii++)
for(jj = 0; jj < k; jj++)
{
if ((i * k + ii > 0) &&
(i * k + ii < height - 1) &&
(j * k + jj > 0) &&
(j * k + jj < width - 1))
{
for(jj = 0; jj < k; jj++)
{
if ((i * k + ii > 0) && (i * k + ii < height - 1) && (j * k + jj > 0) && (j * k + jj < width - 1))
{
d = (k*i + ii)* width + (j*k + jj);
(*map)->Map[(i ) * strsz + (j ) * (*map)->p + alfa[d * 2 ] ] +=
r[d] * w[ii * 2 ] * w[jj * 2 ];
(*map)->Map[(i ) * strsz + (j ) * (*map)->p + alfa[d * 2 + 1] + CNTPARTION] +=
r[d] * w[ii * 2 ] * w[jj * 2 ];
if ((i + nearest_y[ii] >= 0) && (i + nearest_y[ii] <= sizeY - 1))
{
(*map)->Map[(i + nearest_y[ii]) * strsz + (j ) * (*map)->p + alfa[d * 2 ] ] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 ];
(*map)->Map[(i + nearest_y[ii]) * strsz + (j ) * (*map)->p + alfa[d * 2 + 1] + CNTPARTION] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 ];
}
if ((j + nearest_x[jj] >= 0) && (j + nearest_x[jj] <= sizeX - 1))
{
(*map)->Map[(i ) * strsz + (j + nearest_x[jj]) * (*map)->p + alfa[d * 2 ] ] +=
r[d] * w[ii * 2 ] * w[jj * 2 + 1];
(*map)->Map[(i ) * strsz + (j + nearest_x[jj]) * (*map)->p + alfa[d * 2 + 1] + CNTPARTION] +=
r[d] * w[ii * 2 ] * w[jj * 2 + 1];
}
if ((i + nearest_y[ii] >= 0) && (i + nearest_y[ii] <= sizeY - 1) && (j + nearest_x[jj] >= 0) && (j + nearest_x[jj] <= sizeX - 1))
{
(*map)->Map[(i + nearest_y[ii]) * strsz + (j + nearest_x[jj]) * (*map)->p + alfa[d * 2 ] ] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 + 1];
(*map)->Map[(i + nearest_y[ii]) * strsz + (j + nearest_x[jj]) * (*map)->p + alfa[d * 2 + 1] + CNTPARTION] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 + 1];
}
}
}/*for(jj = 0; jj < k; jj++)*/
}/*for(ii = 0; ii < k; ii++)*/
}/*for(j = 1; j < sizeX - 1; j++)*/
d = (k * i + ii) * width + (j * k + jj);
(*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 ]] +=
r[d] * w[ii * 2] * w[jj * 2];
(*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
r[d] * w[ii * 2] * w[jj * 2];
if ((i + nearest[ii] >= 0) &&
(i + nearest[ii] <= sizeY - 1))
{
(*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 ] ] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 ];
(*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 ];
}
if ((j + nearest[jj] >= 0) &&
(j + nearest[jj] <= sizeX - 1))
{
(*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] +=
r[d] * w[ii * 2] * w[jj * 2 + 1];
(*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
r[d] * w[ii * 2] * w[jj * 2 + 1];
}
if ((i + nearest[ii] >= 0) &&
(i + nearest[ii] <= sizeY - 1) &&
(j + nearest[jj] >= 0) &&
(j + nearest[jj] <= sizeX - 1))
{
(*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 + 1];
(*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
r[d] * w[ii * 2 + 1] * w[jj * 2 + 1];
}
}
}/*for(jj = 0; jj < k; jj++)*/
}/*for(ii = 0; ii < k; ii++)*/
}/*for(j = 1; j < sizeX - 1; j++)*/
}/*for(i = 1; i < sizeY - 1; i++)*/
cvReleaseImage(&dx);
@ -205,8 +223,7 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
free(w);
free(nearest_x);
free(nearest_y);
free(nearest);
free(r);
free(alfa);
@ -218,7 +235,7 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
// Feature map Normalization and Truncation
//
// API
// int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa);
// int normalizeAndTruncate(featureMap *map, const float alfa);
// INPUT
// map - feature map
// alfa - truncation threshold
@ -227,114 +244,113 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
// RESULT
// Error status
*/
int normalizationAndTruncationFeatureMaps(CvLSVMFeatureMap *map, const float alfa)
int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa)
{
int i,j, ii;
int sizeX, sizeY, p, pos, pp, xp, pos1, pos2;
float * part_noma; // norm of C(i, j)
float * new_data;
float norm_val;
float * partOfNorm; // norm of C(i, j)
float * newData;
float valOfNorm;
sizeX = map->sizeX;
sizeY = map->sizeY;
part_noma = (float *)malloc (sizeof(float) * (sizeX * sizeY));
partOfNorm = (float *)malloc (sizeof(float) * (sizeX * sizeY));
p = map->xp / 3;
p = NUM_SECTOR;
xp = NUM_SECTOR * 3;
pp = NUM_SECTOR * 12;
for(i = 0; i < sizeX * sizeY; i++)
{
norm_val = 0.0;
pos = i * map->p;
valOfNorm = 0.0f;
pos = i * map->numFeatures;
for(j = 0; j < p; j++)
{
norm_val += map->Map[pos + j] * map->Map[pos + j];
valOfNorm += map->map[pos + j] * map->map[pos + j];
}/*for(j = 0; j < p; j++)*/
part_noma[i] = norm_val;
partOfNorm[i] = valOfNorm;
}/*for(i = 0; i < sizeX * sizeY; i++)*/
xp = map->xp;
pp = xp * 4;
sizeX -= 2;
sizeY -= 2;
new_data = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp));
newData = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp));
//normalization
for(i = 1; i <= sizeY; i++)
{
for(j = 1; j <= sizeX; j++)
{
norm_val = sqrtf(
part_noma[(i )*(sizeX + 2) + (j )] +
part_noma[(i )*(sizeX + 2) + (j + 1)] +
part_noma[(i + 1)*(sizeX + 2) + (j )] +
part_noma[(i + 1)*(sizeX + 2) + (j + 1)]);
valOfNorm = sqrtf(
partOfNorm[(i )*(sizeX + 2) + (j )] +
partOfNorm[(i )*(sizeX + 2) + (j + 1)] +
partOfNorm[(i + 1)*(sizeX + 2) + (j )] +
partOfNorm[(i + 1)*(sizeX + 2) + (j + 1)]);
pos1 = (i ) * (sizeX + 2) * xp + (j ) * xp;
pos2 = (i-1) * (sizeX ) * pp + (j-1) * pp;
for(ii = 0; ii < p; ii++)
{
new_data[pos2 + ii ] = map->Map[pos1 + ii ] / norm_val;
newData[pos2 + ii ] = map->map[pos1 + ii ] / valOfNorm;
}/*for(ii = 0; ii < p; ii++)*/
for(ii = 0; ii < 2 * p; ii++)
{
new_data[pos2 + ii + p * 4] = map->Map[pos1 + ii + p] / norm_val;
newData[pos2 + ii + p * 4] = map->map[pos1 + ii + p] / valOfNorm;
}/*for(ii = 0; ii < 2 * p; ii++)*/
norm_val = sqrtf(
part_noma[(i )*(sizeX + 2) + (j )] +
part_noma[(i )*(sizeX + 2) + (j + 1)] +
part_noma[(i - 1)*(sizeX + 2) + (j )] +
part_noma[(i - 1)*(sizeX + 2) + (j + 1)]);
valOfNorm = sqrtf(
partOfNorm[(i )*(sizeX + 2) + (j )] +
partOfNorm[(i )*(sizeX + 2) + (j + 1)] +
partOfNorm[(i - 1)*(sizeX + 2) + (j )] +
partOfNorm[(i - 1)*(sizeX + 2) + (j + 1)]);
for(ii = 0; ii < p; ii++)
{
new_data[pos2 + ii + p ] = map->Map[pos1 + ii ] / norm_val;
newData[pos2 + ii + p ] = map->map[pos1 + ii ] / valOfNorm;
}/*for(ii = 0; ii < p; ii++)*/
for(ii = 0; ii < 2 * p; ii++)
{
new_data[pos2 + ii + p * 6] = map->Map[pos1 + ii + p] / norm_val;
newData[pos2 + ii + p * 6] = map->map[pos1 + ii + p] / valOfNorm;
}/*for(ii = 0; ii < 2 * p; ii++)*/
norm_val = sqrtf(
part_noma[(i )*(sizeX + 2) + (j )] +
part_noma[(i )*(sizeX + 2) + (j - 1)] +
part_noma[(i + 1)*(sizeX + 2) + (j )] +
part_noma[(i + 1)*(sizeX + 2) + (j - 1)]);
valOfNorm = sqrtf(
partOfNorm[(i )*(sizeX + 2) + (j )] +
partOfNorm[(i )*(sizeX + 2) + (j - 1)] +
partOfNorm[(i + 1)*(sizeX + 2) + (j )] +
partOfNorm[(i + 1)*(sizeX + 2) + (j - 1)]);
for(ii = 0; ii < p; ii++)
{
new_data[pos2 + ii + p * 2] = map->Map[pos1 + ii ] / norm_val;
newData[pos2 + ii + p * 2] = map->map[pos1 + ii ] / valOfNorm;
}/*for(ii = 0; ii < p; ii++)*/
for(ii = 0; ii < 2 * p; ii++)
{
new_data[pos2 + ii + p * 8] = map->Map[pos1 + ii + p] / norm_val;
newData[pos2 + ii + p * 8] = map->map[pos1 + ii + p] / valOfNorm;
}/*for(ii = 0; ii < 2 * p; ii++)*/
norm_val = sqrtf(
part_noma[(i )*(sizeX + 2) + (j )] +
part_noma[(i )*(sizeX + 2) + (j - 1)] +
part_noma[(i - 1)*(sizeX + 2) + (j )] +
part_noma[(i - 1)*(sizeX + 2) + (j - 1)]);
valOfNorm = sqrtf(
partOfNorm[(i )*(sizeX + 2) + (j )] +
partOfNorm[(i )*(sizeX + 2) + (j - 1)] +
partOfNorm[(i - 1)*(sizeX + 2) + (j )] +
partOfNorm[(i - 1)*(sizeX + 2) + (j - 1)]);
for(ii = 0; ii < p; ii++)
{
new_data[pos2 + ii + p * 3 ] = map->Map[pos1 + ii ] / norm_val;
newData[pos2 + ii + p * 3 ] = map->map[pos1 + ii ] / valOfNorm;
}/*for(ii = 0; ii < p; ii++)*/
for(ii = 0; ii < 2 * p; ii++)
{
new_data[pos2 + ii + p * 10] = map->Map[pos1 + ii + p] / norm_val;
newData[pos2 + ii + p * 10] = map->map[pos1 + ii + p] / valOfNorm;
}/*for(ii = 0; ii < 2 * p; ii++)*/
}/*for(j = 1; j <= sizeX; j++)*/
}/*for(i = 1; i <= sizeY; i++)*/
//truncation
for(i = 0; i < sizeX * sizeY * pp; i++)
{
if(new_data [i] > alfa) new_data [i] = alfa;
if(newData [i] > alfa) newData [i] = alfa;
}/*for(i = 0; i < sizeX * sizeY * pp; i++)*/
//swop data
map->p = pp;
map->xp = xp;
map->numFeatures = pp;
map->sizeX = sizeX;
map->sizeY = sizeY;
free (map->Map);
free (part_noma);
free (map->map);
free (partOfNorm);
map->Map = new_data;
map->map = newData;
return LATENT_SVM_OK;
}
@ -356,21 +372,21 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
{
int i,j, ii, jj, k;
int sizeX, sizeY, p, pp, xp, yp, pos1, pos2;
float * new_data;
float * newData;
float val;
float nx, ny;
sizeX = map->sizeX;
sizeY = map->sizeY;
p = map->p;
pp = map->xp + 4;
p = map->numFeatures;
pp = NUM_SECTOR * 3 + 4;
yp = 4;
xp = (map->xp / 3);
xp = NUM_SECTOR;
nx = 1.0f / sqrtf((float)(xp * 2));
ny = 1.0f / sqrtf((float)(yp ));
new_data = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp));
newData = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp));
for(i = 0; i < sizeY; i++)
{
@ -384,9 +400,9 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
val = 0;
for(ii = 0; ii < yp; ii++)
{
val += map->Map[pos1 + yp * xp + ii * xp * 2 + jj];
val += map->map[pos1 + yp * xp + ii * xp * 2 + jj];
}/*for(ii = 0; ii < yp; ii++)*/
new_data[pos2 + k] = val * ny;
newData[pos2 + k] = val * ny;
k++;
}/*for(jj = 0; jj < xp * 2; jj++)*/
for(jj = 0; jj < xp; jj++)
@ -394,9 +410,9 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
val = 0;
for(ii = 0; ii < yp; ii++)
{
val += map->Map[pos1 + ii * xp + jj];
val += map->map[pos1 + ii * xp + jj];
}/*for(ii = 0; ii < yp; ii++)*/
new_data[pos2 + k] = val * ny;
newData[pos2 + k] = val * ny;
k++;
}/*for(jj = 0; jj < xp; jj++)*/
for(ii = 0; ii < yp; ii++)
@ -404,25 +420,47 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
val = 0;
for(jj = 0; jj < 2 * xp; jj++)
{
val += map->Map[pos1 + yp * xp + ii * xp * 2 + jj];
val += map->map[pos1 + yp * xp + ii * xp * 2 + jj];
}/*for(jj = 0; jj < xp; jj++)*/
new_data[pos2 + k] = val * nx;
newData[pos2 + k] = val * nx;
k++;
} /*for(ii = 0; ii < yp; ii++)*/
}/*for(j = 0; j < sizeX; j++)*/
}/*for(i = 0; i < sizeY; i++)*/
//swop data
map->p = pp;
map->xp = pp;
map->numFeatures = pp;
free (map->Map);
free (map->map);
map->Map = new_data;
map->map = newData;
return LATENT_SVM_OK;
}
int getPathOfFeaturePyramid(IplImage * image,
float step, int numStep, int startIndex,
int sideLength, CvLSVMFeaturePyramid **maps)
{
CvLSVMFeatureMap *map;
IplImage *scaleTmp;
float scale;
int i, err;
for(i = 0; i < numStep; i++)
{
scale = 1.0f / powf(step, (float)i);
scaleTmp = resize_opencv (image, scale);
err = getFeatureMaps(scaleTmp, sideLength, &map);
err = normalizeAndTruncate(map, VAL_OF_TRUNCATE);
err = PCAFeatureMaps(map);
(*maps)->pyramid[startIndex + i] = map;
cvReleaseImage(&scaleTmp);
}/*for(i = 0; i < numStep; i++)*/
return LATENT_SVM_OK;
}
/*
// Getting feature pyramid
//
@ -434,145 +472,52 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
const int W, const int H, featurePyramid **maps);
// INPUT
// image - image
// lambda - resize scale
// k - size of cells
// startX - X coordinate of the image rectangle to search
// startY - Y coordinate of the image rectangle to search
// W - width of the image rectangle to search
// H - height of the image rectangle to search
// OUTPUT
// maps - feature maps for all levels
// RESULT
// Error status
*/
int getFeaturePyramid(IplImage * image,
const int lambda, const int k,
const int startX, const int startY,
const int W, const int H, CvLSVMFeaturePyramid **maps)
int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps)
{
IplImage *img2, *imgTmp, *imgResize;
float step, tmp;
int cntStep;
int maxcall;
int i;
int err;
CvLSVMFeatureMap *map;
IplImage *imgResize;
float step;
int numStep;
int maxNumCells;
int W, H;
//geting subimage
cvSetImageROI(image, cvRect(startX, startY, W, H));
img2 = cvCreateImage(cvGetSize(image), image->depth, image->nChannels);
cvCopy(image, img2, NULL);
cvResetImageROI(image);
if(img2->depth != IPL_DEPTH_32F)
if(image->depth == IPL_DEPTH_32F)
{
imgResize = cvCreateImage(cvSize(img2->width , img2->height) , IPL_DEPTH_32F , 3);
cvConvert(img2, imgResize);
imgResize = image;
}
else
{
imgResize = img2;
imgResize = cvCreateImage(cvSize(image->width , image->height) ,
IPL_DEPTH_32F , 3);
cvConvert(image, imgResize);
}
step = powf(2.0f, 1.0f/ ((float)lambda));
maxcall = W/k;
if( maxcall > H/k )
W = imgResize->width;
H = imgResize->height;
step = powf(2.0f, 1.0f / ((float)LAMBDA));
maxNumCells = W / SIDE_LENGTH;
if( maxNumCells > H / SIDE_LENGTH )
{
maxcall = H/k;
maxNumCells = H / SIDE_LENGTH;
}
cntStep = (int)(logf((float)maxcall/(5.0f))/logf(step)) + 1;
//printf("Count step: %f %d\n", step, cntStep);
numStep = (int)(logf((float) maxNumCells / (5.0f)) / logf( step )) + 1;
allocFeaturePyramidObject(maps, lambda, cntStep + lambda);
allocFeaturePyramidObject(maps, numStep + LAMBDA);
for(i = 0; i < lambda; i++)
{
tmp = 1.0f / powf(step, (float)i);
imgTmp = resize_opencv (imgResize, tmp);
//imgTmp = resize_article_dp(img2, tmp, 4);
err = getFeatureMaps_dp(imgTmp, 4, &map);
err = normalizationAndTruncationFeatureMaps(map, 0.2f);
err = PCAFeatureMaps(map);
(*maps)->pyramid[i] = map;
//printf("%d, %d\n", map->sizeY, map->sizeX);
cvReleaseImage(&imgTmp);
}
getPathOfFeaturePyramid(imgResize, step , LAMBDA, 0,
SIDE_LENGTH / 2, maps);
getPathOfFeaturePyramid(imgResize, step, numStep, LAMBDA,
SIDE_LENGTH , maps);
/**********************************one**************/
for(i = 0; i < cntStep; i++)
{
tmp = 1.0f / powf(step, (float)i);
imgTmp = resize_opencv (imgResize, tmp);
//imgTmp = resize_article_dp(imgResize, tmp, 8);
err = getFeatureMaps_dp(imgTmp, 8, &map);
err = normalizationAndTruncationFeatureMaps(map, 0.2f);
err = PCAFeatureMaps(map);
(*maps)->pyramid[i + lambda] = map;
//printf("%d, %d\n", map->sizeY, map->sizeX);
cvReleaseImage(&imgTmp);
}/*for(i = 0; i < cntStep; i++)*/
if(img2->depth != IPL_DEPTH_32F)
if(image->depth != IPL_DEPTH_32F)
{
cvReleaseImage(&imgResize);
}
cvReleaseImage(&img2);
return LATENT_SVM_OK;
}
/*
// add zero border to feature map
//
// API
// int addBordersToFeatureMaps(featureMap *map, const int bX, const int bY);
// INPUT
// map - feature map
// bX - border size in x
// bY - border size in y
// OUTPUT
// map - feature map
// RESULT
// Error status
*/
int addBordersToFeatureMaps(CvLSVMFeatureMap *map, const int bX, const int bY){
int i,j, jj;
int sizeX, sizeY, p, pos1, pos2;
float * new_data;
sizeX = map->sizeX;
sizeY = map->sizeY;
p = map->p;
new_data = (float *)malloc (sizeof(float) * ((sizeX + 2 * bX) * (sizeY + 2 * bY) * p));
for(i = 0; i < ((sizeX + 2 * bX) * (sizeY + 2 * bY) * p); i++)
{
new_data[i] = (float)0;
}/*for(i = 0; i < ((sizeX + 2 * bX) * (sizeY + 2 * bY) * p); i++)*/
for(i = 0; i < sizeY; i++)
{
for(j = 0; j < sizeX; j++)
{
pos1 = ((i )*sizeX + (j )) * p;
pos2 = ((i + bY)*(sizeX + 2 * bX) + (j + bX)) * p;
for(jj = 0; jj < p; jj++)
{
new_data[pos2 + jj] = map->Map[pos1 + jj];
}/*for(jj = 0; jj < p; jj++)*/
}/*for(j = 0; j < sizeX; j++)*/
}/*for(i = 0; i < sizeY; i++)*/
//swop data
map->sizeX = sizeX + 2 * bX;
map->sizeY = sizeY + 2 * bY;
free (map->Map);
map->Map = new_data;
return LATENT_SVM_OK;
}

View File

@ -127,8 +127,7 @@ CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
CvLSVMFeaturePyramid *H;
// Obtaining feature pyramid
opResult = getFeaturePyramid(image, LAMBDA, SIDE_LENGTH, 0, 0,
image->width, image->height, &H);
opResult = getFeaturePyramid(image, &H);
if (opResult != LATENT_SVM_OK)
{
@ -139,7 +138,7 @@ CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
// Addition nullable border for each feature map
// the size of the border for root filters
computeBorderSize(maxXBorder, maxYBorder, &bx, &by);
for (level = 0; level < H->countLevel; level++)
for (level = 0; level < H->numLevels; level++)
{
addNullableBorder(H->pyramid[level], bx, by);
}
@ -196,7 +195,7 @@ int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F
// Transformation filter displacement from the block space
// to the space of pixels at the initial image
// that settles at the level number LAMBDA
convertPoints(H->countLevel, H->lambda, LAMBDA, (*points),
convertPoints(H->numLevels, LAMBDA, LAMBDA, (*points),
(*levels), (*partsDisplacement), (*kPoints), n,
maxXBorder, maxYBorder);
@ -305,7 +304,7 @@ int searchObjectThreshold(const CvLSVMFeaturePyramid *H,
// Transformation filter displacement from the block space
// to the space of pixels at the initial image
// that settles at the level number LAMBDA
convertPoints(H->countLevel, H->lambda, LAMBDA, (*points),
convertPoints(H->numLevels, LAMBDA, LAMBDA, (*points),
(*levels), (*partsDisplacement), (*kPoints), n,
maxXBorder, maxYBorder);

View File

@ -658,8 +658,7 @@ void parserModel(FILE * xmlf, CvLSVMFilterObject *** model, int *last, int *max,
if(tagVal == EMODEL){
//printf("</Model>\n");
for(ii = 0; ii <= *last; ii++){
(*model)[ii]->p = p;
(*model)[ii]->xp = 9;
(*model)[ii]->numFeatures = p;
}
* count = N_comp;
return;

View File

@ -33,7 +33,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
m1 = map->sizeX;
n2 = Fi->sizeY;
m2 = Fi->sizeX;
p = map->p;
p = map->numFeatures;
diff1 = n1 - n2 + 1;
diff2 = m1 - m2 + 1;
@ -51,7 +51,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
{
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
for (k = 0; k < p/4; k++)
{
@ -210,14 +210,14 @@ int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
mapSize = mapDimX * mapDimY;
newFilter = (float *)malloc(sizeof(float) * (2 * mapSize));
rot2PIFilter = (float *)malloc(sizeof(float) * filterSize);
res = allocFFTImage(image, filter->p, mapDimX, mapDimY);
res = allocFFTImage(image, filter->numFeatures, mapDimX, mapDimY);
if (res != LATENT_SVM_OK)
{
return res;
}
for (i = 0; i < filter->p; i++)
for (i = 0; i < filter->numFeatures; i++)
{
rot2PI(filter->H, filter->sizeX, filter->sizeY, rot2PIFilter, filter->p, i);
rot2PI(filter->H, filter->sizeX, filter->sizeY, rot2PIFilter, filter->numFeatures, i);
addNullableBars(rot2PIFilter, filter->sizeX, filter->sizeY,
newFilter, mapDimX, mapDimY);
fft2d(newFilter, (*image)->channels[i], mapDimY, mapDimX);
@ -241,14 +241,14 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image)
{
int i, j, size;
float *buf;
allocFFTImage(image, map->p, map->sizeX, map->sizeY);
allocFFTImage(image, map->numFeatures, map->sizeX, map->sizeY);
size = map->sizeX * map->sizeY;
buf = (float *)malloc(sizeof(float) * (2 * size));
for (i = 0; i < map->p; i++)
for (i = 0; i < map->numFeatures; i++)
{
for (j = 0; j < size; j++)
{
buf[2 * j] = map->Map[j * map->p + i];
buf[2 * j] = map->map[j * map->numFeatures + i];
buf[2 * j + 1] = 0.0;
}
fft2d(buf, (*image)->channels[i], map->sizeY, map->sizeX);
@ -282,7 +282,7 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt
imagesMultRes = (float *)malloc(sizeof(float) * size);
fftImagesMulti(featMapImage->channels[0], filterImage->channels[0],
featMapImage->dimY, featMapImage->dimX, imagesMultRes);
for (i = 1; (i < (int)featMapImage->p) && (i < (int)filterImage->p); i++)
for (i = 1; (i < (int)featMapImage->numFeatures) && (i < (int)filterImage->numFeatures); i++)
{
fftImagesMulti(featMapImage->channels[i],filterImage->channels[i],
featMapImage->dimY, featMapImage->dimX, imagesMult);
@ -343,7 +343,7 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
m1 = pyramid->sizeX;
n2 = Fi->sizeY;
m2 = Fi->sizeX;
p = pyramid->p;
p = pyramid->numFeatures;
(*scoreFi) = NULL;
(*pointsX) = NULL;
(*pointsY) = NULL;
@ -429,7 +429,7 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage
m1 = featMapImage->dimX;
n2 = Fi->sizeY;
m2 = Fi->sizeX;
p = featMapImage->p;
p = featMapImage->numFeatures;
(*scoreFi) = NULL;
(*pointsX) = NULL;
(*pointsY) = NULL;
@ -525,8 +525,8 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by)
float *new_map;
sizeX = map->sizeX + 2 * bx;
sizeY = map->sizeY + 2 * by;
new_map = (float *)malloc(sizeof(float) * sizeX * sizeY * map->p);
for (i = 0; i < sizeX * sizeY * map->p; i++)
new_map = (float *)malloc(sizeof(float) * sizeX * sizeY * map->numFeatures);
for (i = 0; i < sizeX * sizeY * map->numFeatures; i++)
{
new_map[i] = 0.0;
}
@ -534,17 +534,17 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by)
{
for (j = bx; j < map->sizeX + bx; j++)
{
for (k = 0; k < map->p; k++)
for (k = 0; k < map->numFeatures; k++)
{
new_map[(i * sizeX + j) * map->p + k] =
map->Map[((i - by) * map->sizeX + j - bx) * map->p + k];
new_map[(i * sizeX + j) * map->numFeatures + k] =
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k];
}
}
}
map->sizeX = sizeX;
map->sizeY = sizeY;
free(map->Map);
map->Map = new_map;
free(map->map);
map->map = new_map;
return LATENT_SVM_OK;
}
@ -558,19 +558,19 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,
computeBorderSize(maxXBorder, maxYBorder, &bx, &by);
sizeX = map->sizeX + 2 * bx;
sizeY = map->sizeY + 2 * by;
allocFeatureMapObject(&new_map, sizeX, sizeY, map->p, map->xp);
for (i = 0; i < sizeX * sizeY * map->p; i++)
allocFeatureMapObject(&new_map, sizeX, sizeY, map->numFeatures);
for (i = 0; i < sizeX * sizeY * map->numFeatures; i++)
{
new_map->Map[i] = 0.0;
new_map->map[i] = 0.0f;
}
for (i = by; i < map->sizeY + by; i++)
{
for (j = bx; j < map->sizeX + bx; j++)
{
for (k = 0; k < map->p; k++)
for (k = 0; k < map->numFeatures; k++)
{
new_map->Map[(i * sizeX + j) * map->p + k] =
map->Map[((i - by) * map->sizeX + j - bx) * map->p + k];
new_map->map[(i * sizeX + j) * map->numFeatures + k] =
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k];
}
}
}
@ -640,7 +640,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
dimY = H->pyramid[level]->sizeY;
// Number of features
p = H->pyramid[level]->p;
p = H->pyramid[level]->numFeatures;
// Getting dimension of root filter
nF0 = all_F[0]->sizeY;
@ -888,7 +888,7 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
dimY = H->pyramid[level]->sizeY;
// Number of features
p = H->pyramid[level]->p;
p = H->pyramid[level]->numFeatures;
// Getting dimension of root filter
nF0 = all_F[0]->sizeY;
@ -1109,7 +1109,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Computation the number of levels for seaching object,
// first lambda-levels are used for computation values
// of score function for each position of root filter
numLevels = H->countLevel - H->lambda;
numLevels = H->numLevels - LAMBDA;
// Allocation memory for maximum value of score function for each level
tmpScore = (float *)malloc(sizeof(float) * numLevels);
@ -1135,7 +1135,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
}
// Set current value of the maximum of score function
res = maxFunctionalScoreFixedLevel(all_F, n, H, H->lambda, b,
res = maxFunctionalScoreFixedLevel(all_F, n, H, LAMBDA, b,
maxXBorder, maxYBorder,
&(tmpScore[0]),
tmpPoints[0],
@ -1150,9 +1150,9 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
file = fopen("maxScore.csv", "w+");
fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);
//*/
for (l = H->lambda + 1; l < H->countLevel; l++)
for (l = LAMBDA + 1; l < H->numLevels; l++)
{
k = l - H->lambda;
k = l - LAMBDA;
res = maxFunctionalScoreFixedLevel(all_F, n, H, l, b,
maxXBorder, maxYBorder,
&(tmpScore[k]),
@ -1191,7 +1191,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
if ((tmpScore[i] - maxScore) * (tmpScore[i] - maxScore) <= EPS)
{
// Computation the number of level
level = i + H->lambda;
level = i + LAMBDA;
// Addition a set of points
f += tmpKPoints[i];
@ -1272,7 +1272,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Computation the number of levels for seaching object,
// first lambda-levels are used for computation values
// of score function for each position of root filter
numLevels = H->countLevel - H->lambda;
numLevels = H->numLevels - LAMBDA;
// Allocation memory for values of score function for each level
// that exceed threshold
@ -1305,9 +1305,9 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);
//*/
(*kPoints) = 0;
for (l = H->lambda; l < H->countLevel; l++)
for (l = LAMBDA; l < H->numLevels; l++)
{
k = l - H->lambda;
k = l - LAMBDA;
//printf("Score at the level %i\n", l);
res = thresholdFunctionalScoreFixedLevel(all_F, n, H, l, b,
maxXBorder, maxYBorder, scoreThreshold,
@ -1339,7 +1339,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
for (i = 0; i < numLevels; i++)
{
// Computation the number of level
level = i + H->lambda;
level = i + LAMBDA;
// Addition a set of points
f += tmpKPoints[i];
@ -1411,7 +1411,7 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
sumPartFiltersDim += all_F[i]->sizeX * all_F[i]->sizeY;
}
// Number of levels which are used for computation of score function
numLevels = H->countLevel - H->lambda;
numLevels = H->numLevels - LAMBDA;
// Allocation memory for saving number of dot products that will be
// computed for each level of feature pyramid
dotProd = (int *)malloc(sizeof(int) * numLevels);
@ -1421,7 +1421,7 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
dby = 2 * by;
// Total number of dot products for all levels
numDotProducts = 0;
lambda = H->lambda;
lambda = LAMBDA;
for (i = 0; i < numLevels; i++)
{
dotProd[i] = H->pyramid[i + lambda]->sizeX *

View File

@ -1,13 +1,14 @@
#include "precomp.hpp"
#include "_lsvm_routine.h"
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX, const int sizeY, const int p, const int xp){
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX,
const int sizeY, const int numFeatures)
{
int i;
(*obj) = (CvLSVMFilterObject *)malloc(sizeof(CvLSVMFilterObject));
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->p = p ;
(*obj)->xp = xp ;
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->numFeatures = numFeatures;
(*obj)->fineFunction[0] = 0.0f;
(*obj)->fineFunction[1] = 0.0f;
(*obj)->fineFunction[2] = 0.0f;
@ -15,75 +16,87 @@ int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX, const int sizeY
(*obj)->V.x = 0;
(*obj)->V.y = 0;
(*obj)->V.l = 0;
(*obj)->H = (float *) malloc(sizeof (float) * (sizeX * sizeY * p));
for(i = 0; i < sizeX * sizeY * p; i++){
(*obj)->H = (float *) malloc(sizeof (float) *
(sizeX * sizeY * numFeatures));
for(i = 0; i < sizeX * sizeY * numFeatures; i++)
{
(*obj)->H[i] = 0.0f;
}
return LATENT_SVM_OK;
}
int freeFilterObject (CvLSVMFilterObject **obj){
if(*obj == NULL) return 0;
int freeFilterObject (CvLSVMFilterObject **obj)
{
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
free((*obj)->H);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFeatureMapObject(CvLSVMFeatureMap **obj, const int sizeX, const int sizeY, const int p, const int xp){
int allocFeatureMapObject(CvLSVMFeatureMap **obj, const int sizeX,
const int sizeY, const int numFeatures)
{
int i;
(*obj) = (CvLSVMFeatureMap *)malloc(sizeof(CvLSVMFeatureMap));
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->p = p ;
(*obj)->xp = xp ;
(*obj)->Map = (float *) malloc(sizeof (float) * (sizeX * sizeY * p));
for(i = 0; i < sizeX * sizeY * p; i++){
(*obj)->Map[i] = 0.0;
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->numFeatures = numFeatures;
(*obj)->map = (float *) malloc(sizeof (float) *
(sizeX * sizeY * numFeatures));
for(i = 0; i < sizeX * sizeY * numFeatures; i++)
{
(*obj)->map[i] = 0.0f;
}
return LATENT_SVM_OK;
}
int freeFeatureMapObject (CvLSVMFeatureMap **obj){
if(*obj == NULL) return 0;
free((*obj)->Map);
int freeFeatureMapObject (CvLSVMFeatureMap **obj)
{
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
free((*obj)->map);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj, const int lambda, const int countLevel){
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj,
const int numLevels)
{
(*obj) = (CvLSVMFeaturePyramid *)malloc(sizeof(CvLSVMFeaturePyramid));
(*obj)->countLevel = countLevel;
(*obj)->pyramid = (CvLSVMFeatureMap **)malloc(sizeof(CvLSVMFeatureMap *) * countLevel);
(*obj)->lambda = lambda;
(*obj)->numLevels = numLevels;
(*obj)->pyramid = (CvLSVMFeatureMap **)malloc(
sizeof(CvLSVMFeatureMap *) * numLevels);
return LATENT_SVM_OK;
}
int freeFeaturePyramidObject (CvLSVMFeaturePyramid **obj){
int freeFeaturePyramidObject (CvLSVMFeaturePyramid **obj)
{
int i;
if(*obj == NULL) return 0;
for(i = 0; i < (*obj)->countLevel; i++)
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
for(i = 0; i < (*obj)->numLevels; i++)
{
freeFeatureMapObject(&((*obj)->pyramid[i]));
}
free((*obj)->pyramid);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFFTImage(CvLSVMFftImage **image, int p, int dimX, int dimY)
int allocFFTImage(CvLSVMFftImage **image, int numFeatures, int dimX, int dimY)
{
int i, j, size;
*image = (CvLSVMFftImage *)malloc(sizeof(CvLSVMFftImage));
(*image)->p = p;
(*image)->dimX = dimX;
(*image)->dimY = dimY;
(*image)->channels = (float **)malloc(sizeof(float *) * p);
(*image)->numFeatures = numFeatures;
(*image)->dimX = dimX;
(*image)->dimY = dimY;
(*image)->channels = (float **)malloc(sizeof(float *) * numFeatures);
size = 2 * dimX * dimY;
for (i = 0; i < p; i++)
for (i = 0; i < numFeatures; i++)
{
(*image)->channels[i] = (float *)malloc(sizeof(float) * size);
for (j = 0; j < size; j++)
{
(*image)->channels[i][j] = 0.0;
(*image)->channels[i][j] = 0.0f;
}
}
return LATENT_SVM_OK;
@ -91,9 +104,9 @@ int allocFFTImage(CvLSVMFftImage **image, int p, int dimX, int dimY)
int freeFFTImage(CvLSVMFftImage **image)
{
unsigned i;
int i;
if (*image == NULL) return LATENT_SVM_OK;
for (i = 0; i < (*image)->p; i++)
for (i = 0; i < (*image)->numFeatures; i++)
{
free((*image)->channels[i]);
(*image)->channels[i] = NULL;