Commit 07eed8c4 authored by Evgeniy Kozinov's avatar Evgeniy Kozinov

refactoring latentSVM

parent ea8e2796
......@@ -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;
......
......@@ -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
......
......@@ -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
......
......@@ -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"
......
......@@ -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;
......
This diff is collapsed.
......@@ -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);
......
......@@ -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;
......
This diff is collapsed.
#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;
......
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