1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Set stricter warning rules for gcc

This commit is contained in:
Andrey Kamaev
2012-06-07 17:21:29 +00:00
parent 0395f7c63f
commit 49a1ba6038
241 changed files with 9054 additions and 8947 deletions
+3
View File
@@ -42,6 +42,9 @@
#ifndef __CVCOMMON_H_
#define __CVCOMMON_H_
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "cxcore.h"
#include "cv.h"
#include "cxmisc.h"
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -394,7 +394,7 @@ void icvSaveStageHaarClassifier( CvIntHaarClassifier* classifier, FILE* file )
CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step )
static CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step )
{
CvStageHaarClassifier* ptr = NULL;
+129 -129
View File
@@ -108,7 +108,7 @@ CvBackgroundData* cvbgdata = NULL;
/*
* get sum image offsets for <rect> corner points
* get sum image offsets for <rect> corner points
* step - row step (measured in image pixels!) of sum image
*/
#define CV_SUM_OFFSETS( p0, p1, p2, p3, rect, step ) \
@@ -122,7 +122,7 @@ CvBackgroundData* cvbgdata = NULL;
(p3) = (rect).x + (rect).width + (step) * ((rect).y + (rect).height);
/*
* get tilted image offsets for <rect> corner points
* get tilted image offsets for <rect> corner points
* step - row step (measured in image pixels!) of tilted image
*/
#define CV_TILTED_OFFSETS( p0, p1, p2, p3, rect, step ) \
@@ -154,7 +154,7 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
{
CvIntHaarFeatures* features = NULL;
CvTHaarFeature haarFeature;
CvMemStorage* storage = NULL;
CvSeq* seq = NULL;
CvSeqWriter writer;
@@ -172,7 +172,7 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
float factor = 1.0F;
factor = ((float) winsize.width) * winsize.height / (24 * 24);
#if 0
#if 0
s0 = (int) (s0 * factor);
s1 = (int) (s1 * factor);
s2 = (int) (s2 * factor);
@@ -252,7 +252,7 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
// haar_y4
if ( (x+dx <= winsize.width ) && (y+dy*4 <= winsize.height) ) {
if (dx*4*dy < s0) continue;
@@ -277,7 +277,7 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
}
}
if (mode != 0 /*BASIC*/) {
if (mode != 0 /*BASIC*/) {
// point
if ( (x+dx*3 <= winsize.width) && (y+dy*3 <= winsize.height) ) {
if (dx*9*dy < s0) continue;
@@ -289,12 +289,12 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
}
}
}
if (mode == 2 /*ALL*/) {
if (mode == 2 /*ALL*/) {
// tilted haar_x2 (x, y, w, h, b, weight)
if ( (x+2*dx <= winsize.width) && (y+2*dx+dy <= winsize.height) && (x-dy>= 0) ) {
if (dx*2*dy < s1) continue;
if (!symmetric || (x <= (winsize.width / 2) )) {
haarFeature = cvHaarFeature( "tilted_haar_x2",
x, y, dx*2, dy, -1,
@@ -302,11 +302,11 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
// tilted haar_y2 (x, y, w, h, b, weight)
if ( (x+dx <= winsize.width) && (y+dx+2*dy <= winsize.height) && (x-2*dy>= 0) ) {
if (dx*2*dy < s1) continue;
if (!symmetric || (x <= (winsize.width / 2) )) {
haarFeature = cvHaarFeature( "tilted_haar_y2",
x, y, dx, 2*dy, -1,
@@ -314,11 +314,11 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
// tilted haar_x3 (x, y, w, h, b, weight)
if ( (x+3*dx <= winsize.width) && (y+3*dx+dy <= winsize.height) && (x-dy>= 0) ) {
if (dx*3*dy < s2) continue;
if (!symmetric || (x <= (winsize.width / 2) )) {
haarFeature = cvHaarFeature( "tilted_haar_x3",
x, y, dx*3, dy, -1,
@@ -326,11 +326,11 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
// tilted haar_y3 (x, y, w, h, b, weight)
if ( (x+dx <= winsize.width) && (y+dx+3*dy <= winsize.height) && (x-3*dy>= 0) ) {
if (dx*3*dy < s2) continue;
if (!symmetric || (x <= (winsize.width / 2) )) {
haarFeature = cvHaarFeature( "tilted_haar_y3",
x, y, dx, 3*dy, -1,
@@ -338,12 +338,12 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
// tilted haar_x4 (x, y, w, h, b, weight)
if ( (x+4*dx <= winsize.width) && (y+4*dx+dy <= winsize.height) && (x-dy>= 0) ) {
if (dx*4*dy < s3) continue;
if (!symmetric || (x <= (winsize.width / 2) )) {
haarFeature = cvHaarFeature( "tilted_haar_x4",
@@ -353,11 +353,11 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
// tilted haar_y4 (x, y, w, h, b, weight)
if ( (x+dx <= winsize.width) && (y+dx+4*dy <= winsize.height) && (x-4*dy>= 0) ) {
if (dx*4*dy < s3) continue;
if (!symmetric || (x <= (winsize.width / 2) )) {
haarFeature = cvHaarFeature( "tilted_haar_y4",
x, y, dx, 4*dy, -1,
@@ -365,10 +365,10 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
CV_WRITE_SEQ_ELEM( haarFeature, writer );
}
}
/*
// tilted point
if ( (x+dx*3 <= winsize.width - 1) && (y+dy*3 <= winsize.height - 1) && (x-3*dy>= 0)) {
if (dx*9*dy < 36) continue;
@@ -395,10 +395,10 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
features->winsize = winsize;
cvCvtSeqToArray( seq, (CvArr*) features->feature );
cvReleaseMemStorage( &storage );
icvConvertToFastHaarFeature( features->feature, features->fastfeature,
features->count, (winsize.width + 1) );
return features;
}
@@ -438,7 +438,7 @@ void icvConvertToFastHaarFeature( CvTHaarFeature* haarFeature,
fastHaarFeature[i].rect[j].p3,
haarFeature[i].rect[j].r, step )
}
}
else
{
@@ -469,15 +469,15 @@ static
CvHaarTrainigData* icvCreateHaarTrainingData( CvSize winsize, int maxnumsamples )
{
CvHaarTrainigData* data;
CV_FUNCNAME( "icvCreateHaarTrainingData" );
__BEGIN__;
data = NULL;
uchar* ptr = NULL;
size_t datasize = 0;
datasize = sizeof( CvHaarTrainigData ) +
/* sum and tilted */
( 2 * (winsize.width + 1) * (winsize.height + 1) * sizeof( sum_type ) +
@@ -548,7 +548,7 @@ void icvGetTrainingDataCallback( CvMat* mat, CvMat* sampleIdx, CvMat*,
int j = 0;
float val = 0.0F;
float normfactor = 0.0F;
CvHaarTrainingData* training_data;
CvIntHaarFeatures* haar_features;
@@ -639,7 +639,7 @@ void icvGetTrainingDataCallback( CvMat* mat, CvMat* sampleIdx, CvMat*,
#if 0 /*def CV_VERBOSE*/
if( first % 5000 == 0 )
{
fprintf( stderr, "%3d%%\r", (int) (100.0 * first /
fprintf( stderr, "%3d%%\r", (int) (100.0 * first /
haar_features->count) );
fflush( stderr );
}
@@ -692,7 +692,7 @@ void icvPrecalculate( CvHaarTrainingData* data, CvIntHaarFeatures* haarFeatures,
t_data = *data->valcache;
t_idx = *data->idxcache;
t_portion = MIN( portion, (numprecalculated - first) );
/* indices */
t_idx.rows = t_portion;
t_idx.data.ptr = data->idxcache->data.ptr + first * ((size_t)t_idx.step);
@@ -766,7 +766,7 @@ void icvSplitIndicesCallback( int compidx, float threshold,
{
if( cvEvalFastHaarFeature( fastfeature,
(sum_type*) (data->sum.data.ptr + i * data->sum.step),
(sum_type*) (data->tilted.data.ptr + i * data->tilted.step) )
(sum_type*) (data->tilted.data.ptr + i * data->tilted.step) )
< threshold * data->normfactor.data.fl[i] )
{
(*left)->data.fl[(*left)->cols++] = (float) i;
@@ -792,7 +792,7 @@ void icvSplitIndicesCallback( int compidx, float threshold,
index = (int) *((float*) (idxdata + i * idxstep));
if( cvEvalFastHaarFeature( fastfeature,
(sum_type*) (data->sum.data.ptr + index * data->sum.step),
(sum_type*) (data->tilted.data.ptr + index * data->tilted.step) )
(sum_type*) (data->tilted.data.ptr + index * data->tilted.step) )
< threshold * data->normfactor.data.fl[index] )
{
(*left)->data.fl[(*left)->cols++] = (float) index;
@@ -858,7 +858,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
float sum_stage = 0.0F;
float threshold = 0.0F;
float falsealarm = 0.0F;
//CvMat* sampleIdx = NULL;
CvMat* trimmedIdx;
//float* idxdata = NULL;
@@ -871,7 +871,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
int idx;
int numsamples;
int numtrimmed;
CvCARTHaarClassifier* classifier;
CvSeq* seq = NULL;
CvMemStorage* storage = NULL;
@@ -885,7 +885,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
printf( "| N |%%SMP|F| ST.THR | HR | FA | EXP. ERR|\n" );
printf( "+----+----+-+---------+---------+---------+---------+\n" );
#endif /* CV_VERBOSE */
n = haarFeatures->count;
m = data->sum.rows;
numsamples = (sampleIdx) ? MAX( sampleIdx->rows, sampleIdx->cols ) : m;
@@ -909,7 +909,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
trainParams.userdata = &userdata;
eval = cvMat( 1, m, CV_32FC1, cvAlloc( sizeof( float ) * m ) );
storage = cvCreateMemStorage();
seq = cvCreateSeq( 0, sizeof( *seq ), sizeof( classifier ), storage );
@@ -919,7 +919,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
num_splits = 0;
sumalpha = 0.0F;
do
{
{
#ifdef CV_VERBOSE
int v_wt = 0;
@@ -947,12 +947,12 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
num_splits += classifier->count;
cart->release( (CvClassifier**) &cart );
if( symmetric && (seq->total % 2) )
{
float normfactor = 0.0F;
CvStumpClassifier* stump;
/* flip haar features */
for( i = 0; i < classifier->count; i++ )
{
@@ -961,9 +961,9 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
for( j = 0; j < CV_HAAR_FEATURE_MAX &&
classifier->feature[i].rect[j].weight != 0.0F; j++ )
{
classifier->feature[i].rect[j].r.x = data->winsize.width -
classifier->feature[i].rect[j].r.x = data->winsize.width -
classifier->feature[i].rect[j].r.x -
classifier->feature[i].rect[j].r.width;
classifier->feature[i].rect[j].r.width;
}
}
else
@@ -975,7 +975,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
for( j = 0; j < CV_HAAR_FEATURE_MAX &&
classifier->feature[i].rect[j].weight != 0.0F; j++ )
{
classifier->feature[i].rect[j].r.x = data->winsize.width -
classifier->feature[i].rect[j].r.x = data->winsize.width -
classifier->feature[i].rect[j].r.x;
CV_SWAP( classifier->feature[i].rect[j].r.width,
classifier->feature[i].rect[j].r.height, tmp );
@@ -1010,7 +1010,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
weakTrainVals, 0, 0, 0, trimmedIdx,
&(data->weights),
trainParams.stumpTrainParams );
classifier->threshold[i] = stump->threshold;
if( classifier->left[i] <= 0 )
{
@@ -1021,8 +1021,8 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
classifier->val[-classifier->right[i]] = stump->right;
}
stump->release( (CvClassifier**) &stump );
stump->release( (CvClassifier**) &stump );
}
stumpTrainParams.getTrainData = icvGetTrainingDataCallback;
@@ -1040,7 +1040,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
cvReleaseMat( &trimmedIdx );
trimmedIdx = NULL;
}
for( i = 0; i < numsamples; i++ )
{
idx = icvGetIdxAt( sampleIdx, i );
@@ -1054,10 +1054,10 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
alpha = cvBoostNextWeakClassifier( &eval, &data->cls, weakTrainVals,
&data->weights, trainer );
sumalpha += alpha;
for( i = 0; i <= classifier->count; i++ )
{
if( boosttype == CV_RABCLASS )
if( boosttype == CV_RABCLASS )
{
classifier->val[i] = cvLogRatio( classifier->val[i] );
}
@@ -1077,7 +1077,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
for( j = 0; j < seq->total; j++ )
{
classifier = *((CvCARTHaarClassifier**) cvGetSeqElem( seq, j ));
eval.data.fl[numpos] += classifier->eval(
eval.data.fl[numpos] += classifier->eval(
(CvIntHaarClassifier*) classifier,
(sum_type*) (data->sum.data.ptr + idx * data->sum.step),
(sum_type*) (data->tilted.data.ptr + idx * data->tilted.step),
@@ -1163,7 +1163,7 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
fflush( stdout );
}
#endif /* CV_VERBOSE */
} while( falsealarm > maxfalsealarm && (!maxsplits || (num_splits < maxsplits) ) );
cvBoostEndTraining( &trainer );
@@ -1177,12 +1177,12 @@ CvIntHaarClassifier* icvCreateCARTStageClassifier( CvHaarTrainingData* data,
threshold );
cvCvtSeqToArray( seq, (CvArr*) stage->classifier );
}
/* CLEANUP */
cvReleaseMemStorage( &storage );
cvReleaseMat( &weakTrainVals );
cvFree( &(eval.data.ptr) );
return (CvIntHaarClassifier*) stage;
}
@@ -1192,7 +1192,7 @@ CvBackgroundData* icvCreateBackgroundData( const char* filename, CvSize winsize
{
CvBackgroundData* data = NULL;
const char* dir = NULL;
const char* dir = NULL;
char full[PATH_MAX];
char* imgfilename = NULL;
size_t datasize = 0;
@@ -1202,7 +1202,7 @@ CvBackgroundData* icvCreateBackgroundData( const char* filename, CvSize winsize
int len = 0;
assert( filename != NULL );
dir = strrchr( filename, '\\' );
if( dir == NULL )
{
@@ -1223,7 +1223,7 @@ CvBackgroundData* icvCreateBackgroundData( const char* filename, CvSize winsize
{
count = 0;
datasize = 0;
/* count */
while( !feof( input ) )
{
@@ -1257,11 +1257,11 @@ CvBackgroundData* icvCreateBackgroundData( const char* filename, CvSize winsize
while( !feof( input ) )
{
*imgfilename = '\0';
if( !fgets( imgfilename, PATH_MAX - (int)(imgfilename - full) - 1, input ))
if( !fgets( imgfilename, PATH_MAX - (int)(imgfilename - full) - 1, input ))
break;
len = (int)strlen( imgfilename );
if( len > 0 && imgfilename[len-1] == '\n' )
imgfilename[len-1] = 0, len--;
if( len > 0 && imgfilename[len-1] == '\n' )
imgfilename[len-1] = 0, len--;
if( len > 0 )
{
if( (*imgfilename) == '#' ) continue; /* comment */
@@ -1351,14 +1351,14 @@ void icvGetNextFromBackgroundData( CvBackgroundData* data,
{
round = data->round;
//#ifdef CV_VERBOSE
//#ifdef CV_VERBOSE
// printf( "Open background image: %s\n", data->filename[data->last] );
//#endif /* CV_VERBOSE */
data->last = rand() % data->count;
data->last %= data->count;
img = cvLoadImage( data->filename[data->last], 0 );
if( !img )
if( !img )
continue;
data->round += data->last / data->count;
data->round = data->round % (data->winsize.width * data->winsize.height);
@@ -1368,7 +1368,7 @@ void icvGetNextFromBackgroundData( CvBackgroundData* data,
offset.x = MIN( offset.x, img->width - data->winsize.width );
offset.y = MIN( offset.y, img->height - data->winsize.height );
if( img != NULL && img->depth == IPL_DEPTH_8U && img->nChannels == 1 &&
offset.x >= 0 && offset.y >= 0 )
{
@@ -1403,7 +1403,7 @@ void icvGetNextFromBackgroundData( CvBackgroundData* data,
reader->scale = MAX(
((float) data->winsize.width + reader->point.x) / ((float) reader->src.cols),
((float) data->winsize.height + reader->point.y) / ((float) reader->src.rows) );
reader->img = cvMat( (int) (reader->scale * reader->src.rows + 0.5F),
(int) (reader->scale * reader->src.cols + 0.5F),
CV_8UC1, (void*) cvAlloc( datasize ) );
@@ -1576,11 +1576,11 @@ void icvGetAuxImages( CvMat* img, CvMat* sum, CvMat* tilted,
sum_type valsum = 0;
sqsum_type valsqsum = 0;
double area = 0.0;
cvIntegral( img, sum, sqsum, tilted );
normrect = cvRect( 1, 1, img->cols - 2, img->rows - 2 );
CV_SUM_OFFSETS( p0, p1, p2, p3, normrect, img->cols + 1 )
area = normrect.width * normrect.height;
valsum = ((sum_type*) (sum->data.ptr))[p0] - ((sum_type*) (sum->data.ptr))[p1]
- ((sum_type*) (sum->data.ptr))[p2] + ((sum_type*) (sum->data.ptr))[p3];
@@ -1621,28 +1621,28 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
int i = 0;
ccounter_t getcount = 0;
ccounter_t thread_getcount = 0;
ccounter_t consumed_count;
ccounter_t consumed_count;
ccounter_t thread_consumed_count;
/* private variables */
CvMat img;
CvMat sum;
CvMat tilted;
CvMat sqsum;
sum_type* sumdata;
sum_type* tilteddata;
float* normfactor;
/* end private variables */
assert( data != NULL );
assert( first + count <= data->maxnum );
assert( cascade != NULL );
assert( callback != NULL );
// if( !cvbgdata ) return 0; this check needs to be done in the callback for BG
CCOUNTER_SET_ZERO(getcount);
CCOUNTER_SET_ZERO(thread_getcount);
CCOUNTER_SET_ZERO(consumed_count);
@@ -1691,14 +1691,14 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
normfactor = data->normfactor.data.fl + i;
sum.data.ptr = (uchar*) sumdata;
tilted.data.ptr = (uchar*) tilteddata;
icvGetAuxImages( &img, &sum, &tilted, &sqsum, normfactor );
icvGetAuxImages( &img, &sum, &tilted, &sqsum, normfactor );
if( cascade->eval( cascade, sumdata, tilteddata, *normfactor ) != 0.0F )
{
CCOUNTER_INC(thread_getcount);
break;
}
}
#ifdef CV_VERBOSE
if( (i - first) % 500 == 0 )
{
@@ -1720,7 +1720,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
CCOUNTER_ADD(consumed_count, thread_consumed_count);
}
} /* omp parallel */
if( consumed != NULL )
{
*consumed = (int)consumed_count;
@@ -1731,7 +1731,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
/* *acceptance_ratio = ((double) count) / consumed_count; */
*acceptance_ratio = CCOUNTER_DIV(count, consumed_count);
}
return static_cast<int>(getcount);
}
@@ -1791,7 +1791,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
// CV_SQSUM_MAT_TYPE,
// cvAlloc( sizeof( sqsum_type ) * (data->winsize.height + 1)
// * (data->winsize.width + 1) ) );
//
//
// #ifdef CV_OPENMP
// #pragma omp for schedule(static, 1)
// #endif /* CV_OPENMP */
@@ -1800,7 +1800,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
// for( ; ; )
// {
// icvGetBackgroundImage( cvbgdata, cvbgreader, &img );
//
//
// CCOUNTER_INC(thread_consumed_count);
//
// sumdata = (sum_type*) (data->sum.data.ptr + i * data->sum.step);
@@ -1808,7 +1808,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
// normfactor = data->normfactor.data.fl + i;
// sum.data.ptr = (uchar*) sumdata;
// tilted.data.ptr = (uchar*) tilteddata;
// icvGetAuxImages( &img, &sum, &tilted, &sqsum, normfactor );
// icvGetAuxImages( &img, &sum, &tilted, &sqsum, normfactor );
// if( cascade->eval( cascade, sumdata, tilteddata, *normfactor ) != 0.0F )
// {
// break;
@@ -1822,7 +1822,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
// fflush( stderr );
// }
//#endif /* CV_VERBOSE */
//
//
// }
//
// cvFree( &(img.data.ptr) );
@@ -1842,7 +1842,7 @@ int icvGetHaarTrainingData( CvHaarTrainingData* data, int first, int count,
// /* *acceptance_ratio = ((double) count) / consumed_count; */
// *acceptance_ratio = CCOUNTER_DIV(count, consumed_count);
// }
//
//
// return count;
//}
@@ -1853,24 +1853,24 @@ int icvGetHaarTraininDataFromVecCallback( CvMat* img, void* userdata )
int c = 0;
assert( img->rows * img->cols == ((CvVecFile*) userdata)->vecsize );
size_t elements_read = fread( &tmp, sizeof( tmp ), 1, ((CvVecFile*) userdata)->input );
CV_Assert(elements_read == 1);
elements_read = fread( ((CvVecFile*) userdata)->vector, sizeof( short ),
((CvVecFile*) userdata)->vecsize, ((CvVecFile*) userdata)->input );
CV_Assert(elements_read == (size_t)((CvVecFile*) userdata)->vecsize);
if( feof( ((CvVecFile*) userdata)->input ) ||
if( feof( ((CvVecFile*) userdata)->input ) ||
(((CvVecFile*) userdata)->last)++ >= ((CvVecFile*) userdata)->count )
{
return 0;
}
for( r = 0; r < img->rows; r++ )
{
for( c = 0; c < img->cols; c++ )
{
CV_MAT_ELEM( *img, uchar, r, c ) =
CV_MAT_ELEM( *img, uchar, r, c ) =
(uchar) ( ((CvVecFile*) userdata)->vector[r * img->cols + c] );
}
}
@@ -1878,14 +1878,14 @@ int icvGetHaarTraininDataFromVecCallback( CvMat* img, void* userdata )
return 1;
}
int icvGetHaarTrainingDataFromBGCallback ( CvMat* img, void* /*userdata*/ )
static int icvGetHaarTrainingDataFromBGCallback ( CvMat* img, void* /*userdata*/ )
{
if (! cvbgdata)
return 0;
if (! cvbgreader)
return 0;
// just in case icvGetBackgroundImage is not thread-safe ...
#ifdef CV_OPENMP
#pragma omp critical (get_background_image_callback)
@@ -1893,7 +1893,7 @@ int icvGetHaarTrainingDataFromBGCallback ( CvMat* img, void* /*userdata*/ )
{
icvGetBackgroundImage( cvbgdata, cvbgreader, img );
}
return 1;
}
@@ -1902,7 +1902,7 @@ int icvGetHaarTrainingDataFromBGCallback ( CvMat* img, void* /*userdata*/ )
* Get training data from .vec file
*/
static
int icvGetHaarTrainingDataFromVec( CvHaarTrainingData* data, int first, int count,
int icvGetHaarTrainingDataFromVec( CvHaarTrainingData* data, int first, int count,
CvIntHaarClassifier* cascade,
const char* filename,
int* consumed )
@@ -1914,8 +1914,8 @@ int icvGetHaarTrainingDataFromVec( CvHaarTrainingData* data, int first, int coun
__BEGIN__;
CvVecFile file;
short tmp = 0;
short tmp = 0;
file.input = NULL;
if( filename ) file.input = fopen( filename, "rb" );
@@ -1967,8 +1967,8 @@ int icvGetHaarTrainingDataFromBG( CvHaarTrainingData* data, int first, int count
if (filename)
{
CvVecFile file;
short tmp = 0;
short tmp = 0;
file.input = NULL;
if( filename ) file.input = fopen( filename, "rb" );
@@ -2009,7 +2009,7 @@ int icvGetHaarTrainingDataFromBG( CvHaarTrainingData* data, int first, int count
void cvCreateCascadeClassifier( const char* dirname,
const char* vecfilename,
const char* bgfilename,
const char* bgfilename,
int npos, int nneg, int nstages,
int numprecalculated,
int numsplits,
@@ -2048,7 +2048,7 @@ void cvCreateCascadeClassifier( const char* dirname,
cascade = (CvCascadeHaarClassifier*) icvCreateCascadeHaarClassifier( nstages );
cascade->count = 0;
if( icvInitBackgroundReaders( bgfilename, winsize ) )
{
data = icvCreateHaarTrainingData( winsize, npos + nneg );
@@ -2061,7 +2061,7 @@ void cvCreateCascadeClassifier( const char* dirname,
for( i = 0; i < nstages; i++, cascade->count++ )
{
sprintf( stagename, "%s%d/%s", dirname, i, CV_STAGE_CART_FILE_NAME );
cascade->classifier[i] =
cascade->classifier[i] =
icvLoadCARTStageHaarClassifier( stagename, winsize.width + 1 );
if( !icvMkDir( stagename ) )
@@ -2129,7 +2129,7 @@ void cvCreateCascadeClassifier( const char* dirname,
data->sum.rows = data->tilted.rows = poscount + negcount;
data->normfactor.cols = data->weights.cols = data->cls.cols =
poscount + negcount;
posweight = (equalweights) ? 1.0F / (poscount + negcount) : (0.5F / poscount);
negweight = (equalweights) ? 1.0F / (poscount + negcount) : (0.5F / negcount);
for( j = 0; j < poscount; j++ )
@@ -2169,7 +2169,7 @@ void cvCreateCascadeClassifier( const char* dirname,
file = fopen( stagename, "w" );
if( file != NULL )
{
cascade->classifier[i]->save(
cascade->classifier[i]->save(
(CvIntHaarClassifier*) cascade->classifier[i], file );
fclose( file );
}
@@ -2207,7 +2207,7 @@ void cvCreateCascadeClassifier( const char* dirname,
printf( "FAILED TO INITIALIZE BACKGROUND READERS\n" );
#endif /* CV_VERBOSE */
}
/* CLEAN UP */
icvDestroyBackgroundReaders();
cascade->release( (CvIntHaarClassifier**) &cascade );
@@ -2215,7 +2215,7 @@ void cvCreateCascadeClassifier( const char* dirname,
/* tree cascade classifier */
int icvNumSplits( CvStageHaarClassifier* stage )
static int icvNumSplits( CvStageHaarClassifier* stage )
{
int i;
int num;
@@ -2229,7 +2229,7 @@ int icvNumSplits( CvStageHaarClassifier* stage )
return num;
}
void icvSetNumSamples( CvHaarTrainingData* training_data, int num )
static void icvSetNumSamples( CvHaarTrainingData* training_data, int num )
{
assert( num <= training_data->maxnum );
@@ -2238,7 +2238,7 @@ void icvSetNumSamples( CvHaarTrainingData* training_data, int num )
training_data->cls.cols = training_data->weights.cols = num;
}
void icvSetWeightsAndClasses( CvHaarTrainingData* training_data,
static void icvSetWeightsAndClasses( CvHaarTrainingData* training_data,
int num1, float weight1, float cls1,
int num2, float weight2, float cls2 )
{
@@ -2258,7 +2258,7 @@ void icvSetWeightsAndClasses( CvHaarTrainingData* training_data,
}
}
CvMat* icvGetUsedValues( CvHaarTrainingData* training_data,
static CvMat* icvGetUsedValues( CvHaarTrainingData* training_data,
int start, int num,
CvIntHaarFeatures* haar_features,
CvStageHaarClassifier* stage )
@@ -2302,7 +2302,7 @@ CvMat* icvGetUsedValues( CvHaarTrainingData* training_data,
}
total = last + 1;
CV_CALL( ptr = cvCreateMat( num, total, CV_32FC1 ) );
#ifdef CV_OPENMP
#pragma omp parallel for
@@ -2351,7 +2351,7 @@ typedef struct CvSplit
void cvCreateTreeCascadeClassifier( const char* dirname,
const char* vecfilename,
const char* bgfilename,
const char* bgfilename,
int npos, int nneg, int nstages,
int numprecalculated,
int numsplits,
@@ -2425,11 +2425,11 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
sprintf( stage_name, "%s/", dirname );
suffix = stage_name + strlen( stage_name );
if (! bg_vecfile)
if( !icvInitBackgroundReaders( bgfilename, winsize ) && nstages > 0 )
CV_ERROR( CV_StsError, "Unable to read negative images" );
if( nstages > 0 )
{
/* width-first search in the tree */
@@ -2438,7 +2438,7 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
CvSplit* first_split;
CvSplit* last_split;
CvSplit* cur_split;
CvTreeCascadeNode* parent;
CvTreeCascadeNode* cur_node;
CvTreeCascadeNode* last_node;
@@ -2447,7 +2447,7 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
parent = leaves;
leaves = NULL;
do
{
{
int best_clusters; /* best selected number of clusters */
float posweight, negweight;
double leaf_fa_rate;
@@ -2536,7 +2536,7 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
multiple_clusters = NULL;
printf( "Number of used features: %d\n", single_num );
if( maxtreesplits >= 0 )
{
max_clusters = MIN( max_clusters, maxtreesplits - total_splits + 1 );
@@ -2594,7 +2594,7 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
printf( "Clusters are too small. Clustering aborted.\n" );
break;
}
cur_num = 0;
cur_node = last_node = NULL;
for( cluster = 0; (cluster < k) && (cur_num < best_num); cluster++ )
@@ -2676,7 +2676,7 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
CV_CALL( cur_split = (CvSplit*) cvAlloc( sizeof( *cur_split ) ) );
CV_ZERO_OBJ( cur_split );
if( last_split ) last_split->next = cur_split;
else first_split = cur_split;
last_split = cur_split;
@@ -2734,7 +2734,7 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
? last_split->multiple_clusters : last_split->single_cluster;
parent = last_split->parent;
if( parent ) parent->child = cur_node;
/* connect leaves via next_same_level and save them */
for( ; cur_node; cur_node = cur_node->next )
{
@@ -2768,14 +2768,14 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
printf( "\nParent node: %s\n", buf );
printf( "Chosen number of splits: %d\n\n", (last_split->multiple_clusters)
? (last_split->num_clusters - 1) : 0 );
cur_split = last_split;
last_split = last_split->next;
cvFree( &cur_split );
} /* for each split point */
printf( "Total number of splits: %d\n", total_splits );
if( !(tcc->root) ) tcc->root = leaves;
CV_CALL( icvPrintTreeCascade( tcc->root ) );
@@ -2903,7 +2903,7 @@ void cvCreateTrainingSamples( const char* filename,
inverse = (rand() > (RAND_MAX/2));
}
icvPlaceDistortedSample( &sample, inverse, maxintensitydev,
maxxangle, maxyangle, maxzangle,
maxxangle, maxyangle, maxzangle,
0 /* nonzero means placing image without cut offs */,
0.0 /* nozero adds random shifting */,
0.0 /* nozero adds random scaling */,
@@ -2931,13 +2931,13 @@ void cvCreateTrainingSamples( const char* filename,
cvFree( &(sample.data.ptr) );
fclose( output );
} /* if( output != NULL ) */
icvEndSampleDistortion( &data );
}
#ifdef CV_VERBOSE
printf( "\r \r" );
#endif /* CV_VERBOSE */
#endif /* CV_VERBOSE */
}
@@ -2986,7 +2986,7 @@ void cvCreateTestSamples( const char* infoname,
{
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
}
info = fopen( infoname, "w" );
strcpy( fullname, infoname );
filename = strrchr( fullname, '\\' );
@@ -3008,7 +3008,7 @@ void cvCreateTestSamples( const char* infoname,
for( i = 0; i < count; i++ )
{
icvGetNextFromBackgroundData( cvbgdata, cvbgreader );
maxscale = MIN( 0.7F * cvbgreader->src.cols / winwidth,
0.7F * cvbgreader->src.rows / winheight );
if( maxscale < 1.0F ) continue;
@@ -3025,14 +3025,14 @@ void cvCreateTestSamples( const char* infoname,
inverse = (rand() > (RAND_MAX/2));
}
icvPlaceDistortedSample( &win, inverse, maxintensitydev,
maxxangle, maxyangle, maxzangle,
maxxangle, maxyangle, maxzangle,
1, 0.0, 0.0, &data );
sprintf( filename, "%04d_%04d_%04d_%04d_%04d.jpg",
(i + 1), x, y, width, height );
if( info )
if( info )
{
fprintf( info, "%s %d %d %d %d %d\n",
filename, 1, x, y, width, height );
+2 -2
View File
@@ -83,7 +83,7 @@
* cij - coeffs[i][j], coeffs[2][2] = 1
* (ui, vi) - rectangle vertices
*/
void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
static void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
double coeffs[3][3] )
{
//CV_FUNCNAME( "cvWarpPerspective" );
@@ -130,7 +130,7 @@ void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
}
/* Warps source into destination by a perspective transform */
void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
static void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
{
CV_FUNCNAME( "cvWarpPerspective" );
+3
View File
@@ -44,6 +44,9 @@
*
* Measure performance of classifier
*/
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "cv.h"
#include "highgui.h"
+9 -6
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "HOGfeatures.h"
#include "cascadeclassifier.h"
@@ -54,7 +57,7 @@ void CvHOGEvaluator::writeFeatures( FileStorage &fs, const Mat& featureMap ) con
features[featIdx].write( fs, componentIdx );
fs << "}";
}
fs << "]";
fs << "]";
}
void CvHOGEvaluator::generateFeatures()
@@ -85,11 +88,11 @@ void CvHOGEvaluator::generateFeatures()
}
}
w = 4*t;
h = 2*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));
}
}
@@ -136,7 +139,7 @@ void CvHOGEvaluator::Feature::write(FileStorage &fs) const
// int cellIdx = featComponent / N_BINS;
// int binIdx = featComponent % N_BINS;
//
// fs << CC_RECTS << "[:" << rect[cellIdx].x << rect[cellIdx].y <<
// fs << CC_RECTS << "[:" << rect[cellIdx].x << rect[cellIdx].y <<
// rect[cellIdx].width << rect[cellIdx].height << binIdx << "]";
//}
@@ -144,7 +147,7 @@ void CvHOGEvaluator::Feature::write(FileStorage &fs) const
//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 <<
fs << CC_RECT << "[:" << rect[0].x << rect[0].y <<
rect[0].width << rect[0].height << featComponentIdx << "]";
}
@@ -228,7 +231,7 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, M
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++ )
+61 -58
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "boost.h"
#include "cascadeclassifier.h"
#include <queue>
@@ -139,7 +142,7 @@ static CvMat* cvPreprocessIndexArray( const CvMat* idx_arr, int data_arr_size, b
//----------------------------- CascadeBoostParams -------------------------------------------------
CvCascadeBoostParams::CvCascadeBoostParams() : minHitRate( 0.995F), maxFalseAlarm( 0.5F )
{
{
boost_type = CvBoost::GENTLE;
use_surrogates = use_1se_rule = truncate_pruned_tree = false;
}
@@ -157,7 +160,7 @@ CvCascadeBoostParams::CvCascadeBoostParams( int _boostType,
void CvCascadeBoostParams::write( FileStorage &fs ) const
{
String boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST :
String boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST :
boost_type == CvBoost::REAL ? CC_REAL_BOOST :
boost_type == CvBoost::LOGIT ? CC_LOGIT_BOOST :
boost_type == CvBoost::GENTLE ? CC_GENTLE_BOOST : String();
@@ -197,7 +200,7 @@ bool CvCascadeBoostParams::read( const FileNode &node )
void CvCascadeBoostParams::printDefaults() const
{
cout << "--boostParams--" << endl;
cout << " [-bt <{" << CC_DISCRETE_BOOST << ", "
cout << " [-bt <{" << CC_DISCRETE_BOOST << ", "
<< CC_REAL_BOOST << ", "
<< CC_LOGIT_BOOST ", "
<< CC_GENTLE_BOOST << "(default)}>]" << endl;
@@ -210,7 +213,7 @@ void CvCascadeBoostParams::printDefaults() const
void CvCascadeBoostParams::printAttrs() const
{
String boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST :
String boostTypeStr = boost_type == CvBoost::DISCRETE ? CC_DISCRETE_BOOST :
boost_type == CvBoost::REAL ? CC_REAL_BOOST :
boost_type == CvBoost::LOGIT ? CC_LOGIT_BOOST :
boost_type == CvBoost::GENTLE ? CC_GENTLE_BOOST : String();
@@ -259,7 +262,7 @@ bool CvCascadeBoostParams::scanAttr( const String prmName, const String val)
else
res = false;
return res;
return res;
}
CvDTreeNode* CvCascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx )
@@ -440,7 +443,7 @@ CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _fea
set_params( _params );
max_c_count = MAX( 2, featureEvaluator->getMaxCatCount() );
var_type = cvCreateMat( 1, var_count + 2, CV_32SC1 );
if ( featureEvaluator->getMaxCatCount() > 0 )
if ( featureEvaluator->getMaxCatCount() > 0 )
{
numPrecalcIdx = 0;
cat_var_count = var_count;
@@ -448,7 +451,7 @@ CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _fea
for( int vi = 0; vi < var_count; vi++ )
{
var_type->data.i[vi] = vi;
}
}
}
else
{
@@ -457,8 +460,8 @@ CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _fea
for( int vi = 1; vi <= var_count; vi++ )
{
var_type->data.i[vi-1] = -vi;
}
}
}
}
var_type->data.i[var_count] = cat_var_count;
var_type->data.i[var_count+1] = cat_var_count+1;
@@ -467,7 +470,7 @@ CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _fea
treeBlockSize = MAX(treeBlockSize + BlockSizeDelta, MinBlockSize);
tree_storage = cvCreateMemStorage( treeBlockSize );
node_heap = cvCreateSet( 0, sizeof(node_heap[0]), sizeof(CvDTreeNode), tree_storage );
split_heap = cvCreateSet( 0, sizeof(split_heap[0]), maxSplitSize, tree_storage );
split_heap = cvCreateSet( 0, sizeof(split_heap[0]), maxSplitSize, tree_storage );
}
CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _featureEvaluator,
@@ -477,15 +480,15 @@ CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _fea
{
setData( _featureEvaluator, _numSamples, _precalcValBufSize, _precalcIdxBufSize, _params );
}
void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluator,
int _numSamples,
int _precalcValBufSize, int _precalcIdxBufSize,
const CvDTreeParams& _params )
{
const CvDTreeParams& _params )
{
int* idst = 0;
unsigned short* udst = 0;
clear();
shared = true;
have_labels = true;
@@ -503,16 +506,16 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
_resp = featureEvaluator->getCls();
responses = &_resp;
// TODO: check responses: elements must be 0 or 1
if( _precalcValBufSize < 0 || _precalcIdxBufSize < 0)
if( _precalcValBufSize < 0 || _precalcIdxBufSize < 0)
CV_Error( CV_StsOutOfRange, "_numPrecalcVal and _numPrecalcIdx must be positive or 0" );
var_count = var_all = featureEvaluator->getNumFeatures() * featureEvaluator->getFeatureSize();
var_count = var_all = featureEvaluator->getNumFeatures() * featureEvaluator->getFeatureSize();
sample_count = _numSamples;
is_buf_16u = false;
if (sample_count < 65536)
is_buf_16u = true;
is_buf_16u = false;
if (sample_count < 65536)
is_buf_16u = true;
numPrecalcVal = min( cvRound((double)_precalcValBufSize*1048576. / (sizeof(float)*sample_count)), var_count );
numPrecalcIdx = min( cvRound((double)_precalcIdxBufSize*1048576. /
@@ -522,8 +525,8 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
valCache.create( numPrecalcVal, sample_count, CV_32FC1 );
var_type = cvCreateMat( 1, var_count + 2, CV_32SC1 );
if ( featureEvaluator->getMaxCatCount() > 0 )
if ( featureEvaluator->getMaxCatCount() > 0 )
{
numPrecalcIdx = 0;
cat_var_count = var_count;
@@ -531,7 +534,7 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
for( int vi = 0; vi < var_count; vi++ )
{
var_type->data.i[vi] = vi;
}
}
}
else
{
@@ -540,14 +543,14 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
for( int vi = 1; vi <= var_count; vi++ )
{
var_type->data.i[vi-1] = -vi;
}
}
}
var_type->data.i[var_count] = cat_var_count;
var_type->data.i[var_count+1] = cat_var_count+1;
work_var_count = ( cat_var_count ? 0 : numPrecalcIdx ) + 1/*cv_lables*/;
buf_size = (work_var_count + 1) * sample_count/*sample_indices*/;
buf_count = 2;
if ( is_buf_16u )
buf = cvCreateMat( buf_count, buf_size, CV_16UC1 );
else
@@ -556,7 +559,7 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
cat_count = cvCreateMat( 1, cat_var_count + 1, CV_32SC1 );
// precalculate valCache and set indices in buf
precalculate();
precalculate();
// now calculate the maximum size of split,
// create memory storage that will keep nodes and splits of the decision tree
@@ -574,7 +577,7 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
tempBlockSize = MAX( tempBlockSize + BlockSizeDelta, MinBlockSize );
temp_storage = cvCreateMemStorage( tempBlockSize );
nv_heap = cvCreateSet( 0, sizeof(*nv_heap), nvSize, temp_storage );
data_root = new_node( 0, sample_count, 0, 0 );
// set sample labels
@@ -617,7 +620,7 @@ void CvCascadeBoostTrainData::free_train_data()
const int* CvCascadeBoostTrainData::get_class_labels( CvDTreeNode* n, int* labelsBuf)
{
int nodeSampleCount = n->sample_count;
int nodeSampleCount = n->sample_count;
int rStep = CV_IS_MAT_CONT( responses->type ) ? 1 : responses->step / CV_ELEM_SIZE( responses->type );
int* sampleIndicesBuf = labelsBuf; //
@@ -626,7 +629,7 @@ const int* CvCascadeBoostTrainData::get_class_labels( CvDTreeNode* n, int* label
{
int sidx = sampleIndices[si];
labelsBuf[si] = (int)responses->data.fl[sidx*rStep];
}
}
return labelsBuf;
}
@@ -643,9 +646,9 @@ const int* CvCascadeBoostTrainData::get_cv_labels( CvDTreeNode* n, int* labels_b
void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ordValuesBuf, int* sortedIndicesBuf,
const float** ordValues, const int** sortedIndices, int* sampleIndicesBuf )
{
int nodeSampleCount = n->sample_count;
int nodeSampleCount = n->sample_count;
const int* sampleIndices = get_sample_indices(n, sampleIndicesBuf);
if ( vi < numPrecalcIdx )
{
if( !is_buf_16u )
@@ -659,7 +662,7 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o
*sortedIndices = sortedIndicesBuf;
}
if( vi < numPrecalcVal )
{
for( int i = 0; i < nodeSampleCount; i++ )
@@ -705,10 +708,10 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o
ordValuesBuf[i] = (&sampleValues[0])[sortedIndicesBuf[i]];
*sortedIndices = sortedIndicesBuf;
}
*ordValues = ordValuesBuf;
}
const int* CvCascadeBoostTrainData::get_cat_var_data( CvDTreeNode* n, int vi, int* catValuesBuf )
{
int nodeSampleCount = n->sample_count;
@@ -739,8 +742,8 @@ const int* CvCascadeBoostTrainData::get_cat_var_data( CvDTreeNode* n, int vi, in
float CvCascadeBoostTrainData::getVarValue( int vi, int si )
{
if ( vi < numPrecalcVal && !valCache.empty() )
return valCache.at<float>( vi, si );
return (*featureEvaluator)( vi, si );
return valCache.at<float>( vi, si );
return (*featureEvaluator)( vi, si );
}
@@ -858,7 +861,7 @@ CvDTreeNode* CvCascadeBoostTree::predict( int sampleIdx ) const
CvDTreeNode* node = root;
if( !node )
CV_Error( CV_StsError, "The tree has not been trained yet" );
if ( ((CvCascadeBoostTrainData*)data)->featureEvaluator->getMaxCatCount() == 0 ) // ordered
{
while( node->left )
@@ -946,7 +949,7 @@ void CvCascadeBoostTree::read( const FileNode &node, CvBoost* _ensemble,
int maxCatCount = ((CvCascadeBoostTrainData*)_data)->featureEvaluator->getMaxCatCount();
int subsetN = (maxCatCount + 31)/32;
int step = 3 + ( maxCatCount>0 ? subsetN : 1 );
queue<CvDTreeNode*> internalNodesQueue;
FileNodeIterator internalNodesIt, leafValsuesIt;
CvDTreeNode* prntNode, *cldNode;
@@ -986,11 +989,11 @@ void CvCascadeBoostTree::read( const FileNode &node, CvBoost* _ensemble,
{
prntNode->right = cldNode = data->new_node( 0, 0, 0, 0 );
*leafValsuesIt >> cldNode->value; leafValsuesIt--;
cldNode->parent = prntNode;
cldNode->parent = prntNode;
}
else
{
prntNode->right = internalNodesQueue.front();
prntNode->right = internalNodesQueue.front();
prntNode->right->parent = prntNode;
internalNodesQueue.pop();
}
@@ -999,7 +1002,7 @@ void CvCascadeBoostTree::read( const FileNode &node, CvBoost* _ensemble,
{
prntNode->left = cldNode = data->new_node( 0, 0, 0, 0 );
*leafValsuesIt >> cldNode->value; leafValsuesIt--;
cldNode->parent = prntNode;
cldNode->parent = prntNode;
}
else
{
@@ -1089,7 +1092,7 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
}
}
CV_Assert( n1 == n );
}
}
else
{
int *ldst, *rdst;
@@ -1116,7 +1119,7 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
}
}
CV_Assert( n1 == n );
}
}
}
// split cv_labels using newIdx relocation table
@@ -1171,7 +1174,7 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
}
}
}
// split sample indices
int *sampleIdx_src_buf = tempBuf + n;
const int* sampleIdx_src = data->get_sample_indices(node, sampleIdx_src_buf);
@@ -1181,9 +1184,9 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
if (data->is_buf_16u)
{
unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
workVarCount*scount + left->offset);
unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
workVarCount*scount + right->offset);
for (int i = 0; i < n; i++)
{
@@ -1202,9 +1205,9 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
}
else
{
int* ldst = buf->data.i + left->buf_idx*buf->cols +
int* ldst = buf->data.i + left->buf_idx*buf->cols +
workVarCount*scount + left->offset;
int* rdst = buf->data.i + right->buf_idx*buf->cols +
int* rdst = buf->data.i + right->buf_idx*buf->cols +
workVarCount*scount + right->offset;
for (int i = 0; i < n; i++)
{
@@ -1229,10 +1232,10 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
}
// deallocate the parent node data that is not needed anymore
data->free_node_data(node);
data->free_node_data(node);
}
void auxMarkFeaturesInMap( const CvDTreeNode* node, Mat& featureMap)
static void auxMarkFeaturesInMap( const CvDTreeNode* node, Mat& featureMap)
{
if ( node && node->split )
{
@@ -1265,7 +1268,7 @@ bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator,
set_params( _params );
if ( (_params.boost_type == LOGIT) || (_params.boost_type == GENTLE) )
data->do_responses_copy();
update_weights( 0 );
cout << "+----+---------+---------+" << endl;
@@ -1316,7 +1319,7 @@ bool CvCascadeBoost::set_params( const CvBoostParams& _params )
minHitRate = ((CvCascadeBoostParams&)_params).minHitRate;
maxFalseAlarm = ((CvCascadeBoostParams&)_params).maxFalseAlarm;
return ( ( minHitRate > 0 ) && ( minHitRate < 1) &&
( maxFalseAlarm > 0 ) && ( maxFalseAlarm < 1) &&
( maxFalseAlarm > 0 ) && ( maxFalseAlarm < 1) &&
CvBoost::set_params( _params ));
}
@@ -1364,7 +1367,7 @@ void CvCascadeBoost::update_weights( CvBoostTree* tree )
if (data->is_buf_16u)
{
unsigned short* labels = (unsigned short*)(buf->data.s + data->data_root->buf_idx*buf->cols +
unsigned short* labels = (unsigned short*)(buf->data.s + data->data_root->buf_idx*buf->cols +
data->data_root->offset + (data->work_var_count-1)*data->sample_count);
for( int i = 0; i < n; i++ )
{
@@ -1382,7 +1385,7 @@ void CvCascadeBoost::update_weights( CvBoostTree* tree )
}
else
{
int* labels = buf->data.i + data->data_root->buf_idx*buf->cols +
int* labels = buf->data.i + data->data_root->buf_idx*buf->cols +
data->data_root->offset + (data->work_var_count-1)*data->sample_count;
for( int i = 0; i < n; i++ )
@@ -1425,7 +1428,7 @@ void CvCascadeBoost::update_weights( CvBoostTree* tree )
{
// invert the subsample mask
cvXorS( subsample_mask, cvScalar(1.), subsample_mask );
// run tree through all the non-processed samples
for( int i = 0; i < n; i++ )
if( subsample_mask->data.ptr[i] )
@@ -1565,7 +1568,7 @@ bool CvCascadeBoost::isErrDesired()
int sCount = data->sample_count,
numPos = 0, numNeg = 0, numFalse = 0, numPosTrue = 0;
vector<float> eval(sCount);
for( int i = 0; i < sCount; i++ )
if( ((CvCascadeBoostTrainData*)data)->featureEvaluator->getCls( i ) == 1.0F )
eval[numPos++] = predict( i, true );
@@ -1625,7 +1628,7 @@ bool CvCascadeBoost::read( const FileNode &node,
set_params( _params );
node[CC_STAGE_THRESHOLD] >> threshold;
FileNode rnode = node[CC_WEAK_CLASSIFIERS];
FileNode rnode = node[CC_WEAK_CLASSIFIERS];
storage = cvCreateMemStorage();
weak = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvBoostTree*), storage );
+31 -28
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "cascadeclassifier.h"
#include <queue>
@@ -6,14 +9,14 @@ using namespace std;
static const char* stageTypes[] = { CC_BOOST };
static const char* featureTypes[] = { CC_HAAR, CC_LBP, CC_HOG };
CvCascadeParams::CvCascadeParams() : stageType( defaultStageType ),
CvCascadeParams::CvCascadeParams() : stageType( defaultStageType ),
featureType( defaultFeatureType ), winSize( cvSize(24, 24) )
{
name = CC_CASCADE_PARAMS;
{
name = CC_CASCADE_PARAMS;
}
CvCascadeParams::CvCascadeParams( int _stageType, int _featureType ) : stageType( _stageType ),
featureType( _featureType ), winSize( cvSize(24, 24) )
{
{
name = CC_CASCADE_PARAMS;
}
@@ -25,7 +28,7 @@ void CvCascadeParams::write( FileStorage &fs ) const
CV_Assert( !stageTypeStr.empty() );
fs << CC_STAGE_TYPE << stageTypeStr;
String featureTypeStr = featureType == CvFeatureParams::HAAR ? CC_HAAR :
featureType == CvFeatureParams::LBP ? CC_LBP :
featureType == CvFeatureParams::LBP ? CC_LBP :
featureType == CvFeatureParams::HOG ? CC_HOG :
0;
CV_Assert( !stageTypeStr.empty() );
@@ -51,7 +54,7 @@ bool CvCascadeParams::read( const FileNode &node )
return false;
rnode >> featureTypeStr;
featureType = !featureTypeStr.compare( CC_HAAR ) ? CvFeatureParams::HAAR :
!featureTypeStr.compare( CC_LBP ) ? CvFeatureParams::LBP :
!featureTypeStr.compare( CC_LBP ) ? CvFeatureParams::LBP :
!featureTypeStr.compare( CC_HOG ) ? CvFeatureParams::HOG :
-1;
if (featureType == -1)
@@ -125,15 +128,15 @@ bool CvCascadeParams::scanAttr( const String prmName, const String val )
bool CvCascadeClassifier::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,
const CvFeatureParams& _featureParams,
const CvCascadeBoostParams& _stageParams,
bool baseFormatSave )
{
{
if( _cascadeDirName.empty() || _posFilename.empty() || _negFilename.empty() )
CV_Error( CV_StsBadArg, "_cascadeDirName or _bgfileName or _vecFileName is NULL" );
@@ -181,17 +184,17 @@ bool CvCascadeClassifier::train( const String _cascadeDirName,
cout << endl << "Stages 0-" << startNumStages-1 << " are loaded" << endl;
else if ( startNumStages == 1)
cout << endl << "Stage 0 is loaded" << endl;
double requiredLeafFARate = pow( (double) stageParams->maxFalseAlarm, (double) numStages ) /
(double)stageParams->max_depth;
double tempLeafFARate;
for( int i = startNumStages; i < numStages; i++ )
{
cout << endl << "===== TRAINING " << i << "-stage =====" << endl;
cout << "<BEGIN" << endl;
if ( !updateTrainingSet( tempLeafFARate ) )
if ( !updateTrainingSet( tempLeafFARate ) )
{
cout << "Train dataset for temp stage can not be filled. "
"Branch training terminated." << endl;
@@ -211,10 +214,10 @@ bool CvCascadeClassifier::train( const String _cascadeDirName,
stageClassifiers.push_back( tempStage );
cout << "END>" << endl;
// save params
String filename;
if ( i == 0)
if ( i == 0)
{
filename = dirName + CC_PARAMS_FILENAME;
FileStorage fs( filename, FileStorage::WRITE);
@@ -289,7 +292,7 @@ int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositiv
{
bool isGetImg = isPositive ? imgReader.getPos( img ) :
imgReader.getNeg( img );
if( !isGetImg )
if( !isGetImg )
return getcount;
consumed++;
@@ -313,14 +316,14 @@ void CvCascadeClassifier::writeParams( FileStorage &fs ) const
void CvCascadeClassifier::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
{
((CvFeatureEvaluator*)((Ptr<CvFeatureEvaluator>)featureEvaluator))->writeFeatures( fs, featureMap );
((CvFeatureEvaluator*)((Ptr<CvFeatureEvaluator>)featureEvaluator))->writeFeatures( fs, featureMap );
}
void CvCascadeClassifier::writeStages( FileStorage &fs, const Mat& featureMap ) const
{
char cmnt[30];
int i = 0;
fs << CC_STAGES << "[";
fs << CC_STAGES << "[";
for( vector< Ptr<CvCascadeBoost> >::const_iterator it = stageClassifiers.begin();
it != stageClassifiers.end(); it++, i++ )
{
@@ -337,17 +340,17 @@ bool CvCascadeClassifier::readParams( const FileNode &node )
{
if ( !node.isMap() || !cascadeParams.read( node ) )
return false;
stageParams = new CvCascadeBoostParams;
FileNode rnode = node[CC_STAGE_PARAMS];
if ( !stageParams->read( rnode ) )
return false;
featureParams = CvFeatureParams::create(cascadeParams.featureType);
rnode = node[CC_FEATURE_PARAMS];
if ( !featureParams->read( rnode ) )
return false;
return true;
return true;
}
bool CvCascadeClassifier::readStages( const FileNode &node)
@@ -396,7 +399,7 @@ void CvCascadeClassifier::save( const String filename, bool baseFormat )
fs << FileStorage::getDefaultObjectName(filename) << "{";
if ( !baseFormat )
{
Mat featureMap;
Mat featureMap;
getUsedFeaturesIdxMap( featureMap );
writeParams( fs );
fs << CC_STAGE_NUM << (int)stageClassifiers.size();
@@ -409,7 +412,7 @@ void CvCascadeClassifier::save( const String filename, bool baseFormat )
CvSeq* weak;
if ( cascadeParams.featureType != CvFeatureParams::HAAR )
CV_Error( CV_StsBadFunc, "old file format is used for Haar-like features only");
fs << ICV_HAAR_SIZE_NAME << "[:" << cascadeParams.winSize.width <<
fs << ICV_HAAR_SIZE_NAME << "[:" << cascadeParams.winSize.width <<
cascadeParams.winSize.height << "]";
fs << ICV_HAAR_STAGES_NAME << "[";
for( size_t si = 0; si < stageClassifiers.size(); si++ )
@@ -424,16 +427,16 @@ void CvCascadeClassifier::save( const String filename, bool baseFormat )
int inner_node_idx = -1, total_inner_node_idx = -1;
queue<const CvDTreeNode*> inner_nodes_queue;
CvCascadeBoostTree* tree = *((CvCascadeBoostTree**) cvGetSeqElem( weak, wi ));
fs << "[";
/*sprintf( buf, "tree %d", wi );
CV_CALL( cvWriteComment( fs, buf, 1 ) );*/
const CvDTreeNode* tempNode;
inner_nodes_queue.push( tree->get_root() );
total_inner_node_idx++;
while (!inner_nodes_queue.empty())
{
tempNode = inner_nodes_queue.front();
@@ -498,7 +501,7 @@ bool CvCascadeClassifier::load( const String cascadeDirName )
node = fs.getFirstTopLevelNode();
if ( !fs.isOpened() )
break;
CvCascadeBoost *tempStage = new CvCascadeBoost;
CvCascadeBoost *tempStage = new CvCascadeBoost;
if ( !tempStage->read( node, (CvFeatureEvaluator*)featureEvaluator, *((CvCascadeBoostParams*)stageParams )) )
{
@@ -516,11 +519,11 @@ void CvCascadeClassifier::getUsedFeaturesIdxMap( Mat& featureMap )
int varCount = featureEvaluator->getNumFeatures() * featureEvaluator->getFeatureSize();
featureMap.create( 1, varCount, CV_32SC1 );
featureMap.setTo(Scalar(-1));
for( vector< Ptr<CvCascadeBoost> >::const_iterator it = stageClassifiers.begin();
it != stageClassifiers.end(); it++ )
((CvCascadeBoost*)((Ptr<CvCascadeBoost>)(*it)))->markUsedFeaturesInMap( featureMap );
for( int fi = 0, idx = 0; fi < varCount; fi++ )
if ( featureMap.at<int>(0, fi) >= 0 )
featureMap.ptr<int>(0)[fi] = idx++;
+6 -3
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "traincascade_features.h"
#include "cascadeclassifier.h"
@@ -28,7 +31,7 @@ bool CvParams::scanAttr( const String prmName, const String val ) { return false
CvFeatureParams::CvFeatureParams() : maxCatCount( 0 ), featSize( 1 )
{
name = CC_FEATURE_PARAMS;
name = CC_FEATURE_PARAMS;
}
void CvFeatureParams::init( const CvFeatureParams& fp )
@@ -55,7 +58,7 @@ bool CvFeatureParams::read( const FileNode &node )
Ptr<CvFeatureParams> CvFeatureParams::create( int featureType )
{
return featureType == HAAR ? Ptr<CvFeatureParams>(new CvHaarFeatureParams) :
featureType == LBP ? Ptr<CvFeatureParams>(new CvLBPFeatureParams) :
featureType == LBP ? Ptr<CvFeatureParams>(new CvLBPFeatureParams) :
featureType == HOG ? Ptr<CvFeatureParams>(new CvHOGFeatureParams) :
Ptr<CvFeatureParams>();
}
@@ -84,7 +87,7 @@ void CvFeatureEvaluator::setImage(const Mat &img, uchar clsLabel, int idx)
Ptr<CvFeatureEvaluator> CvFeatureEvaluator::create(int type)
{
return type == CvFeatureParams::HAAR ? Ptr<CvFeatureEvaluator>(new CvHaarEvaluator) :
type == CvFeatureParams::LBP ? Ptr<CvFeatureEvaluator>(new CvLBPEvaluator) :
type == CvFeatureParams::LBP ? Ptr<CvFeatureEvaluator>(new CvLBPEvaluator) :
type == CvFeatureParams::HOG ? Ptr<CvFeatureEvaluator>(new CvHOGEvaluator) :
Ptr<CvFeatureEvaluator>();
}
+21 -18
View File
@@ -1,16 +1,19 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "haarfeatures.h"
#include "cascadeclassifier.h"
using namespace std;
CvHaarFeatureParams::CvHaarFeatureParams() : mode(BASIC)
{
{
name = HFP_NAME;
}
CvHaarFeatureParams::CvHaarFeatureParams( int _mode ) : mode( _mode )
{
name = HFP_NAME;
name = HFP_NAME;
}
void CvHaarFeatureParams::init( const CvFeatureParams& fp )
@@ -22,7 +25,7 @@ void CvHaarFeatureParams::init( const CvFeatureParams& fp )
void CvHaarFeatureParams::write( FileStorage &fs ) const
{
CvFeatureParams::write( fs );
String modeStr = mode == BASIC ? CC_MODE_BASIC :
String modeStr = mode == BASIC ? CC_MODE_BASIC :
mode == CORE ? CC_MODE_CORE :
mode == ALL ? CC_MODE_ALL : String();
CV_Assert( !modeStr.empty() );
@@ -55,7 +58,7 @@ void CvHaarFeatureParams::printDefaults() const
void CvHaarFeatureParams::printAttrs() const
{
CvFeatureParams::printAttrs();
String mode_str = mode == BASIC ? CC_MODE_BASIC :
String mode_str = mode == BASIC ? CC_MODE_BASIC :
mode == CORE ? CC_MODE_CORE :
mode == ALL ? CC_MODE_ALL : 0;
cout << "mode: " << mode_str << endl;
@@ -156,7 +159,7 @@ void CvHaarEvaluator::generateFeatures()
if( mode != CvHaarFeatureParams::BASIC )
{
// haar_x4
if ( (x+dx*4 <= winSize.width) && (y+dy <= winSize.height) )
if ( (x+dx*4 <= winSize.width) && (y+dy <= winSize.height) )
{
features.push_back( Feature( offset, false,
x, y, dx*4, dy, -1,
@@ -171,61 +174,61 @@ void CvHaarEvaluator::generateFeatures()
}
}
// x2_y2
if ( (x+dx*2 <= winSize.width) && (y+dy*2 <= winSize.height) )
if ( (x+dx*2 <= winSize.width) && (y+dy*2 <= winSize.height) )
{
features.push_back( Feature( offset, false,
x, y, dx*2, dy*2, -1,
x, y, dx, dy, +2,
x+dx, y+dy, dx, dy, +2 ) );
}
if (mode != CvHaarFeatureParams::BASIC)
{
if ( (x+dx*3 <= winSize.width) && (y+dy*3 <= winSize.height) )
if (mode != CvHaarFeatureParams::BASIC)
{
if ( (x+dx*3 <= winSize.width) && (y+dy*3 <= winSize.height) )
{
features.push_back( Feature( offset, false,
x , y , dx*3, dy*3, -1,
x+dx, y+dy, dx , dy , +9) );
}
}
if (mode == CvHaarFeatureParams::ALL)
{
if (mode == CvHaarFeatureParams::ALL)
{
// tilted haar_x2
if ( (x+2*dx <= winSize.width) && (y+2*dx+dy <= winSize.height) && (x-dy>= 0) )
if ( (x+2*dx <= winSize.width) && (y+2*dx+dy <= winSize.height) && (x-dy>= 0) )
{
features.push_back( Feature( offset, true,
x, y, dx*2, dy, -1,
x, y, dx, dy, +2 ) );
}
// tilted haar_y2
if ( (x+dx <= winSize.width) && (y+dx+2*dy <= winSize.height) && (x-2*dy>= 0) )
if ( (x+dx <= winSize.width) && (y+dx+2*dy <= winSize.height) && (x-2*dy>= 0) )
{
features.push_back( Feature( offset, true,
x, y, dx, 2*dy, -1,
x, y, dx, dy, +2 ) );
}
// tilted haar_x3
if ( (x+3*dx <= winSize.width) && (y+3*dx+dy <= winSize.height) && (x-dy>= 0) )
if ( (x+3*dx <= winSize.width) && (y+3*dx+dy <= winSize.height) && (x-dy>= 0) )
{
features.push_back( Feature( offset, true,
x, y, dx*3, dy, -1,
x+dx, y+dx, dx, dy, +3 ) );
}
// tilted haar_y3
if ( (x+dx <= winSize.width) && (y+dx+3*dy <= winSize.height) && (x-3*dy>= 0) )
if ( (x+dx <= winSize.width) && (y+dx+3*dy <= winSize.height) && (x-3*dy>= 0) )
{
features.push_back( Feature( offset, true,
x, y, dx, 3*dy, -1,
x-dy, y+dy, dx, dy, +3 ) );
}
// tilted haar_x4
if ( (x+4*dx <= winSize.width) && (y+4*dx+dy <= winSize.height) && (x-dy>= 0) )
if ( (x+4*dx <= winSize.width) && (y+4*dx+dy <= winSize.height) && (x-dy>= 0) )
{
features.push_back( Feature( offset, true,
x, y, dx*4, dy, -1,
x+dx, y+dx, dx*2, dy, +2 ) );
}
// tilted haar_y4
if ( (x+dx <= winSize.width) && (y+dx+4*dy <= winSize.height) && (x-4*dy>= 0) )
if ( (x+dx <= winSize.width) && (y+dx+4*dy <= winSize.height) && (x-4*dy>= 0) )
{
features.push_back( Feature( offset, true,
x, y, dx, 4*dy, -1,
@@ -296,7 +299,7 @@ void CvHaarEvaluator::Feature::write( FileStorage &fs ) const
fs << CC_RECTS << "[";
for( int ri = 0; ri < CV_HAAR_FEATURE_MAX && rect[ri].r.width != 0; ++ri )
{
fs << "[:" << rect[ri].r.x << rect[ri].r.y <<
fs << "[:" << rect[ri].r.x << rect[ri].r.y <<
rect[ri].r.width << rect[ri].r.height << rect[ri].weight << "]";
}
fs << "]" << CC_TILTED << tilted;
+9 -6
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "cv.h"
#include "imagestorage.h"
#include <stdio.h>
@@ -55,7 +58,7 @@ bool CvCascadeImageReader::NegReader::nextImg()
for( size_t i = 0; i < count; i++ )
{
src = imread( imgFilenames[last++], 0 );
if( src.empty() )
if( src.empty() )
continue;
round += last / count;
round = round % (winSize.width * winSize.height);
@@ -63,7 +66,7 @@ bool CvCascadeImageReader::NegReader::nextImg()
_offset.x = min( (int)round % winSize.width, src.cols - winSize.width );
_offset.y = min( (int)round / winSize.width, src.rows - winSize.height );
if( !src.empty() && src.type() == CV_8UC1
if( !src.empty() && src.type() == CV_8UC1
&& offset.x >= 0 && offset.y >= 0 )
break;
}
@@ -73,7 +76,7 @@ bool CvCascadeImageReader::NegReader::nextImg()
point = offset = _offset;
scale = max( ((float)winSize.width + point.x) / ((float)src.cols),
((float)winSize.height + point.y) / ((float)src.rows) );
Size sz( (int)(scale*src.cols + 0.5F), (int)(scale*src.rows + 0.5F) );
resize( src, img, sz );
return true;
@@ -87,7 +90,7 @@ bool CvCascadeImageReader::NegReader::get( Mat& _img )
CV_Assert( _img.rows == winSize.height );
if( img.empty() )
if ( !nextImg() )
if ( !nextImg() )
return false;
Mat mat( winSize.height, winSize.width, CV_8UC1,
@@ -109,7 +112,7 @@ bool CvCascadeImageReader::NegReader::get( Mat& _img )
resize( src, img, Size( (int)(scale*src.cols), (int)(scale*src.rows) ) );
else
{
if ( !nextImg() )
if ( !nextImg() )
return false;
}
}
@@ -131,7 +134,7 @@ bool CvCascadeImageReader::PosReader::create( const String _filename )
if( !file )
return false;
short tmp = 0;
short tmp = 0;
if( fread( &count, sizeof( count ), 1, file ) != 1 ||
fread( &vecSize, sizeof( vecSize ), 1, file ) != 1 ||
fread( &tmp, sizeof( tmp ), 1, file ) != 1 ||
+3
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "lbpfeatures.h"
#include "cascadeclassifier.h"
+9 -6
View File
@@ -1,3 +1,6 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "cv.h"
#include "cascadeclassifier.h"
@@ -13,11 +16,11 @@ int main( int argc, char* argv[] )
int precalcValBufSize = 256,
precalcIdxBufSize = 256;
bool baseFormatSave = false;
CvCascadeParams cascadeParams;
CvCascadeBoostParams stageParams;
Ptr<CvFeatureParams> featureParams[] = { Ptr<CvFeatureParams>(new CvHaarFeatureParams),
Ptr<CvFeatureParams>(new CvLBPFeatureParams),
Ptr<CvFeatureParams>(new CvLBPFeatureParams),
Ptr<CvFeatureParams>(new CvHOGFeatureParams)
};
int fc = sizeof(featureParams)/sizeof(featureParams[0]);
@@ -85,7 +88,7 @@ int main( int argc, char* argv[] )
{
for( int fi = 0; fi < fc; fi++ )
{
set = featureParams[fi]->scanAttr(argv[i], argv[i+1]);
set = featureParams[fi]->scanAttr(argv[i], argv[i+1]);
if ( !set )
{
i++;
@@ -94,11 +97,11 @@ int main( int argc, char* argv[] )
}
}
}
classifier.train( cascadeDirName,
vecName,
bgName,
numPos, numNeg,
bgName,
numPos, numNeg,
precalcValBufSize, precalcIdxBufSize,
numStages,
cascadeParams,