Normalize line endings and whitespace

This commit is contained in:
OpenCV Buildbot
2012-10-17 11:12:04 +04:00
committed by Andrey Kamaev
parent 0442bca235
commit 81f826db2b
1511 changed files with 258678 additions and 258624 deletions

View File

@@ -129,25 +129,25 @@ CV_INLINE CvTHaarFeature cvHaarFeature( const char* desc,
strcpy( &(hf.desc[0]), desc );
hf.tilted = ( hf.desc[0] == 't' );
hf.rect[0].r.x = x0;
hf.rect[0].r.y = y0;
hf.rect[0].r.width = w0;
hf.rect[0].r.height = h0;
hf.rect[0].weight = wt0;
hf.rect[1].r.x = x1;
hf.rect[1].r.y = y1;
hf.rect[1].r.width = w1;
hf.rect[1].r.height = h1;
hf.rect[1].weight = wt1;
hf.rect[2].r.x = x2;
hf.rect[2].r.y = y2;
hf.rect[2].r.width = w2;
hf.rect[2].r.height = h2;
hf.rect[2].weight = wt2;
return hf;
}
@@ -223,7 +223,7 @@ typedef struct CvCARTHaarClassifier
typedef struct CvStageHaarClassifier
{
CV_INT_HAAR_CLASSIFIER_FIELDS()
int count;
float threshold;
CvIntHaarClassifier** classifier;
@@ -342,7 +342,7 @@ int icvGetHaarTraininDataFromVecCallback( CvMat* img, void* userdata );
* icvGetHaarTrainingDataFromVec
*
* Fill <data> with samples from .vec file, passed <cascade>
int icvGetHaarTrainingDataFromVec( CvHaarTrainingData* data, int first, int count,
int icvGetHaarTrainingDataFromVec( CvHaarTrainingData* data, int first, int count,
CvIntHaarClassifier* cascade,
const char* filename,
int* consumed );

View File

@@ -153,7 +153,7 @@ typedef struct CvClassifierTrainParams
CvMat* weights CV_DEFAULT(0),
CvClassifierTrainParams* trainParams CV_DEFAULT(0)
)
*/
typedef CvClassifier* (*CvClassifierConstructor)( CvMat*, int, CvMat*, CvMat*, CvMat*,
@@ -190,7 +190,7 @@ typedef struct CvMTStumpTrainParams
CvStumpError error;
int portion; /* number of components calculated in each thread */
int numcomp; /* total number of components */
/* callback which fills <mat> with components [first, first+num[ */
void (*getTrainData)( CvMat* mat, CvMat* sampleIdx, CvMat* compIdx,
int first, int num, void* userdata );
@@ -202,10 +202,10 @@ typedef struct CvStumpClassifier
{
CV_CLASSIFIER_FIELDS()
int compidx;
float lerror; /* impurity of the right node */
float rerror; /* impurity of the left node */
float threshold;
float left;
float right;
@@ -218,7 +218,7 @@ typedef struct CvCARTTrainParams
int count;
CvClassifierTrainParams* stumpTrainParams;
CvClassifierConstructor stumpConstructor;
/*
* Split sample indices <idx>
* on the "left" indices <left> and "right" indices <right>
@@ -316,13 +316,13 @@ float cvEvalCARTClassifier( CvClassifier* classifier, CvMat* sample );
\****************************************************************************************/
/*
* CvBoostType
* CvBoostType
*
* The CvBoostType enumeration specifies the boosting type.
*
* Remarks
* Four different boosting variants for 2 class classification problems are supported:
* Discrete AdaBoost, Real AdaBoost, LogitBoost and Gentle AdaBoost.
* Discrete AdaBoost, Real AdaBoost, LogitBoost and Gentle AdaBoost.
* The L2 (2 class classification problems) and LK (K class classification problems)
* algorithms are close to LogitBoost but more numerically stable than last one.
* For regression three different loss functions are supported:
@@ -496,7 +496,7 @@ void cvBoostEndTraining( CvBoostTrainer** trainer );
typedef struct CvBtClassifier
{
CV_CLASSIFIER_FIELDS()
CvBoostType type;
int numclasses;
int numiter;

View File

@@ -97,7 +97,7 @@ int icvMkDir( const char* filename )
}
#endif /* _WIN32 */
}
p[pos] = '/';
p += pos + 1;
@@ -113,7 +113,7 @@ void icvSave( const CvArr* ptr, const char* filename, int line )
CvFileStorage* fs;
char buf[PATH_MAX];
const char* name;
name = strrchr( filename, '\\' );
if( !name ) name = strrchr( filename, '/' );
if( !name ) name = filename;

View File

@@ -101,7 +101,7 @@ void cvCreateTestSamples( const char* infoname,
* showsamples - if not 0 samples will be shown
* winwidth - sample width
* winheight - sample height
*
*
* Return number of successfully created samples
*/
int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilename,
@@ -164,7 +164,7 @@ void cvShowVecSamples( const char* filename, int winwidth, int winheight, double
*/
void cvCreateCascadeClassifier( const char* dirname,
const char* vecfilename,
const char* bgfilename,
const char* bgfilename,
int npos, int nneg, int nstages,
int numprecalculated,
int numsplits,
@@ -177,7 +177,7 @@ void cvCreateCascadeClassifier( const char* dirname,
void cvCreateTreeCascadeClassifier( const char* dirname,
const char* vecfilename,
const char* bgfilename,
const char* bgfilename,
int npos, int nneg, int nstages,
int numprecalculated,
int numsplits,

View File

@@ -22,7 +22,7 @@ set(traincascade_files traincascade.cpp
HOGfeatures.cpp HOGfeatures.h
imagestorage.cpp imagestorage.h)
set(the_target opencv_traincascade)
set(the_target opencv_traincascade)
add_executable(${the_target} ${traincascade_files})
target_link_libraries(${the_target} ${OPENCV_TRAINCASCADE_DEPS} opencv_haartraining_engine)
@@ -32,10 +32,10 @@ set_target_properties(${the_target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib
OUTPUT_NAME "opencv_traincascade")
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "applications")
endif()
endif()
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)

View File

@@ -1,248 +1,248 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "HOGfeatures.h"
#include "cascadeclassifier.h"
CvHOGFeatureParams::CvHOGFeatureParams()
{
maxCatCount = 0;
name = HOGF_NAME;
featSize = N_BINS * N_CELLS;
}
void CvHOGEvaluator::init(const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize)
{
CV_Assert( _maxSampleCount > 0);
int cols = (_winSize.width + 1) * (_winSize.height + 1);
for (int bin = 0; bin < N_BINS; bin++)
{
hist.push_back(Mat(_maxSampleCount, cols, CV_32FC1));
}
normSum.create( (int)_maxSampleCount, cols, CV_32FC1 );
CvFeatureEvaluator::init( _featureParams, _maxSampleCount, _winSize );
}
void CvHOGEvaluator::setImage(const Mat &img, uchar clsLabel, int idx)
{
CV_DbgAssert( !hist.empty());
CvFeatureEvaluator::setImage( img, clsLabel, idx );
vector<Mat> integralHist;
for (int bin = 0; bin < N_BINS; bin++)
{
integralHist.push_back( Mat(winSize.height + 1, winSize.width + 1, hist[bin].type(), hist[bin].ptr<float>((int)idx)) );
}
Mat integralNorm(winSize.height + 1, winSize.width + 1, normSum.type(), normSum.ptr<float>((int)idx));
integralHistogram(img, integralHist, integralNorm, (int)N_BINS);
}
//void CvHOGEvaluator::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
//{
// _writeFeatures( features, fs, featureMap );
//}
void CvHOGEvaluator::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
{
int featIdx;
int componentIdx;
const Mat_<int>& featureMap_ = (const Mat_<int>&)featureMap;
fs << FEATURES << "[";
for ( int fi = 0; fi < featureMap.cols; fi++ )
if ( featureMap_(0, fi) >= 0 )
{
fs << "{";
featIdx = fi / getFeatureSize();
componentIdx = fi % getFeatureSize();
features[featIdx].write( fs, componentIdx );
fs << "}";
}
fs << "]";
}
void CvHOGEvaluator::generateFeatures()
{
int offset = winSize.width + 1;
Size blockStep;
int x, y, t, w, h;
for (t = 8; t <= winSize.width/2; t+=8) //t = size of a cell. blocksize = 4*cellSize
{
blockStep = Size(4,4);
w = 2*t; //width of a block
h = 2*t; //height of a block
for (x = 0; x <= winSize.width - w; x += blockStep.width)
{
for (y = 0; y <= winSize.height - h; y += blockStep.height)
{
features.push_back(Feature(offset, x, y, t, t));
}
}
w = 2*t;
h = 4*t;
for (x = 0; x <= winSize.width - w; x += blockStep.width)
{
for (y = 0; y <= winSize.height - h; y += blockStep.height)
{
features.push_back(Feature(offset, x, y, t, 2*t));
}
}
w = 4*t;
h = 2*t;
for (x = 0; x <= winSize.width - w; x += blockStep.width)
{
for (y = 0; y <= winSize.height - h; y += blockStep.height)
{
features.push_back(Feature(offset, x, y, 2*t, t));
}
}
}
numFeatures = (int)features.size();
}
CvHOGEvaluator::Feature::Feature()
{
for (int i = 0; i < N_CELLS; i++)
{
rect[i] = Rect(0, 0, 0, 0);
}
}
CvHOGEvaluator::Feature::Feature( int offset, int x, int y, int cellW, int cellH )
{
rect[0] = Rect(x, y, cellW, cellH); //cell0
rect[1] = Rect(x+cellW, y, cellW, cellH); //cell1
rect[2] = Rect(x, y+cellH, cellW, cellH); //cell2
rect[3] = Rect(x+cellW, y+cellH, cellW, cellH); //cell3
for (int i = 0; i < N_CELLS; i++)
{
CV_SUM_OFFSETS(fastRect[i].p0, fastRect[i].p1, fastRect[i].p2, fastRect[i].p3, rect[i], offset);
}
}
void CvHOGEvaluator::Feature::write(FileStorage &fs) const
{
fs << CC_RECTS << "[";
for( int i = 0; i < N_CELLS; i++ )
{
fs << "[:" << rect[i].x << rect[i].y << rect[i].width << rect[i].height << "]";
}
fs << "]";
}
//cell and bin idx writing
//void CvHOGEvaluator::Feature::write(FileStorage &fs, int varIdx) const
//{
// int featComponent = varIdx % (N_CELLS * N_BINS);
// int cellIdx = featComponent / N_BINS;
// int binIdx = featComponent % N_BINS;
//
// fs << CC_RECTS << "[:" << rect[cellIdx].x << rect[cellIdx].y <<
// rect[cellIdx].width << rect[cellIdx].height << binIdx << "]";
//}
//cell[0] and featComponent idx writing. By cell[0] it's possible to recover all block
//All block is nessesary for block normalization
void CvHOGEvaluator::Feature::write(FileStorage &fs, int featComponentIdx) const
{
fs << CC_RECT << "[:" << rect[0].x << rect[0].y <<
rect[0].width << rect[0].height << featComponentIdx << "]";
}
void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, Mat &norm, int nbins) const
{
CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 );
int x, y, binIdx;
Size gradSize(img.size());
Size histSize(histogram[0].size());
Mat grad(gradSize, CV_32F);
Mat qangle(gradSize, CV_8U);
AutoBuffer<int> mapbuf(gradSize.width + gradSize.height + 4);
int* xmap = (int*)mapbuf + 1;
int* ymap = xmap + gradSize.width + 2;
const int borderType = (int)BORDER_REPLICATE;
for( x = -1; x < gradSize.width + 1; x++ )
xmap[x] = borderInterpolate(x, gradSize.width, borderType);
for( y = -1; y < gradSize.height + 1; y++ )
ymap[y] = borderInterpolate(y, gradSize.height, borderType);
int width = gradSize.width;
AutoBuffer<float> _dbuf(width*4);
float* dbuf = _dbuf;
Mat Dx(1, width, CV_32F, dbuf);
Mat Dy(1, width, CV_32F, dbuf + width);
Mat Mag(1, width, CV_32F, dbuf + width*2);
Mat Angle(1, width, CV_32F, dbuf + width*3);
float angleScale = (float)(nbins/CV_PI);
for( y = 0; y < gradSize.height; y++ )
{
const uchar* currPtr = img.data + img.step*ymap[y];
const uchar* prevPtr = img.data + img.step*ymap[y-1];
const uchar* nextPtr = img.data + img.step*ymap[y+1];
float* gradPtr = (float*)grad.ptr(y);
uchar* qanglePtr = (uchar*)qangle.ptr(y);
for( x = 0; x < width; x++ )
{
dbuf[x] = (float)(currPtr[xmap[x+1]] - currPtr[xmap[x-1]]);
dbuf[width + x] = (float)(nextPtr[xmap[x]] - prevPtr[xmap[x]]);
}
cartToPolar( Dx, Dy, Mag, Angle, false );
for( x = 0; x < width; x++ )
{
float mag = dbuf[x+width*2];
float angle = dbuf[x+width*3];
angle = angle*angleScale - 0.5f;
int bidx = cvFloor(angle);
angle -= bidx;
if( bidx < 0 )
bidx += nbins;
else if( bidx >= nbins )
bidx -= nbins;
qanglePtr[x] = (uchar)bidx;
gradPtr[x] = mag;
}
}
integral(grad, norm, grad.depth());
float* histBuf;
const float* magBuf;
const uchar* binsBuf;
int binsStep = (int)( qangle.step / sizeof(uchar) );
int histStep = (int)( histogram[0].step / sizeof(float) );
int magStep = (int)( grad.step / sizeof(float) );
for( binIdx = 0; binIdx < nbins; binIdx++ )
{
histBuf = (float*)histogram[binIdx].data;
magBuf = (const float*)grad.data;
binsBuf = (const uchar*)qangle.data;
memset( histBuf, 0, histSize.width * sizeof(histBuf[0]) );
histBuf += histStep + 1;
for( y = 0; y < qangle.rows; y++ )
{
histBuf[-1] = 0.f;
float strSum = 0.f;
for( x = 0; x < qangle.cols; x++ )
{
if( binsBuf[x] == binIdx )
strSum += magBuf[x];
histBuf[x] = histBuf[-histStep + x] + strSum;
}
histBuf += histStep;
binsBuf += binsStep;
magBuf += magStep;
}
}
}
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "HOGfeatures.h"
#include "cascadeclassifier.h"
CvHOGFeatureParams::CvHOGFeatureParams()
{
maxCatCount = 0;
name = HOGF_NAME;
featSize = N_BINS * N_CELLS;
}
void CvHOGEvaluator::init(const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize)
{
CV_Assert( _maxSampleCount > 0);
int cols = (_winSize.width + 1) * (_winSize.height + 1);
for (int bin = 0; bin < N_BINS; bin++)
{
hist.push_back(Mat(_maxSampleCount, cols, CV_32FC1));
}
normSum.create( (int)_maxSampleCount, cols, CV_32FC1 );
CvFeatureEvaluator::init( _featureParams, _maxSampleCount, _winSize );
}
void CvHOGEvaluator::setImage(const Mat &img, uchar clsLabel, int idx)
{
CV_DbgAssert( !hist.empty());
CvFeatureEvaluator::setImage( img, clsLabel, idx );
vector<Mat> integralHist;
for (int bin = 0; bin < N_BINS; bin++)
{
integralHist.push_back( Mat(winSize.height + 1, winSize.width + 1, hist[bin].type(), hist[bin].ptr<float>((int)idx)) );
}
Mat integralNorm(winSize.height + 1, winSize.width + 1, normSum.type(), normSum.ptr<float>((int)idx));
integralHistogram(img, integralHist, integralNorm, (int)N_BINS);
}
//void CvHOGEvaluator::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
//{
// _writeFeatures( features, fs, featureMap );
//}
void CvHOGEvaluator::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
{
int featIdx;
int componentIdx;
const Mat_<int>& featureMap_ = (const Mat_<int>&)featureMap;
fs << FEATURES << "[";
for ( int fi = 0; fi < featureMap.cols; fi++ )
if ( featureMap_(0, fi) >= 0 )
{
fs << "{";
featIdx = fi / getFeatureSize();
componentIdx = fi % getFeatureSize();
features[featIdx].write( fs, componentIdx );
fs << "}";
}
fs << "]";
}
void CvHOGEvaluator::generateFeatures()
{
int offset = winSize.width + 1;
Size blockStep;
int x, y, t, w, h;
for (t = 8; t <= winSize.width/2; t+=8) //t = size of a cell. blocksize = 4*cellSize
{
blockStep = Size(4,4);
w = 2*t; //width of a block
h = 2*t; //height of a block
for (x = 0; x <= winSize.width - w; x += blockStep.width)
{
for (y = 0; y <= winSize.height - h; y += blockStep.height)
{
features.push_back(Feature(offset, x, y, t, t));
}
}
w = 2*t;
h = 4*t;
for (x = 0; x <= winSize.width - w; x += blockStep.width)
{
for (y = 0; y <= winSize.height - h; y += blockStep.height)
{
features.push_back(Feature(offset, x, y, t, 2*t));
}
}
w = 4*t;
h = 2*t;
for (x = 0; x <= winSize.width - w; x += blockStep.width)
{
for (y = 0; y <= winSize.height - h; y += blockStep.height)
{
features.push_back(Feature(offset, x, y, 2*t, t));
}
}
}
numFeatures = (int)features.size();
}
CvHOGEvaluator::Feature::Feature()
{
for (int i = 0; i < N_CELLS; i++)
{
rect[i] = Rect(0, 0, 0, 0);
}
}
CvHOGEvaluator::Feature::Feature( int offset, int x, int y, int cellW, int cellH )
{
rect[0] = Rect(x, y, cellW, cellH); //cell0
rect[1] = Rect(x+cellW, y, cellW, cellH); //cell1
rect[2] = Rect(x, y+cellH, cellW, cellH); //cell2
rect[3] = Rect(x+cellW, y+cellH, cellW, cellH); //cell3
for (int i = 0; i < N_CELLS; i++)
{
CV_SUM_OFFSETS(fastRect[i].p0, fastRect[i].p1, fastRect[i].p2, fastRect[i].p3, rect[i], offset);
}
}
void CvHOGEvaluator::Feature::write(FileStorage &fs) const
{
fs << CC_RECTS << "[";
for( int i = 0; i < N_CELLS; i++ )
{
fs << "[:" << rect[i].x << rect[i].y << rect[i].width << rect[i].height << "]";
}
fs << "]";
}
//cell and bin idx writing
//void CvHOGEvaluator::Feature::write(FileStorage &fs, int varIdx) const
//{
// int featComponent = varIdx % (N_CELLS * N_BINS);
// int cellIdx = featComponent / N_BINS;
// int binIdx = featComponent % N_BINS;
//
// fs << CC_RECTS << "[:" << rect[cellIdx].x << rect[cellIdx].y <<
// rect[cellIdx].width << rect[cellIdx].height << binIdx << "]";
//}
//cell[0] and featComponent idx writing. By cell[0] it's possible to recover all block
//All block is nessesary for block normalization
void CvHOGEvaluator::Feature::write(FileStorage &fs, int featComponentIdx) const
{
fs << CC_RECT << "[:" << rect[0].x << rect[0].y <<
rect[0].width << rect[0].height << featComponentIdx << "]";
}
void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, Mat &norm, int nbins) const
{
CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 );
int x, y, binIdx;
Size gradSize(img.size());
Size histSize(histogram[0].size());
Mat grad(gradSize, CV_32F);
Mat qangle(gradSize, CV_8U);
AutoBuffer<int> mapbuf(gradSize.width + gradSize.height + 4);
int* xmap = (int*)mapbuf + 1;
int* ymap = xmap + gradSize.width + 2;
const int borderType = (int)BORDER_REPLICATE;
for( x = -1; x < gradSize.width + 1; x++ )
xmap[x] = borderInterpolate(x, gradSize.width, borderType);
for( y = -1; y < gradSize.height + 1; y++ )
ymap[y] = borderInterpolate(y, gradSize.height, borderType);
int width = gradSize.width;
AutoBuffer<float> _dbuf(width*4);
float* dbuf = _dbuf;
Mat Dx(1, width, CV_32F, dbuf);
Mat Dy(1, width, CV_32F, dbuf + width);
Mat Mag(1, width, CV_32F, dbuf + width*2);
Mat Angle(1, width, CV_32F, dbuf + width*3);
float angleScale = (float)(nbins/CV_PI);
for( y = 0; y < gradSize.height; y++ )
{
const uchar* currPtr = img.data + img.step*ymap[y];
const uchar* prevPtr = img.data + img.step*ymap[y-1];
const uchar* nextPtr = img.data + img.step*ymap[y+1];
float* gradPtr = (float*)grad.ptr(y);
uchar* qanglePtr = (uchar*)qangle.ptr(y);
for( x = 0; x < width; x++ )
{
dbuf[x] = (float)(currPtr[xmap[x+1]] - currPtr[xmap[x-1]]);
dbuf[width + x] = (float)(nextPtr[xmap[x]] - prevPtr[xmap[x]]);
}
cartToPolar( Dx, Dy, Mag, Angle, false );
for( x = 0; x < width; x++ )
{
float mag = dbuf[x+width*2];
float angle = dbuf[x+width*3];
angle = angle*angleScale - 0.5f;
int bidx = cvFloor(angle);
angle -= bidx;
if( bidx < 0 )
bidx += nbins;
else if( bidx >= nbins )
bidx -= nbins;
qanglePtr[x] = (uchar)bidx;
gradPtr[x] = mag;
}
}
integral(grad, norm, grad.depth());
float* histBuf;
const float* magBuf;
const uchar* binsBuf;
int binsStep = (int)( qangle.step / sizeof(uchar) );
int histStep = (int)( histogram[0].step / sizeof(float) );
int magStep = (int)( grad.step / sizeof(float) );
for( binIdx = 0; binIdx < nbins; binIdx++ )
{
histBuf = (float*)histogram[binIdx].data;
magBuf = (const float*)grad.data;
binsBuf = (const uchar*)qangle.data;
memset( histBuf, 0, histSize.width * sizeof(histBuf[0]) );
histBuf += histStep + 1;
for( y = 0; y < qangle.rows; y++ )
{
histBuf[-1] = 0.f;
float strSum = 0.f;
for( x = 0; x < qangle.cols; x++ )
{
if( binsBuf[x] == binIdx )
strSum += magBuf[x];
histBuf[x] = histBuf[-histStep + x] + strSum;
}
histBuf += histStep;
binsBuf += binsStep;
magBuf += magStep;
}
}
}

View File

@@ -1,78 +1,78 @@
#ifndef _OPENCV_HOGFEATURES_H_
#define _OPENCV_HOGFEATURES_H_
#include "traincascade_features.h"
//#define TEST_INTHIST_BUILD
//#define TEST_FEAT_CALC
#define N_BINS 9
#define N_CELLS 4
#define HOGF_NAME "HOGFeatureParams"
struct CvHOGFeatureParams : public CvFeatureParams
{
CvHOGFeatureParams();
};
class CvHOGEvaluator : public CvFeatureEvaluator
{
public:
virtual ~CvHOGEvaluator() {}
virtual void init(const CvFeatureParams *_featureParams,
int _maxSampleCount, Size _winSize );
virtual void setImage(const Mat& img, uchar clsLabel, int idx);
virtual float operator()(int varIdx, int sampleIdx) const;
virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
protected:
virtual void generateFeatures();
virtual void integralHistogram(const Mat &img, vector<Mat> &histogram, Mat &norm, int nbins) const;
class Feature
{
public:
Feature();
Feature( int offset, int x, int y, int cellW, int cellH );
float calc( const vector<Mat> &_hists, const Mat &_normSum, size_t y, int featComponent ) const;
void write( FileStorage &fs ) const;
void write( FileStorage &fs, int varIdx ) const;
Rect rect[N_CELLS]; //cells
struct
{
int p0, p1, p2, p3;
} fastRect[N_CELLS];
};
vector<Feature> features;
Mat normSum; //for nomalization calculation (L1 or L2)
vector<Mat> hist;
};
inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const
{
int featureIdx = varIdx / (N_BINS * N_CELLS);
int componentIdx = varIdx % (N_BINS * N_CELLS);
//return features[featureIdx].calc( hist, sampleIdx, componentIdx);
return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx);
}
inline float CvHOGEvaluator::Feature::calc( const vector<Mat>& _hists, const Mat& _normSum, size_t y, int featComponent ) const
{
float normFactor;
float res;
int binIdx = featComponent % N_BINS;
int cellIdx = featComponent / N_BINS;
const float *phist = _hists[binIdx].ptr<float>((int)y);
res = phist[fastRect[cellIdx].p0] - phist[fastRect[cellIdx].p1] - phist[fastRect[cellIdx].p2] + phist[fastRect[cellIdx].p3];
const float *pnormSum = _normSum.ptr<float>((int)y);
normFactor = (float)(pnormSum[fastRect[0].p0] - pnormSum[fastRect[1].p1] - pnormSum[fastRect[2].p2] + pnormSum[fastRect[3].p3]);
res = (res > 0.001f) ? ( res / (normFactor + 0.001f) ) : 0.f; //for cutting negative values, which apper due to floating precision
return res;
}
#endif // _OPENCV_HOGFEATURES_H_
#ifndef _OPENCV_HOGFEATURES_H_
#define _OPENCV_HOGFEATURES_H_
#include "traincascade_features.h"
//#define TEST_INTHIST_BUILD
//#define TEST_FEAT_CALC
#define N_BINS 9
#define N_CELLS 4
#define HOGF_NAME "HOGFeatureParams"
struct CvHOGFeatureParams : public CvFeatureParams
{
CvHOGFeatureParams();
};
class CvHOGEvaluator : public CvFeatureEvaluator
{
public:
virtual ~CvHOGEvaluator() {}
virtual void init(const CvFeatureParams *_featureParams,
int _maxSampleCount, Size _winSize );
virtual void setImage(const Mat& img, uchar clsLabel, int idx);
virtual float operator()(int varIdx, int sampleIdx) const;
virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
protected:
virtual void generateFeatures();
virtual void integralHistogram(const Mat &img, vector<Mat> &histogram, Mat &norm, int nbins) const;
class Feature
{
public:
Feature();
Feature( int offset, int x, int y, int cellW, int cellH );
float calc( const vector<Mat> &_hists, const Mat &_normSum, size_t y, int featComponent ) const;
void write( FileStorage &fs ) const;
void write( FileStorage &fs, int varIdx ) const;
Rect rect[N_CELLS]; //cells
struct
{
int p0, p1, p2, p3;
} fastRect[N_CELLS];
};
vector<Feature> features;
Mat normSum; //for nomalization calculation (L1 or L2)
vector<Mat> hist;
};
inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const
{
int featureIdx = varIdx / (N_BINS * N_CELLS);
int componentIdx = varIdx % (N_BINS * N_CELLS);
//return features[featureIdx].calc( hist, sampleIdx, componentIdx);
return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx);
}
inline float CvHOGEvaluator::Feature::calc( const vector<Mat>& _hists, const Mat& _normSum, size_t y, int featComponent ) const
{
float normFactor;
float res;
int binIdx = featComponent % N_BINS;
int cellIdx = featComponent / N_BINS;
const float *phist = _hists[binIdx].ptr<float>((int)y);
res = phist[fastRect[cellIdx].p0] - phist[fastRect[cellIdx].p1] - phist[fastRect[cellIdx].p2] + phist[fastRect[cellIdx].p3];
const float *pnormSum = _normSum.ptr<float>((int)y);
normFactor = (float)(pnormSum[fastRect[0].p0] - pnormSum[fastRect[1].p1] - pnormSum[fastRect[2].p2] + pnormSum[fastRect[3].p3]);
res = (res > 0.001f) ? ( res / (normFactor + 0.001f) ) : 0.f; //for cutting negative values, which apper due to floating precision
return res;
}
#endif // _OPENCV_HOGFEATURES_H_

View File

@@ -8,7 +8,7 @@ struct CvCascadeBoostParams : CvBoostParams
{
float minHitRate;
float maxFalseAlarm;
CvCascadeBoostParams();
CvCascadeBoostParams( int _boostType, float _minHitRate, float _maxFalseAlarm,
double _weightTrimRate, int _maxDepth, int _maxWeakCount );
@@ -37,7 +37,7 @@ struct CvCascadeBoostTrainData : CvDTreeTrainData
virtual const int* get_class_labels( CvDTreeNode* n, int* labelsBuf );
virtual const int* get_cv_labels( CvDTreeNode* n, int* labelsBuf);
virtual const int* get_sample_indices( CvDTreeNode* n, int* indicesBuf );
virtual void get_ord_var_data( CvDTreeNode* n, int vi, float* ordValuesBuf, int* sortedIndicesBuf,
const float** ordValues, const int** sortedIndices, int* sampleIndicesBuf );
virtual const int* get_cat_var_data( CvDTreeNode* n, int vi, int* catValuesBuf );

View File

@@ -76,7 +76,7 @@ public:
bool read( const FileNode &node );
void printDefaults() const;
void printAttrs() const;
void printAttrs() const;
bool scanAttr( const String prmName, const String val );
int stageType;
@@ -89,8 +89,8 @@ class CvCascadeClassifier
public:
bool train( const String _cascadeDirName,
const String _posFilename,
const String _negFilename,
int _numPos, int _numNeg,
const String _negFilename,
int _numPos, int _numNeg,
int _precalcValBufSize, int _precalcIdxBufSize,
int _numStages,
const CvCascadeParams& _cascadeParams,
@@ -109,14 +109,14 @@ private:
void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
bool readParams( const FileNode &node );
bool readStages( const FileNode &node );
void getUsedFeaturesIdxMap( Mat& featureMap );
CvCascadeParams cascadeParams;
Ptr<CvFeatureParams> featureParams;
Ptr<CvCascadeBoostParams> stageParams;
Ptr<CvFeatureEvaluator> featureEvaluator;
Ptr<CvFeatureEvaluator> featureEvaluator;
vector< Ptr<CvCascadeBoost> > stageClassifiers;
CvCascadeImageReader imgReader;
int numStages, curNumSamples;

View File

@@ -13,18 +13,18 @@ public:
/* 0 - BASIC = Viola
* 1 - CORE = All upright
* 2 - ALL = All features */
CvHaarFeatureParams();
CvHaarFeatureParams( int _mode );
virtual void init( const CvFeatureParams& fp );
virtual void write( FileStorage &fs ) const;
virtual bool read( const FileNode &node );
virtual void printDefaults() const;
virtual void printDefaults() const;
virtual void printAttrs() const;
virtual bool scanAttr( const String prm, const String val);
int mode;
};
@@ -47,7 +47,7 @@ protected:
Feature( int offset, bool _tilted,
int x0, int y0, int w0, int h0, float wt0,
int x1, int y1, int w1, int h1, float wt1,
int x2 = 0, int y2 = 0, int w2 = 0, int h2 = 0, float wt2 = 0.0F );
int x2 = 0, int y2 = 0, int w2 = 0, int h2 = 0, float wt2 = 0.0F );
float calc( const Mat &sum, const Mat &tilted, size_t y) const;
void write( FileStorage &fs ) const;
@@ -58,11 +58,11 @@ protected:
float weight;
} rect[CV_HAAR_FEATURE_MAX];
struct
struct
{
int p0, p1, p2, p3;
} fastRect[CV_HAAR_FEATURE_MAX];
};
};
vector<Feature> features;
Mat sum; /* sum images (each row represents image) */
@@ -73,7 +73,7 @@ protected:
inline float CvHaarEvaluator::operator()(int featureIdx, int sampleIdx) const
{
float nf = normfactor.at<float>(0, sampleIdx);
return !nf ? 0.0f : (features[featureIdx].calc( sum, tilted, sampleIdx)/nf);
return !nf ? 0.0f : (features[featureIdx].calc( sum, tilted, sampleIdx)/nf);
}
inline float CvHaarEvaluator::Feature::calc( const Mat &_sum, const Mat &_tilted, size_t y) const

View File

@@ -7,7 +7,7 @@
struct CvLBPFeatureParams : CvFeatureParams
{
CvLBPFeatureParams();
};
class CvLBPEvaluator : public CvFeatureEvaluator
@@ -27,7 +27,7 @@ protected:
{
public:
Feature();
Feature( int offset, int x, int y, int _block_w, int _block_h );
Feature( int offset, int x, int y, int _block_w, int _block_h );
uchar calc( const Mat& _sum, size_t y ) const;
void write( FileStorage &fs ) const;