From: Andrey Kamaev Date: Thu, 7 Jun 2012 17:21:29 +0000 (+0000) Subject: Set stricter warning rules for gcc X-Git-Tag: accepted/2.0/20130307.220821~364^2~679 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49a1ba603826f53de925ca06ac1fa08065a29466;p=profile%2Fivi%2Fopencv.git Set stricter warning rules for gcc --- diff --git a/apps/haartraining/_cvcommon.h b/apps/haartraining/_cvcommon.h index 688e3b2..e4f1081 100644 --- a/apps/haartraining/_cvcommon.h +++ b/apps/haartraining/_cvcommon.h @@ -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" diff --git a/apps/haartraining/cvboost.cpp b/apps/haartraining/cvboost.cpp index 2ee3637..88ada60 100644 --- a/apps/haartraining/cvboost.cpp +++ b/apps/haartraining/cvboost.cpp @@ -80,11 +80,11 @@ typedef struct CvValArray ( *( (float*) (aux->data + ((int) (idx1)) * aux->step ) ) < \ *( (float*) (aux->data + ((int) (idx2)) * aux->step ) ) ) -CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_16s, short, CMP_VALUES, CvValArray* ) +static CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_16s, short, CMP_VALUES, CvValArray* ) -CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32s, int, CMP_VALUES, CvValArray* ) +static CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32s, int, CMP_VALUES, CvValArray* ) -CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32f, float, CMP_VALUES, CvValArray* ) +static CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32f, float, CMP_VALUES, CvValArray* ) CV_BOOST_IMPL void cvGetSortedIndices( CvMat* val, CvMat* idx, int sortcols ) @@ -181,16 +181,16 @@ float cvEvalStumpClassifier( CvClassifier* classifier, CvMat* sample ) assert( classifier != NULL ); assert( sample != NULL ); assert( CV_MAT_TYPE( sample->type ) == CV_32FC1 ); - + if( (CV_MAT_ELEM( (*sample), float, 0, ((CvStumpClassifier*) classifier)->compidx )) < - ((CvStumpClassifier*) classifier)->threshold ) + ((CvStumpClassifier*) classifier)->threshold ) return ((CvStumpClassifier*) classifier)->left; return ((CvStumpClassifier*) classifier)->right; } #define ICV_DEF_FIND_STUMP_THRESHOLD( suffix, type, error ) \ -CV_BOOST_IMPL int icvFindStumpThreshold_##suffix( \ +static int icvFindStumpThreshold_##suffix( \ uchar* data, size_t datastep, \ uchar* wdata, size_t wstep, \ uchar* ydata, size_t ystep, \ @@ -430,13 +430,13 @@ CvClassifier* cvCreateStumpClassifier( CvMat* trainData, int ystep = 0; uchar* idxdata = NULL; int idxstep = 0; - int l = 0; /* number of indices */ + int l = 0; /* number of indices */ uchar* wdata = NULL; int wstep = 0; int* idx = NULL; int i = 0; - + float sumw = FLT_MAX; float sumwy = FLT_MAX; float sumwyy = FLT_MAX; @@ -553,7 +553,7 @@ CvClassifier* cvCreateStumpClassifier( CvMat* trainData, ( data + i * ((size_t) cstep), sstep, wdata, wstep, ydata, ystep, (uchar*) idx, sizeof( int ), l, &(stump->lerror), &(stump->rerror), - &(stump->threshold), &(stump->left), &(stump->right), + &(stump->threshold), &(stump->left), &(stump->right), &sumw, &sumwy, &sumwyy ) ) { stump->compidx = i; @@ -601,7 +601,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, size_t ystep = 0; uchar* idxdata = NULL; size_t idxstep = 0; - int l = 0; /* number of indices */ + int l = 0; /* number of indices */ uchar* wdata = NULL; size_t wstep = 0; @@ -614,7 +614,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, char* filter = NULL; int i = 0; - + int compidx = 0; int stumperror; int portion; @@ -635,7 +635,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, int t_compidx; int t_n; - + int ti; int tj; int tk; @@ -722,7 +722,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, if( ((CvMTStumpTrainParams*) trainParams)->getTrainData != NULL ) { n = ((CvMTStumpTrainParams*) trainParams)->numcomp; - } + } } assert( datan <= n ); @@ -755,14 +755,14 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, memset( (void*) stump, 0, sizeof( CvStumpClassifier ) ); portion = ((CvMTStumpTrainParams*)trainParams)->portion; - + if( portion < 1 ) { /* auto portion */ portion = n; #ifdef _OPENMP - portion /= omp_get_max_threads(); - #endif /* _OPENMP */ + portion /= omp_get_max_threads(); + #endif /* _OPENMP */ } stump->eval = cvEvalStumpClassifier; @@ -796,7 +796,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, t_compidx = 0; t_n = 0; - + ti = 0; tj = 0; tk = 0; @@ -811,7 +811,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, t_idx = NULL; mat.data.ptr = NULL; - + if( datan < n ) { /* prepare matrix for callback */ @@ -848,7 +848,7 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, { t_idx[ti] = ti; } - } + } } } @@ -902,12 +902,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, t_idx[tk++] = curidx; } } - if( findStumpThreshold_32s[stumperror]( + if( findStumpThreshold_32s[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, (uchar*) t_idx, sizeof( int ), tk, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -927,12 +927,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, t_idx[tk++] = curidx; } } - if( findStumpThreshold_32s[stumperror]( + if( findStumpThreshold_32s[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, (uchar*) t_idx, sizeof( int ), tk, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -952,12 +952,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, t_idx[tk++] = curidx; } } - if( findStumpThreshold_32s[stumperror]( + if( findStumpThreshold_32s[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, (uchar*) t_idx, sizeof( int ), tk, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -977,12 +977,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, case CV_16SC1: for( ti = t_compidx; ti < MIN( sortedn, t_compidx + t_n ); ti++ ) { - if( findStumpThreshold_16s[stumperror]( + if( findStumpThreshold_16s[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, sorteddata + ti * sortedcstep, sortedsstep, sortedm, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -992,12 +992,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, case CV_32SC1: for( ti = t_compidx; ti < MIN( sortedn, t_compidx + t_n ); ti++ ) { - if( findStumpThreshold_32s[stumperror]( + if( findStumpThreshold_32s[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, sorteddata + ti * sortedcstep, sortedsstep, sortedm, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -1007,12 +1007,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, case CV_32FC1: for( ti = t_compidx; ti < MIN( sortedn, t_compidx + t_n ); ti++ ) { - if( findStumpThreshold_32f[stumperror]( + if( findStumpThreshold_32f[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, sorteddata + ti * sortedcstep, sortedsstep, sortedm, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -1032,12 +1032,12 @@ CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData, va.data = t_data + ti * t_cstep; va.step = t_sstep; icvSortIndexedValArray_32s( t_idx, l, &va ); - if( findStumpThreshold_32s[stumperror]( + if( findStumpThreshold_32s[stumperror]( t_data + ti * t_cstep, t_sstep, wdata, wstep, ydata, ystep, (uchar*)t_idx, sizeof( int ), l, &lerror, &rerror, - &threshold, &left, &right, + &threshold, &left, &right, &sumw, &sumwy, &sumwyy ) ) { optcompidx = ti; @@ -1117,7 +1117,7 @@ float cvEvalCARTClassifier( CvClassifier* classifier, CvMat* sample ) { if( (CV_MAT_ELEM( (*sample), float, 0, ((CvCARTClassifier*) classifier)->compidx[idx] )) < - ((CvCARTClassifier*) classifier)->threshold[idx] ) + ((CvCARTClassifier*) classifier)->threshold[idx] ) { idx = ((CvCARTClassifier*) classifier)->left[idx]; } @@ -1133,7 +1133,7 @@ float cvEvalCARTClassifier( CvClassifier* classifier, CvMat* sample ) { if( (CV_MAT_ELEM( (*sample), float, ((CvCARTClassifier*) classifier)->compidx[idx], 0 )) < - ((CvCARTClassifier*) classifier)->threshold[idx] ) + ((CvCARTClassifier*) classifier)->threshold[idx] ) { idx = ((CvCARTClassifier*) classifier)->left[idx]; } @@ -1142,14 +1142,14 @@ float cvEvalCARTClassifier( CvClassifier* classifier, CvMat* sample ) idx = ((CvCARTClassifier*) classifier)->right[idx]; } } while( idx > 0 ); - } + } __END__; return ((CvCARTClassifier*) classifier)->val[-idx]; } -CV_BOOST_IMPL +static float cvEvalCARTClassifierIdx( CvClassifier* classifier, CvMat* sample ) { CV_FUNCNAME( "cvEvalCARTClassifierIdx" ); @@ -1170,7 +1170,7 @@ float cvEvalCARTClassifierIdx( CvClassifier* classifier, CvMat* sample ) { if( (CV_MAT_ELEM( (*sample), float, 0, ((CvCARTClassifier*) classifier)->compidx[idx] )) < - ((CvCARTClassifier*) classifier)->threshold[idx] ) + ((CvCARTClassifier*) classifier)->threshold[idx] ) { idx = ((CvCARTClassifier*) classifier)->left[idx]; } @@ -1186,7 +1186,7 @@ float cvEvalCARTClassifierIdx( CvClassifier* classifier, CvMat* sample ) { if( (CV_MAT_ELEM( (*sample), float, ((CvCARTClassifier*) classifier)->compidx[idx], 0 )) < - ((CvCARTClassifier*) classifier)->threshold[idx] ) + ((CvCARTClassifier*) classifier)->threshold[idx] ) { idx = ((CvCARTClassifier*) classifier)->left[idx]; } @@ -1195,7 +1195,7 @@ float cvEvalCARTClassifierIdx( CvClassifier* classifier, CvMat* sample ) idx = ((CvCARTClassifier*) classifier)->right[idx]; } } while( idx > 0 ); - } + } __END__; @@ -1209,7 +1209,7 @@ void cvReleaseCARTClassifier( CvClassifier** classifier ) *classifier = NULL; } -void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold, +static void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold, CvMat* idx, CvMat** left, CvMat** right, void* userdata ) { @@ -1258,7 +1258,7 @@ void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold, } } -void CV_CDECL icvDefaultSplitIdx_C( int compidx, float threshold, +static void CV_CDECL icvDefaultSplitIdx_C( int compidx, float threshold, CvMat* idx, CvMat** left, CvMat** right, void* userdata ) { @@ -1333,13 +1333,13 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, int count = 0; int i = 0; int j = 0; - + CvCARTNode* intnode = NULL; CvCARTNode* list = NULL; int listcount = 0; CvMat* lidx = NULL; CvMat* ridx = NULL; - + float maxerrdrop = 0.0F; int idx = 0; @@ -1349,17 +1349,17 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, void* userdata; count = ((CvCARTTrainParams*) trainParams)->count; - + assert( count > 0 ); - datasize = sizeof( *cart ) + (sizeof( float ) + 3 * sizeof( int )) * count + + datasize = sizeof( *cart ) + (sizeof( float ) + 3 * sizeof( int )) * count + sizeof( float ) * (count + 1); - + cart = (CvCARTClassifier*) cvAlloc( datasize ); memset( cart, 0, datasize ); - + cart->count = count; - + cart->eval = cvEvalCARTClassifier; cart->save = NULL; cart->release = cvReleaseCARTClassifier; @@ -1399,7 +1399,7 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, /* split last added node */ splitIdxCallback( intnode[i-1].stump->compidx, intnode[i-1].stump->threshold, intnode[i-1].sampleIdx, &lidx, &ridx, userdata ); - + if( intnode[i-1].stump->lerror != 0.0F ) { list[listcount].sampleIdx = lidx; @@ -1436,7 +1436,7 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, { cvReleaseMat( &ridx ); } - + if( listcount == 0 ) break; /* find the best node to be added to the tree */ @@ -1474,7 +1474,7 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, cart->count++; cart->compidx[i] = intnode[i].stump->compidx; cart->threshold[i] = intnode[i].stump->threshold; - + /* leaves */ if( cart->left[i] <= 0 ) { @@ -1489,7 +1489,7 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, j++; } } - + /* CLEAN UP */ for( i = 0; i < count && (intnode[i].stump != NULL); i++ ) { @@ -1504,7 +1504,7 @@ CvClassifier* cvCreateCARTClassifier( CvMat* trainData, list[i].stump->release( (CvClassifier**) &(list[i].stump) ); cvReleaseMat( &(list[i].sampleIdx) ); } - + cvFree( &intnode ); return (CvClassifier*) cart; @@ -1529,7 +1529,7 @@ typedef struct CvBoostTrainer * using ANY appropriate weak classifier */ -CV_BOOST_IMPL +static CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses, CvMat* weakTrainVals, CvMat* /*weights*/, @@ -1569,7 +1569,7 @@ CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses, { CV_MAT2VEC( *sampleIdx, idxdata, idxstep, idxnum ); } - + datasize = sizeof( *ptr ) + sizeof( *ptr->idx ) * idxnum; ptr = (CvBoostTrainer*) cvAlloc( datasize ); memset( ptr, 0, datasize ); @@ -1578,7 +1578,7 @@ CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses, ptr->count = m; ptr->type = type; - + if( idxnum > 0 ) { CvScalar s; @@ -1595,7 +1595,7 @@ CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses, { idx = (ptr->idx) ? ptr->idx[i] : i; - *((float*) (traindata + idx * trainstep)) = + *((float*) (traindata + idx * trainstep)) = 2.0F * (*((float*) (ydata + idx * ystep))) - 1.0F; } @@ -1607,7 +1607,7 @@ CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses, * Discrete AdaBoost functions * */ -CV_BOOST_IMPL +static float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals, CvMat* trainClasses, CvMat* /*weakTrainVals*/, @@ -1651,18 +1651,18 @@ float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals, sumw += *((float*) (wdata + idx*wstep)); err += (*((float*) (wdata + idx*wstep))) * - ( (*((float*) (evaldata + idx*evalstep))) != + ( (*((float*) (evaldata + idx*evalstep))) != 2.0F * (*((float*) (ydata + idx*ystep))) - 1.0F ); } err /= sumw; err = -cvLogRatio( err ); - + for( i = 0; i < trainer->count; i++ ) { idx = (trainer->idx) ? trainer->idx[i] : i; - *((float*) (wdata + idx*wstep)) *= expf( err * - ((*((float*) (evaldata + idx*evalstep))) != + *((float*) (wdata + idx*wstep)) *= expf( err * + ((*((float*) (evaldata + idx*evalstep))) != 2.0F * (*((float*) (ydata + idx*ystep))) - 1.0F) ); sumw += *((float*) (wdata + idx*wstep)); } @@ -1672,7 +1672,7 @@ float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals, *((float*) (wdata + idx * wstep)) /= sumw; } - + return err; } @@ -1681,7 +1681,7 @@ float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals, * Real AdaBoost functions * */ -CV_BOOST_IMPL +static float icvBoostNextWeakClassifierRAB( CvMat* weakEvalVals, CvMat* trainClasses, CvMat* /*weakTrainVals*/, @@ -1731,7 +1731,7 @@ float icvBoostNextWeakClassifierRAB( CvMat* weakEvalVals, *((float*) (wdata + idx*wstep)) /= sumw; } - + return 1.0F; } @@ -1743,7 +1743,7 @@ float icvBoostNextWeakClassifierRAB( CvMat* weakEvalVals, #define CV_LB_PROB_THRESH 0.01F #define CV_LB_WEIGHT_THRESHOLD 0.0001F -CV_BOOST_IMPL +static void icvResponsesAndWeightsLB( int num, uchar* wdata, int wstep, uchar* ydata, int ystep, uchar* fdata, int fstep, @@ -1761,18 +1761,18 @@ void icvResponsesAndWeightsLB( int num, uchar* wdata, int wstep, *((float*) (wdata + idx*wstep)) = MAX( p * (1.0F - p), CV_LB_WEIGHT_THRESHOLD ); if( *((float*) (ydata + idx*ystep)) == 1.0F ) { - *((float*) (traindata + idx*trainstep)) = + *((float*) (traindata + idx*trainstep)) = 1.0F / (MAX( p, CV_LB_PROB_THRESH )); } else { - *((float*) (traindata + idx*trainstep)) = + *((float*) (traindata + idx*trainstep)) = -1.0F / (MAX( 1.0F - p, CV_LB_PROB_THRESH )); } } } -CV_BOOST_IMPL +static CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses, CvMat* weakTrainVals, CvMat* weights, @@ -1819,7 +1819,7 @@ CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses, { CV_MAT2VEC( *sampleIdx, idxdata, idxstep, idxnum ); } - + datasize = sizeof( *ptr ) + sizeof( *ptr->F ) * m + sizeof( *ptr->idx ) * idxnum; ptr = (CvBoostTrainer*) cvAlloc( datasize ); memset( ptr, 0, datasize ); @@ -1828,7 +1828,7 @@ CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses, ptr->count = m; ptr->type = type; - + if( idxnum > 0 ) { CvScalar s; @@ -1854,7 +1854,7 @@ CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses, return ptr; } -CV_BOOST_IMPL +static float icvBoostNextWeakClassifierLB( CvMat* weakEvalVals, CvMat* trainClasses, CvMat* weakTrainVals, @@ -1900,7 +1900,7 @@ float icvBoostNextWeakClassifierLB( CvMat* weakEvalVals, trainer->F[idx] += *((float*) (evaldata + idx * evalstep)); } - + icvResponsesAndWeightsLB( trainer->count, wdata, wstep, ydata, ystep, (uchar*) trainer->F, sizeof( *trainer->F ), traindata, trainstep, trainer->idx ); @@ -1913,7 +1913,7 @@ float icvBoostNextWeakClassifierLB( CvMat* weakEvalVals, * Gentle AdaBoost * */ -CV_BOOST_IMPL +static float icvBoostNextWeakClassifierGAB( CvMat* weakEvalVals, CvMat* trainClasses, CvMat* /*weakTrainVals*/, @@ -1952,12 +1952,12 @@ float icvBoostNextWeakClassifierGAB( CvMat* weakEvalVals, { idx = (trainer->idx) ? trainer->idx[i] : i; - *((float*) (wdata + idx*wstep)) *= + *((float*) (wdata + idx*wstep)) *= expf( -(*((float*) (evaldata + idx*evalstep))) * ( 2.0F * (*((float*) (ydata + idx*ystep))) - 1.0F ) ); sumw += *((float*) (wdata + idx*wstep)); } - + for( i = 0; i < trainer->count; i++ ) { idx = (trainer->idx) ? trainer->idx[i] : i; @@ -2033,10 +2033,10 @@ float cvBoostNextWeakClassifier( CvMat* weakEvalVals, typedef struct CvBtTrainer { - /* {{ external */ + /* {{ external */ CvMat* trainData; int flags; - + CvMat* trainClasses; int m; uchar* ydata; @@ -2044,7 +2044,7 @@ typedef struct CvBtTrainer CvMat* sampleIdx; int numsamples; - + float param[2]; CvBoostType type; int numclasses; @@ -2071,7 +2071,7 @@ typedef struct CvBtTrainer typedef void (*CvZeroApproxFunc)( float* approx, CvBtTrainer* trainer ); /* Mean zero approximation */ -void icvZeroApproxMean( float* approx, CvBtTrainer* trainer ) +static void icvZeroApproxMean( float* approx, CvBtTrainer* trainer ) { int i; int idx; @@ -2088,7 +2088,7 @@ void icvZeroApproxMean( float* approx, CvBtTrainer* trainer ) /* * Median zero approximation */ -void icvZeroApproxMed( float* approx, CvBtTrainer* trainer ) +static void icvZeroApproxMed( float* approx, CvBtTrainer* trainer ) { int i; int idx; @@ -2098,7 +2098,7 @@ void icvZeroApproxMed( float* approx, CvBtTrainer* trainer ) idx = icvGetIdxAt( trainer->sampleIdx, i ); trainer->f[i] = *((float*) (trainer->ydata + idx * trainer->ystep)); } - + icvSort_32f( trainer->f, trainer->numsamples, 0 ); approx[0] = trainer->f[trainer->numsamples / 2]; } @@ -2106,7 +2106,7 @@ void icvZeroApproxMed( float* approx, CvBtTrainer* trainer ) /* * 0.5 * log( mean(y) / (1 - mean(y)) ) where y in {0, 1} */ -void icvZeroApproxLog( float* approx, CvBtTrainer* trainer ) +static void icvZeroApproxLog( float* approx, CvBtTrainer* trainer ) { float y_mean; @@ -2117,7 +2117,7 @@ void icvZeroApproxLog( float* approx, CvBtTrainer* trainer ) /* * 0 zero approximation */ -void icvZeroApprox0( float* approx, CvBtTrainer* trainer ) +static void icvZeroApprox0( float* approx, CvBtTrainer* trainer ) { int i; @@ -2143,7 +2143,7 @@ static CvZeroApproxFunc icvZeroApproxFunc[] = CV_BOOST_IMPL void cvBtNext( CvCARTClassifier** trees, CvBtTrainer* trainer ); -CV_BOOST_IMPL +static CvBtTrainer* cvBtStart( CvCARTClassifier** trees, CvMat* trainData, int flags, @@ -2164,13 +2164,13 @@ CvBtTrainer* cvBtStart( CvCARTClassifier** trees, float* zero_approx; int m; int i, j; - + if( trees == NULL ) { CV_ERROR( CV_StsNullPtr, "Invalid trees parameter" ); } - - if( type < CV_DABCLASS || type > CV_MREG ) + + if( type < CV_DABCLASS || type > CV_MREG ) { CV_ERROR( CV_StsUnsupportedFormat, "Unsupported type parameter" ); } @@ -2198,7 +2198,7 @@ CvBtTrainer* cvBtStart( CvCARTClassifier** trees, ptr->flags = flags; ptr->trainClasses = trainClasses; CV_MAT2VEC( *trainClasses, ptr->ydata, ptr->ystep, ptr->m ); - + memset( &(ptr->cartParams), 0, sizeof( ptr->cartParams ) ); memset( &(ptr->stumpParams), 0, sizeof( ptr->stumpParams ) ); @@ -2229,10 +2229,10 @@ CvBtTrainer* cvBtStart( CvCARTClassifier** trees, ptr->sampleIdx = sampleIdx; ptr->numsamples = ( sampleIdx == NULL ) ? ptr->m : MAX( sampleIdx->rows, sampleIdx->cols ); - + ptr->weights = cvCreateMat( 1, m, CV_32FC1 ); - cvSet( ptr->weights, cvScalar( 1.0 ) ); - + cvSet( ptr->weights, cvScalar( 1.0 ) ); + if( type <= CV_GABCLASS ) { ptr->boosttrainer = cvBoostStartTraining( ptr->trainClasses, ptr->y, @@ -2261,7 +2261,7 @@ CvBtTrainer* cvBtStart( CvCARTClassifier** trees, { trees[i]->val[j] += zero_approx[i]; } - } + } CV_CALL( cvFree( &zero_approx ) ); } @@ -2270,14 +2270,14 @@ CvBtTrainer* cvBtStart( CvCARTClassifier** trees, return ptr; } -void icvBtNext_LSREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) +static void icvBtNext_LSREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) { int i; /* yhat_i = y_i - F_(m-1)(x_i) */ for( i = 0; i < trainer->m; i++ ) { - trainer->y->data.fl[i] = + trainer->y->data.fl[i] = *((float*) (trainer->ydata + i * trainer->ystep)) - trainer->f[i]; } @@ -2288,7 +2288,7 @@ void icvBtNext_LSREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) } -void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) +static void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) { CvCARTClassifier* ptr; int i, j; @@ -2296,7 +2296,7 @@ void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) int sample_step; uchar* sample_data; int index; - + int data_size; int* idx; float* resp; @@ -2356,19 +2356,19 @@ void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) cvFree( &idx ); cvFree( &resp ); - + trees[0] = ptr; } -void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) +static void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) { CvCARTClassifier* ptr; int i, j; CvMat sample; int sample_step; uchar* sample_data; - + int data_size; int* idx; float* resid; @@ -2395,7 +2395,7 @@ void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) /* for delta */ resp[i] = (float) fabs( resid[index] ); } - + /* delta = quantile_alpha{abs(resid_i)} */ icvSort_32f( resp, trainer->numsamples, 0 ); delta = resp[(int)(trainer->param[1] * (trainer->numsamples - 1))]; @@ -2407,7 +2407,7 @@ void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) trainer->y->data.fl[index] = MIN( delta, ((float) fabs( resid[index] )) ) * CV_SIGN( resid[index] ); } - + ptr = (CvCARTClassifier*) cvCreateCARTClassifier( trainer->trainData, trainer->flags, trainer->y, NULL, NULL, NULL, trainer->sampleIdx, trainer->weights, (CvClassifierTrainParams*) &trainer->cartParams ); @@ -2439,7 +2439,7 @@ void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) /* rhat = median(y_i - F_(m-1)(x_i)) */ icvSort_32f( resp, respnum, 0 ); rhat = resp[respnum / 2]; - + /* val = sum{sign(r_i - rhat_i) * min(delta, abs(r_i - rhat_i)} * r_i = y_i - F_(m-1)(x_i) */ @@ -2464,7 +2464,7 @@ void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) cvFree( &resid ); cvFree( &resp ); cvFree( &idx ); - + trees[0] = ptr; } @@ -2476,14 +2476,14 @@ void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer ) #define CV_LOG_VAL_MAX 18.0 -void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) +static void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) { CvCARTClassifier* ptr; int i, j; CvMat sample; int sample_step; uchar* sample_data; - + int data_size; int* idx; int respnum; @@ -2505,7 +2505,7 @@ void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) weights = (float*) cvAlloc( data_size ); data_size = trainer->m * sizeof( *sorted_weights ); sorted_weights = (float*) cvAlloc( data_size ); - + /* yhat_i = (4 * y_i - 2) / ( 1 + exp( (4 * y_i - 2) * F_(m-1)(x_i) ) ). * y_i in {0, 1} */ @@ -2523,32 +2523,32 @@ void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) sorted_weights[i] = weights[index]; sum_weights += sorted_weights[i]; } - + trimmed_idx = NULL; sample_idx = trainer->sampleIdx; trimmed_num = trainer->numsamples; if( trainer->param[1] < 1.0F ) { /* perform weight trimming */ - + float threshold; int count; - + icvSort_32f( sorted_weights, trainer->numsamples, 0 ); sum_weights *= (1.0F - trainer->param[1]); - + i = -1; do { sum_weights -= sorted_weights[++i]; } while( sum_weights > 0.0F && i < (trainer->numsamples - 1) ); - + threshold = sorted_weights[i]; while( i > 0 && sorted_weights[i-1] == threshold ) i--; if( i > 0 ) { - trimmed_num = trainer->numsamples - i; + trimmed_num = trainer->numsamples - i; trimmed_idx = cvCreateMat( 1, trimmed_num, CV_32FC1 ); count = 0; for( i = 0; i < trainer->numsamples; i++ ) @@ -2560,12 +2560,12 @@ void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) count++; } } - + assert( count == trimmed_num ); sample_idx = trimmed_idx; - printf( "Used samples %%: %g\n", + printf( "Used samples %%: %g\n", (float) trimmed_num / (float) trainer->numsamples * 100.0F ); } } @@ -2608,22 +2608,22 @@ void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) } ptr->val[j] = val; } - + if( trimmed_idx != NULL ) cvReleaseMat( &trimmed_idx ); cvFree( &sorted_weights ); cvFree( &weights ); cvFree( &idx ); - + trees[0] = ptr; } -void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) +static void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) { int i, j, k, kk, num; CvMat sample; int sample_step; uchar* sample_data; - + int data_size; int* idx; int respnum; @@ -2673,7 +2673,7 @@ void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) sum_exp_f += exp_f; } - val = (float) ( (*((float*) (trainer->ydata + index * trainer->ystep))) + val = (float) ( (*((float*) (trainer->ydata + index * trainer->ystep))) == (float) k ); val -= (float) ( (sum_exp_f == CV_VAL_MAX) ? 0.0 : ( 1.0 / sum_exp_f ) ); @@ -2692,25 +2692,25 @@ void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) if( trainer->param[1] < 1.0F ) { /* perform weight trimming */ - + float threshold; int count; - + icvSort_32f( sorted_weights, trainer->numsamples, 0 ); sum_weights *= (1.0F - trainer->param[1]); - + i = -1; do { sum_weights -= sorted_weights[++i]; } while( sum_weights > 0.0F && i < (trainer->numsamples - 1) ); - + threshold = sorted_weights[i]; while( i > 0 && sorted_weights[i-1] == threshold ) i--; if( i > 0 ) { - trimmed_num = trainer->numsamples - i; + trimmed_num = trainer->numsamples - i; trimmed_idx->cols = trimmed_num; count = 0; for( i = 0; i < trainer->numsamples; i++ ) @@ -2722,12 +2722,12 @@ void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) count++; } } - + assert( count == trimmed_num ); sample_idx = trimmed_idx; - printf( "k: %d Used samples %%: %g\n", k, + printf( "k: %d Used samples %%: %g\n", k, (float) trimmed_num / (float) trainer->numsamples * 100.0F ); } } /* weight trimming */ @@ -2773,7 +2773,7 @@ void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) trees[k]->val[j] = val; } } /* for each class */ - + cvReleaseMat( &trimmed_idx ); cvFree( &sorted_weights ); cvFree( &weights ); @@ -2781,7 +2781,7 @@ void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) } -void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) +static void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) { float alpha; int i; @@ -2799,19 +2799,19 @@ void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) num_samples = ( sample_idx == NULL ) ? trainer->m : MAX( sample_idx->rows, sample_idx->cols ); - printf( "Used samples %%: %g\n", + printf( "Used samples %%: %g\n", (float) num_samples / (float) trainer->numsamples * 100.0F ); trees[0] = (CvCARTClassifier*) cvCreateCARTClassifier( trainer->trainData, trainer->flags, trainer->y, NULL, NULL, NULL, sample_idx, trainer->weights, (CvClassifierTrainParams*) &trainer->cartParams ); - + /* evaluate samples */ CV_GET_SAMPLE( *trainer->trainData, trainer->flags, 0, sample ); CV_GET_SAMPLE_STEP( *trainer->trainData, trainer->flags, sample_step ); sample_data = sample.data.ptr; - + for( i = 0; i < trainer->m; i++ ) { sample.data.ptr = sample_data + i * sample_step; @@ -2820,7 +2820,7 @@ void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) alpha = cvBoostNextWeakClassifier( weak_eval_vals, trainer->trainClasses, trainer->y, trainer->weights, trainer->boosttrainer ); - + /* multiply tree by alpha */ for( i = 0; i <= trees[0]->count; i++ ) { @@ -2833,7 +2833,7 @@ void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer ) trees[0]->val[i] = cvLogRatio( trees[0]->val[i] ); } } - + if( sample_idx != NULL && sample_idx != trainer->sampleIdx ) { cvReleaseMat( &sample_idx ); @@ -2865,7 +2865,7 @@ void cvBtNext( CvCARTClassifier** trees, CvBtTrainer* trainer ) int sample_step; uchar* sample_data; - icvBtNextFunc[trainer->type]( trees, trainer ); + icvBtNextFunc[trainer->type]( trees, trainer ); /* shrinkage */ if( trainer->param[0] != 1.0F ) @@ -2890,26 +2890,26 @@ void cvBtNext( CvCARTClassifier** trees, CvBtTrainer* trainer ) index = icvGetIdxAt( trainer->sampleIdx, i ); sample.data.ptr = sample_data + index * sample_step; for( j = 0; j < trainer->numclasses; j++ ) - { - trainer->f[index * trainer->numclasses + j] += + { + trainer->f[index * trainer->numclasses + j] += trees[j]->eval( (CvClassifier*) (trees[j]), &sample ); } } } } -CV_BOOST_IMPL +static void cvBtEnd( CvBtTrainer** trainer ) { CV_FUNCNAME( "cvBtEnd" ); - + __BEGIN__; - + if( trainer == NULL || (*trainer) == NULL ) { CV_ERROR( CV_StsNullPtr, "Invalid trainer parameter" ); } - + if( (*trainer)->y != NULL ) { CV_CALL( cvReleaseMat( &((*trainer)->y) ) ); @@ -2931,7 +2931,7 @@ void cvBtEnd( CvBtTrainer** trainer ) * Boosted tree model as a classifier * \****************************************************************************************/ -CV_BOOST_IMPL +static float cvEvalBtClassifier( CvClassifier* classifier, CvMat* sample ) { float val; @@ -2939,7 +2939,7 @@ float cvEvalBtClassifier( CvClassifier* classifier, CvMat* sample ) CV_FUNCNAME( "cvEvalBtClassifier" ); __BEGIN__; - + int i; val = 0.0F; @@ -2972,7 +2972,7 @@ float cvEvalBtClassifier( CvClassifier* classifier, CvMat* sample ) return val; } -CV_BOOST_IMPL +static float cvEvalBtClassifier2( CvClassifier* classifier, CvMat* sample ) { float val; @@ -2980,7 +2980,7 @@ float cvEvalBtClassifier2( CvClassifier* classifier, CvMat* sample ) CV_FUNCNAME( "cvEvalBtClassifier2" ); __BEGIN__; - + CV_CALL( val = cvEvalBtClassifier( classifier, sample ) ); __END__; @@ -2988,7 +2988,7 @@ float cvEvalBtClassifier2( CvClassifier* classifier, CvMat* sample ) return (float) (val >= 0.0F); } -CV_BOOST_IMPL +static float cvEvalBtClassifierK( CvClassifier* classifier, CvMat* sample ) { int cls = 0; @@ -2996,7 +2996,7 @@ float cvEvalBtClassifierK( CvClassifier* classifier, CvMat* sample ) CV_FUNCNAME( "cvEvalBtClassifierK" ); __BEGIN__; - + int i, k; float max_val; int numclasses; @@ -3072,7 +3072,7 @@ static CvEvalBtClassifier icvEvalBtClassifier[] = cvEvalBtClassifier }; -CV_BOOST_IMPL +static int cvSaveBtClassifier( CvClassifier* classifier, const char* filename ) { CV_FUNCNAME( "cvSaveBtClassifier" ); @@ -3087,7 +3087,7 @@ int cvSaveBtClassifier( CvClassifier* classifier, const char* filename ) CV_ASSERT( classifier ); CV_ASSERT( filename ); - + if( !icvMkDir( filename ) || (file = fopen( filename, "w" )) == 0 ) { CV_ERROR( CV_StsError, "Unable to create file" ); @@ -3101,7 +3101,7 @@ int cvSaveBtClassifier( CvClassifier* classifier, const char* filename ) ((CvBtClassifier*) classifier)->numclasses, ((CvBtClassifier*) classifier)->numfeatures, ((CvBtClassifier*) classifier)->numiter ); - + for( i = 0; i < ((CvBtClassifier*) classifier)->numclasses * ((CvBtClassifier*) classifier)->numiter; i++ ) { @@ -3137,7 +3137,7 @@ int cvSaveBtClassifier( CvClassifier* classifier, const char* filename ) } -CV_BOOST_IMPL +static void cvReleaseBtClassifier( CvClassifier** ptr ) { CV_FUNCNAME( "cvReleaseBtClassifier" ); @@ -3183,7 +3183,7 @@ void cvReleaseBtClassifier( CvClassifier** ptr ) __END__; } -void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags, +static void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags, CvMat*, CvMat* , CvMat*, CvMat*, CvMat* ) { CV_FUNCNAME( "cvTuneBtClassifier" ); @@ -3231,7 +3231,7 @@ void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags, ((CvBtClassifier*) classifier)->seq->total; CV_CALL( ptr = cvAlloc( data_size ) ); CV_CALL( cvCvtSeqToArray( ((CvBtClassifier*) classifier)->seq, ptr ) ); - CV_CALL( cvReleaseMemStorage( + CV_CALL( cvReleaseMemStorage( &(((CvBtClassifier*) classifier)->seq->storage) ) ); ((CvBtClassifier*) classifier)->trees = (CvCARTClassifier**) ptr; classifier->flags &= ~CV_TUNABLE; @@ -3244,7 +3244,7 @@ void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags, __END__; } -CvBtClassifier* icvAllocBtClassifier( CvBoostType type, int flags, int numclasses, +static CvBtClassifier* icvAllocBtClassifier( CvBoostType type, int flags, int numclasses, int numiter ) { CvBtClassifier* ptr; @@ -3317,7 +3317,7 @@ CvClassifier* cvCreateBtClassifier( CvMat* trainData, CV_ASSERT( trainParams != NULL ); type = ((CvBtClassifierTrainParams*) trainParams)->type; - + if( type >= CV_DABCLASS && type <= CV_GABCLASS && sampleIdx ) { CV_ERROR( CV_StsBadArg, "Sample indices are not supported for this type" ); @@ -3330,7 +3330,7 @@ CvClassifier* cvCreateBtClassifier( CvMat* trainData, cvMinMaxLoc( trainClasses, &min_val, &max_val ); num_classes = (int) (max_val + 1.0); - + CV_ASSERT( num_classes >= 2 ); } else @@ -3338,12 +3338,12 @@ CvClassifier* cvCreateBtClassifier( CvMat* trainData, num_classes = 1; } num_iter = ((CvBtClassifierTrainParams*) trainParams)->numiter; - + CV_ASSERT( num_iter > 0 ); ptr = icvAllocBtClassifier( type, CV_TUNABLE | flags, num_classes, num_iter ); ptr->numfeatures = (CV_IS_ROW_SAMPLE( flags )) ? trainData->cols : trainData->rows; - + i = 0; printf( "Iteration %d\n", 1 ); @@ -3358,7 +3358,7 @@ CvClassifier* cvCreateBtClassifier( CvMat* trainData, CV_CALL( cvSeqPushMulti( ptr->seq, trees, ptr->numclasses ) ); CV_CALL( cvFree( &trees ) ); ptr->numiter++; - + for( i = 1; i < num_iter; i++ ) { ptr->tune( (CvClassifier*) ptr, NULL, CV_TUNABLE, NULL, NULL, NULL, NULL, NULL ); @@ -3380,7 +3380,7 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) CvBtClassifier* ptr = 0; CV_FUNCNAME( "cvCreateBtClassifierFromFile" ); - + __BEGIN__; FILE* file; @@ -3400,7 +3400,7 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) { CV_ERROR( CV_StsError, "Unable to open file" ); } - + values_read = fscanf( file, "%d %d %d %d", &type, &num_classes, &num_features, &num_classifiers ); CV_Assert(values_read == 4); @@ -3414,7 +3414,7 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) } ptr = icvAllocBtClassifier( (CvBoostType) type, 0, num_classes, num_classifiers ); ptr->numfeatures = num_features; - + for( i = 0; i < num_classes * num_classifiers; i++ ) { int count; @@ -3532,7 +3532,7 @@ CvMat* cvTrimWeights( CvMat* weights, CvMat* idx, float factor ) count++; } } - + assert( count == ptr->cols ); } cvFree( &sorted_weights ); @@ -3572,7 +3572,7 @@ void cvReadTrainData( const char* filename, int flags, { CV_ERROR( CV_StsNullPtr, "trainClasses must be not NULL" ); } - + *trainData = NULL; *trainClasses = NULL; file = fopen( filename, "r" ); @@ -3592,7 +3592,7 @@ void cvReadTrainData( const char* filename, int flags, { CV_CALL( *trainData = cvCreateMat( n, m, CV_32FC1 ) ); } - + CV_CALL( *trainClasses = cvCreateMat( 1, m, CV_32FC1 ) ); for( i = 0; i < m; i++ ) @@ -3618,7 +3618,7 @@ void cvReadTrainData( const char* filename, int flags, fclose( file ); __END__; - + } CV_BOOST_IMPL @@ -3665,7 +3665,7 @@ void cvWriteTrainData( const char* filename, int flags, { CV_ERROR( CV_StsUnmatchedSizes, "Incorrect trainData and trainClasses sizes" ); } - + if( sampleIdx != NULL ) { count = (sampleIdx->rows == 1) ? sampleIdx->cols : sampleIdx->rows; @@ -3674,7 +3674,7 @@ void cvWriteTrainData( const char* filename, int flags, { count = m; } - + file = fopen( filename, "w" ); if( !file ) @@ -3705,7 +3705,7 @@ void cvWriteTrainData( const char* filename, int flags, for( j = 0; j < n; j++ ) { fprintf( file, "%g ", ( (CV_IS_ROW_SAMPLE( flags )) - ? CV_MAT_ELEM( *trainData, float, idx, j ) + ? CV_MAT_ELEM( *trainData, float, idx, j ) : CV_MAT_ELEM( *trainData, float, j, idx ) ) ); } fprintf( file, "%g\n", ( (clsrow) @@ -3714,13 +3714,13 @@ void cvWriteTrainData( const char* filename, int flags, } fclose( file ); - + __END__; } #define ICV_RAND_SHUFFLE( suffix, type ) \ -void icvRandShuffle_##suffix( uchar* data, size_t step, int num ) \ +static void icvRandShuffle_##suffix( uchar* data, size_t step, int num ) \ { \ time_t seed; \ type tmp; \ diff --git a/apps/haartraining/cvhaarclassifier.cpp b/apps/haartraining/cvhaarclassifier.cpp index 458712b..af69bf1 100644 --- a/apps/haartraining/cvhaarclassifier.cpp +++ b/apps/haartraining/cvhaarclassifier.cpp @@ -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; diff --git a/apps/haartraining/cvhaartraining.cpp b/apps/haartraining/cvhaartraining.cpp index dc9f3ac..253ffe6 100644 --- a/apps/haartraining/cvhaartraining.cpp +++ b/apps/haartraining/cvhaartraining.cpp @@ -108,7 +108,7 @@ CvBackgroundData* cvbgdata = NULL; /* - * get sum image offsets for corner points + * get sum image offsets for 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 corner points + * get tilted image offsets for 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(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 ); diff --git a/apps/haartraining/cvsamples.cpp b/apps/haartraining/cvsamples.cpp index 2702384..3b4c872 100644 --- a/apps/haartraining/cvsamples.cpp +++ b/apps/haartraining/cvsamples.cpp @@ -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" ); diff --git a/apps/haartraining/performance.cpp b/apps/haartraining/performance.cpp index c14e41c..2341f3a 100644 --- a/apps/haartraining/performance.cpp +++ b/apps/haartraining/performance.cpp @@ -44,6 +44,9 @@ * * Measure performance of classifier */ +#include "opencv2/core/core.hpp" +#include "opencv2/core/internal.hpp" + #include "cv.h" #include "highgui.h" diff --git a/apps/traincascade/HOGfeatures.cpp b/apps/traincascade/HOGfeatures.cpp index 68c1943..69f5b4a 100644 --- a/apps/traincascade/HOGfeatures.cpp +++ b/apps/traincascade/HOGfeatures.cpp @@ -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 &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++ ) diff --git a/apps/traincascade/boost.cpp b/apps/traincascade/boost.cpp index f05f458..18165fd 100644 --- a/apps/traincascade/boost.cpp +++ b/apps/traincascade/boost.cpp @@ -1,3 +1,6 @@ +#include "opencv2/core/core.hpp" +#include "opencv2/core/internal.hpp" + #include "boost.h" #include "cascadeclassifier.h" #include @@ -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( vi, si ); - return (*featureEvaluator)( vi, si ); + return valCache.at( 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 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 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 ); diff --git a/apps/traincascade/cascadeclassifier.cpp b/apps/traincascade/cascadeclassifier.cpp index 3433d74..ef6d181 100644 --- a/apps/traincascade/cascadeclassifier.cpp +++ b/apps/traincascade/cascadeclassifier.cpp @@ -1,3 +1,6 @@ +#include "opencv2/core/core.hpp" +#include "opencv2/core/internal.hpp" + #include "cascadeclassifier.h" #include @@ -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 << "" << 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)featureEvaluator))->writeFeatures( fs, featureMap ); + ((CvFeatureEvaluator*)((Ptr)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 >::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 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 >::const_iterator it = stageClassifiers.begin(); it != stageClassifiers.end(); it++ ) ((CvCascadeBoost*)((Ptr)(*it)))->markUsedFeaturesInMap( featureMap ); - + for( int fi = 0, idx = 0; fi < varCount; fi++ ) if ( featureMap.at(0, fi) >= 0 ) featureMap.ptr(0)[fi] = idx++; diff --git a/apps/traincascade/features.cpp b/apps/traincascade/features.cpp index c117a99..8ecdfcc 100644 --- a/apps/traincascade/features.cpp +++ b/apps/traincascade/features.cpp @@ -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::create( int featureType ) { return featureType == HAAR ? Ptr(new CvHaarFeatureParams) : - featureType == LBP ? Ptr(new CvLBPFeatureParams) : + featureType == LBP ? Ptr(new CvLBPFeatureParams) : featureType == HOG ? Ptr(new CvHOGFeatureParams) : Ptr(); } @@ -84,7 +87,7 @@ void CvFeatureEvaluator::setImage(const Mat &img, uchar clsLabel, int idx) Ptr CvFeatureEvaluator::create(int type) { return type == CvFeatureParams::HAAR ? Ptr(new CvHaarEvaluator) : - type == CvFeatureParams::LBP ? Ptr(new CvLBPEvaluator) : + type == CvFeatureParams::LBP ? Ptr(new CvLBPEvaluator) : type == CvFeatureParams::HOG ? Ptr(new CvHOGEvaluator) : Ptr(); } diff --git a/apps/traincascade/haarfeatures.cpp b/apps/traincascade/haarfeatures.cpp index 6344af5..0298b42 100644 --- a/apps/traincascade/haarfeatures.cpp +++ b/apps/traincascade/haarfeatures.cpp @@ -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; diff --git a/apps/traincascade/imagestorage.cpp b/apps/traincascade/imagestorage.cpp index 64089c6..3830a4b 100644 --- a/apps/traincascade/imagestorage.cpp +++ b/apps/traincascade/imagestorage.cpp @@ -1,3 +1,6 @@ +#include "opencv2/core/core.hpp" +#include "opencv2/core/internal.hpp" + #include "cv.h" #include "imagestorage.h" #include @@ -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 || diff --git a/apps/traincascade/lbpfeatures.cpp b/apps/traincascade/lbpfeatures.cpp index ac1d23c..cf9bb7b 100644 --- a/apps/traincascade/lbpfeatures.cpp +++ b/apps/traincascade/lbpfeatures.cpp @@ -1,3 +1,6 @@ +#include "opencv2/core/core.hpp" +#include "opencv2/core/internal.hpp" + #include "lbpfeatures.h" #include "cascadeclassifier.h" diff --git a/apps/traincascade/traincascade.cpp b/apps/traincascade/traincascade.cpp index 07dbe3e..5a969f4 100644 --- a/apps/traincascade/traincascade.cpp +++ b/apps/traincascade/traincascade.cpp @@ -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 featureParams[] = { Ptr(new CvHaarFeatureParams), - Ptr(new CvLBPFeatureParams), + Ptr(new CvLBPFeatureParams), Ptr(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, diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index e00128a..3a45b6d 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -47,6 +47,9 @@ if(CMAKE_COMPILER_IS_GNUCXX) # High level of warnings. set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall") + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Werror=format-security") + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wmissing-declarations -Wcast-align -Wundef -Winit-self -Wpointer-arith") #-Wstrict-aliasing=2 + # The -Wno-long-long is required in 64bit systems when including sytem headers. if(X86_64) set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wno-long-long") @@ -171,18 +174,18 @@ if(MSVC) set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE2") endif() endif() - + if(ENABLE_SSE3) set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE3") endif() if(ENABLE_SSE4_1) set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE4.1") endif() - + if(ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1) set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Oi") endif() - + if(X86 OR X86_64) if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND ENABLE_SSE2) set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /fp:fast")# !! important - be on the same wave with x64 compilers @@ -217,6 +220,10 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}") +if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes -Wstrict-prototypes") +endif() + if(MSVC) # avoid warnings from MSVC about overriding the /W* option # we replace /W3 with /W4 only for C++ files, @@ -225,12 +232,12 @@ if(MSVC) string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - + # allow extern "C" functions throw exceptions foreach(flags CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) string(REPLACE "/EHsc-" "/EHs" ${flags} "${${flags}}") string(REPLACE "/EHsc" "/EHs" ${flags} "${${flags}}") - + string(REPLACE "/Zm1000" "" ${flags} "${${flags}}") endforeach() diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake index 7e7ef15..c22a44a 100644 --- a/cmake/OpenCVPCHSupport.cmake +++ b/cmake/OpenCVPCHSupport.cmake @@ -72,6 +72,7 @@ MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp) ADD_CUSTOM_COMMAND( OUTPUT "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo "#include \\\"${_include_file}\\\"" > "${${_dephelp}}" + COMMAND ${CMAKE_COMMAND} -E echo "int testfunction();" >> "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo "int testfunction()" >> "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo " return 0;" >> "${${_dephelp}}" @@ -82,6 +83,7 @@ MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp) ADD_CUSTOM_COMMAND( OUTPUT "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${_include_file}\\\"" > "${${_dephelp}}" + COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)\\;" >> "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)" >> "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}" COMMAND ${CMAKE_COMMAND} -E echo " \\return 0\\;" >> "${${_dephelp}}" diff --git a/modules/calib3d/perf/perf_precomp.hpp b/modules/calib3d/perf/perf_precomp.hpp index ccadd24..1616273 100644 --- a/modules/calib3d/perf/perf_precomp.hpp +++ b/modules/calib3d/perf/perf_precomp.hpp @@ -6,7 +6,7 @@ #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/calib3d/src/checkchessboard.cpp b/modules/calib3d/src/checkchessboard.cpp index 61e44a7..60e275d 100644 --- a/modules/calib3d/src/checkchessboard.cpp +++ b/modules/calib3d/src/checkchessboard.cpp @@ -55,12 +55,12 @@ # endif #endif -void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector >& quads, int class_id) +static void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector >& quads, int class_id) { const float min_aspect_ratio = 0.3f; const float max_aspect_ratio = 3.0f; const float min_box_size = 10.0f; - + for(CvSeq* seq = contours; seq != NULL; seq = seq->h_next) { CvBox2D box = cvMinAreaRect2(seq); @@ -75,12 +75,12 @@ void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector(box_size, class_id)); } } -void countClasses(const std::vector >& pairs, size_t idx1, size_t idx2, std::vector& counts) +static void countClasses(const std::vector >& pairs, size_t idx1, size_t idx2, std::vector& counts) { counts.assign(2, 0); for(size_t i = idx1; i != idx2; i++) @@ -89,36 +89,36 @@ void countClasses(const std::vector >& pairs, size_t idx1, } } -bool less_pred(const std::pair& p1, const std::pair& p2) +inline bool less_pred(const std::pair& p1, const std::pair& p2) { return p1.first < p2.first; } -// does a fast check if a chessboard is in the input image. This is a workaround to +// does a fast check if a chessboard is in the input image. This is a workaround to // a problem of cvFindChessboardCorners being slow on images with no chessboard // - src: input image // - size: chessboard size -// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, +// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, // 0 if there is no chessboard, -1 in case of error int cvCheckChessboard(IplImage* src, CvSize size) { if(src->nChannels > 1) { - cvError(CV_BadNumChannels, "cvCheckChessboard", "supports single-channel images only", + cvError(CV_BadNumChannels, "cvCheckChessboard", "supports single-channel images only", __FILE__, __LINE__); } - + if(src->depth != 8) { - cvError(CV_BadDepth, "cvCheckChessboard", "supports depth=8 images only", + cvError(CV_BadDepth, "cvCheckChessboard", "supports depth=8 images only", __FILE__, __LINE__); } - + const int erosion_count = 1; const float black_level = 20.f; const float white_level = 130.f; const float black_white_gap = 70.f; - + #if defined(DEBUG_WINDOWS) cvNamedWindow("1", 1); cvShowImage("1", src); @@ -126,46 +126,46 @@ int cvCheckChessboard(IplImage* src, CvSize size) #endif //DEBUG_WINDOWS CvMemStorage* storage = cvCreateMemStorage(); - + IplImage* white = cvCloneImage(src); IplImage* black = cvCloneImage(src); - + cvErode(white, white, NULL, erosion_count); cvDilate(black, black, NULL, erosion_count); IplImage* thresh = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1); - + int result = 0; for(float thresh_level = black_level; thresh_level < white_level && !result; thresh_level += 20.0f) { cvThreshold(white, thresh, thresh_level + black_white_gap, 255, CV_THRESH_BINARY); - + #if defined(DEBUG_WINDOWS) cvShowImage("1", thresh); cvWaitKey(0); #endif //DEBUG_WINDOWS - + CvSeq* first = 0; std::vector > quads; - cvFindContours(thresh, storage, &first, sizeof(CvContour), CV_RETR_CCOMP); + cvFindContours(thresh, storage, &first, sizeof(CvContour), CV_RETR_CCOMP); icvGetQuadrangleHypotheses(first, quads, 1); - + cvThreshold(black, thresh, thresh_level, 255, CV_THRESH_BINARY_INV); - + #if defined(DEBUG_WINDOWS) cvShowImage("1", thresh); cvWaitKey(0); #endif //DEBUG_WINDOWS - + cvFindContours(thresh, storage, &first, sizeof(CvContour), CV_RETR_CCOMP); icvGetQuadrangleHypotheses(first, quads, 0); - + const size_t min_quads_count = size.width*size.height/2; std::sort(quads.begin(), quads.end(), less_pred); - + // now check if there are many hypotheses with similar sizes // do this by floodfill-style algorithm const float size_rel_dev = 0.4f; - + for(size_t i = 0; i < quads.size(); i++) { size_t j = i + 1; @@ -176,7 +176,7 @@ int cvCheckChessboard(IplImage* src, CvSize size) break; } } - + if(j + 1 > min_quads_count + i) { // check the number of black and white squares @@ -194,12 +194,12 @@ int cvCheckChessboard(IplImage* src, CvSize size) } } } - - + + cvReleaseImage(&thresh); cvReleaseImage(&white); cvReleaseImage(&black); cvReleaseMemStorage(&storage); - + return result; } diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index 870a657..f729919 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -1223,7 +1223,7 @@ void computePredecessorMatrix(const Mat &dm, int verticesCount, Mat &predecessor } } -void computeShortestPath(Mat &predecessorMatrix, size_t v1, size_t v2, vector &path) +static void computeShortestPath(Mat &predecessorMatrix, size_t v1, size_t v2, vector &path) { if (predecessorMatrix.at ((int)v1, (int)v2) < 0) { @@ -1403,7 +1403,7 @@ void CirclesGridFinder::getHoles(vector &outHoles) const } } -bool areIndicesCorrect(Point pos, vector > *points) +static bool areIndicesCorrect(Point pos, vector > *points) { if (pos.y < 0 || pos.x < 0) return false; diff --git a/modules/calib3d/src/precomp.hpp b/modules/calib3d/src/precomp.hpp index 50b4d40..14bcfa3 100644 --- a/modules/calib3d/src/precomp.hpp +++ b/modules/calib3d/src/precomp.hpp @@ -42,11 +42,11 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4710 4711 4514 4996 ) #endif -#ifdef HAVE_CVCONFIG_H +#ifdef HAVE_CVCONFIG_H #include "cvconfig.h" #endif diff --git a/modules/calib3d/src/quadsubpix.cpp b/modules/calib3d/src/quadsubpix.cpp index 35257fb..2aec9d6 100644 --- a/modules/calib3d/src/quadsubpix.cpp +++ b/modules/calib3d/src/quadsubpix.cpp @@ -52,41 +52,41 @@ #undef max namespace cv { - - -void drawCircles(Mat& img, const vector& corners, const vector& radius) -{ - for(size_t i = 0; i < corners.size(); i++) - { - circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0)); - } -} - -int histQuantile(const Mat& hist, float quantile) -{ - if(hist.dims > 1) return -1; // works for 1D histograms only - - float cur_sum = 0; - float total_sum = (float)sum(hist).val[0]; - float quantile_sum = total_sum*quantile; - for(int j = 0; j < hist.size[0]; j++) - { - cur_sum += (float)hist.at(j); - if(cur_sum > quantile_sum) - { - return j; - } - } - - return hist.size[0] - 1; -} - -bool is_smaller(const std::pair& p1, const std::pair& p2) + + +// static void drawCircles(Mat& img, const vector& corners, const vector& radius) +// { +// for(size_t i = 0; i < corners.size(); i++) +// { +// circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0)); +// } +// } + +// static int histQuantile(const Mat& hist, float quantile) +// { +// if(hist.dims > 1) return -1; // works for 1D histograms only + +// float cur_sum = 0; +// float total_sum = (float)sum(hist).val[0]; +// float quantile_sum = total_sum*quantile; +// for(int j = 0; j < hist.size[0]; j++) +// { +// cur_sum += (float)hist.at(j); +// if(cur_sum > quantile_sum) +// { +// return j; +// } +// } + +// return hist.size[0] - 1; +// } + +inline bool is_smaller(const std::pair& p1, const std::pair& p2) { return p1.second < p2.second; } -void orderContours(const vector >& contours, Point2f point, vector >& order) +static void orderContours(const vector >& contours, Point2f point, vector >& order) { order.clear(); size_t i, j, n = contours.size(); @@ -101,58 +101,58 @@ void orderContours(const vector >& contours, Point2f point, vector } order.push_back(std::pair((int)i, (float)min_dist)); } - + std::sort(order.begin(), order.end(), is_smaller); } // fit second order curve to a set of 2D points -void fitCurve2Order(const vector& /*points*/, vector& /*curve*/) +inline void fitCurve2Order(const vector& /*points*/, vector& /*curve*/) { // TBD } - -void findCurvesCross(const vector& /*curve1*/, const vector& /*curve2*/, Point2f& /*cross_point*/) + +inline void findCurvesCross(const vector& /*curve1*/, const vector& /*curve2*/, Point2f& /*cross_point*/) { } - -void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f dir2, Point2f& cross_point) + +static void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f dir2, Point2f& cross_point) { float det = dir2.x*dir1.y - dir2.y*dir1.x; Point2f offset = origin2 - origin1; - + float alpha = (dir2.x*offset.y - dir2.y*offset.x)/det; cross_point = origin1 + dir1*alpha; } - -void findCorner(const vector& contour, Point2f point, Point2f& corner) -{ - // find the nearest point - double min_dist = std::numeric_limits::max(); - int min_idx = -1; - - // find corner idx - for(size_t i = 0; i < contour.size(); i++) - { - double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point); - if(dist < min_dist) - { - min_dist = dist; - min_idx = (int)i; - } - } - assert(min_idx >= 0); - - // temporary solution, have to make something more precise - corner = contour[min_idx]; - return; -} -void findCorner(const vector& contour, Point2f point, Point2f& corner) +// static void findCorner(const vector& contour, Point2f point, Point2f& corner) +// { +// // find the nearest point +// double min_dist = std::numeric_limits::max(); +// int min_idx = -1; + +// // find corner idx +// for(size_t i = 0; i < contour.size(); i++) +// { +// double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point); +// if(dist < min_dist) +// { +// min_dist = dist; +// min_idx = (int)i; +// } +// } +// assert(min_idx >= 0); + +// // temporary solution, have to make something more precise +// corner = contour[min_idx]; +// return; +// } + +static void findCorner(const vector& contour, Point2f point, Point2f& corner) { // find the nearest point double min_dist = std::numeric_limits::max(); int min_idx = -1; - + // find corner idx for(size_t i = 0; i < contour.size(); i++) { @@ -164,23 +164,23 @@ void findCorner(const vector& contour, Point2f point, Point2f& corner) } } assert(min_idx >= 0); - + // temporary solution, have to make something more precise corner = contour[min_idx]; return; } - -int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh) + +static int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh) { Mat bw; //const double max_bell_width = 20; // we expect two bells with width bounded above //const double min_bell_width = 5; // and below - + double total_sum = sum(hist).val[0]; //double thresh = total_sum/(2*max_bell_width)*0.25f; // quarter of a bar inside a bell - + // threshold(hist, bw, thresh, 255.0, CV_THRESH_BINARY); - + double quantile_sum = 0.0; //double min_quantile = 0.2; double low_sum = 0; @@ -193,7 +193,7 @@ int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh) { quantile_sum += hist.at(x); if(quantile_sum < 0.2*total_sum) continue; - + if(quantile_sum - low_sum > out_of_bells_fraction*total_sum) { if(max_segment_length < x - start_x) @@ -207,7 +207,7 @@ int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh) start_x = x; } } - + if(start_x == -1) { return 0; @@ -219,9 +219,9 @@ int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh) return 1; } } - + } - + bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size region_size) { Mat img = _img.getMat(), cornersM = _corners.getMat(); @@ -232,22 +232,22 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size float ranges[] = {0, 256}; const float* _ranges = ranges; Mat hist; - + #if defined(_SUBPIX_VERBOSE) vector radius; radius.assign(corners.size(), 0.0f); #endif //_SUBPIX_VERBOSE - - + + Mat black_comp, white_comp; for(int i = 0; i < ncorners; i++) - { + { int channels = 0; Rect roi(cvRound(corners[i].x - region_size.width), cvRound(corners[i].y - region_size.height), region_size.width*2 + 1, region_size.height*2 + 1); Mat img_roi = img(roi); calcHist(&img_roi, 1, &channels, Mat(), hist, 1, &nbins, &_ranges); - + #if 0 int black_thresh = histQuantile(hist, 0.45f); int white_thresh = histQuantile(hist, 0.55f); @@ -255,10 +255,10 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size int black_thresh, white_thresh; segment_hist_max(hist, black_thresh, white_thresh); #endif - + threshold(img, black_comp, black_thresh, 255.0, CV_THRESH_BINARY_INV); threshold(img, white_comp, white_thresh, 255.0, CV_THRESH_BINARY); - + const int erode_count = 1; erode(black_comp, black_comp, Mat(), Point(-1, -1), erode_count); erode(white_comp, white_comp, Mat(), Point(-1, -1), erode_count); @@ -275,28 +275,28 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size imwrite("black.jpg", black_comp); imwrite("white.jpg", white_comp); #endif - - + + vector > white_contours, black_contours; vector white_hierarchy, black_hierarchy; findContours(black_comp, black_contours, black_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); findContours(white_comp, white_contours, white_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); - + if(black_contours.size() < 5 || white_contours.size() < 5) continue; - + // find two white and black blobs that are close to the input point vector > white_order, black_order; orderContours(black_contours, corners[i], black_order); orderContours(white_contours, corners[i], white_order); const float max_dist = 10.0f; - if(black_order[0].second > max_dist || black_order[1].second > max_dist || + if(black_order[0].second > max_dist || black_order[1].second > max_dist || white_order[0].second > max_dist || white_order[1].second > max_dist) { continue; // there will be no improvement in this corner position } - - const vector* quads[4] = {&black_contours[black_order[0].first], &black_contours[black_order[1].first], + + const vector* quads[4] = {&black_contours[black_order[0].first], &black_contours[black_order[1].first], &white_contours[white_order[0].first], &white_contours[white_order[1].first]}; vector quads_approx[4]; Point2f quad_corners[4]; @@ -306,14 +306,14 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size vector temp; for(size_t j = 0; j < quads[k]->size(); j++) temp.push_back((*quads[k])[j]); approxPolyDP(Mat(temp), quads_approx[k], 0.5, true); - + findCorner(quads_approx[k], corners[i], quad_corners[k]); #else findCorner(*quads[k], corners[i], quad_corners[k]); #endif quad_corners[k] += Point2f(0.5f, 0.5f); } - + // cross two lines Point2f origin1 = quad_corners[0]; Point2f dir1 = quad_corners[1] - quad_corners[0]; @@ -321,12 +321,12 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size Point2f dir2 = quad_corners[3] - quad_corners[2]; double angle = acos(dir1.dot(dir2)/(norm(dir1)*norm(dir2))); if(cvIsNaN(angle) || cvIsInf(angle) || angle < 0.5 || angle > CV_PI - 0.5) continue; - + findLinesCrossPoint(origin1, dir1, origin2, dir2, corners[i]); - + #if defined(_SUBPIX_VERBOSE) radius[i] = norm(corners[i] - ground_truth_corners[ground_truth_idx])*6; - + #if 1 Mat test(img.size(), CV_32FC3); cvtColor(img, test, CV_GRAY2RGB); @@ -349,9 +349,9 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size waitKey(0); #endif #endif //_SUBPIX_VERBOSE - + } - + #if defined(_SUBPIX_VERBOSE) Mat test(img.size(), CV_32FC3); cvtColor(img, test, CV_GRAY2RGB); @@ -361,6 +361,6 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size imshow("corners", test); waitKey(); #endif //_SUBPIX_VERBOSE - + return true; } diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index 9d0f621..4465339 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -52,48 +52,48 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints, { Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat(); int npoints = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F)); - CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) ); + CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) ); _rvec.create(3, 1, CV_64F); _tvec.create(3, 1, CV_64F); Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat(); if (flags == CV_EPNP) { - cv::Mat undistortedPoints; - cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs); - epnp PnP(cameraMatrix, opoints, undistortedPoints); - + cv::Mat undistortedPoints; + cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs); + epnp PnP(cameraMatrix, opoints, undistortedPoints); + cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat(); PnP.compute_pose(R, tvec); cv::Rodrigues(R, rvec); - return true; - } - else if (flags == CV_P3P) - { - CV_Assert( npoints == 4); - cv::Mat undistortedPoints; - cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs); - p3p P3Psolver(cameraMatrix); + return true; + } + else if (flags == CV_P3P) + { + CV_Assert( npoints == 4); + cv::Mat undistortedPoints; + cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs); + p3p P3Psolver(cameraMatrix); cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat(); bool result = P3Psolver.solve(R, tvec, opoints, undistortedPoints); if (result) - cv::Rodrigues(R, rvec); - return result; - } - else if (flags == CV_ITERATIVE) - { - CvMat c_objectPoints = opoints, c_imagePoints = ipoints; - CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs; - CvMat c_rvec = _rvec.getMat(), c_tvec = _tvec.getMat(); - cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix, - c_distCoeffs.rows*c_distCoeffs.cols ? &c_distCoeffs : 0, - &c_rvec, &c_tvec, useExtrinsicGuess ); - return true; - } - else + cv::Rodrigues(R, rvec); + return result; + } + else if (flags == CV_ITERATIVE) + { + CvMat c_objectPoints = opoints, c_imagePoints = ipoints; + CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs; + CvMat c_rvec = _rvec.getMat(), c_tvec = _tvec.getMat(); + cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix, + c_distCoeffs.rows*c_distCoeffs.cols ? &c_distCoeffs : 0, + &c_rvec, &c_tvec, useExtrinsicGuess ); + return true; + } + else CV_Error(CV_StsBadArg, "The flags argument must be one of CV_ITERATIVE or CV_EPNP"); - return false; + return false; } namespace cv @@ -101,8 +101,8 @@ namespace cv namespace pnpransac { const int MIN_POINTS_COUNT = 4; - - void project3dPoints(const Mat& points, const Mat& rvec, const Mat& tvec, Mat& modif_points) + + static void project3dPoints(const Mat& points, const Mat& rvec, const Mat& tvec, Mat& modif_points) { modif_points.create(1, points.cols, CV_32FC3); Mat R(3, 3, CV_64FC1); @@ -114,32 +114,32 @@ namespace cv tvec.copyTo(t); transform(points, modif_points, transformation); } - + class Mutex { public: Mutex() { - } + } void lock() { #ifdef HAVE_TBB - resultsMutex.lock(); + resultsMutex.lock(); #endif } - + void unlock() { #ifdef HAVE_TBB resultsMutex.unlock(); #endif } - + private: #ifdef HAVE_TBB tbb::mutex resultsMutex; #endif }; - + struct CameraParameters { void init(Mat _intrinsics, Mat _distCoeffs) @@ -147,22 +147,22 @@ namespace cv _intrinsics.copyTo(intrinsics); _distCoeffs.copyTo(distortion); } - + Mat intrinsics; Mat distortion; }; - + struct Parameters { int iterationsCount; float reprojectionError; int minInliersCount; bool useExtrinsicGuess; - int flags; + int flags; CameraParameters camera; }; - - void pnpTask(const vector& pointsMask, const Mat& objectPoints, const Mat& imagePoints, + + static void pnpTask(const vector& pointsMask, const Mat& objectPoints, const Mat& imagePoints, const Parameters& params, vector& inliers, Mat& rvec, Mat& tvec, const Mat& rvecInit, const Mat& tvecInit, Mutex& resultsMutex) { @@ -178,7 +178,7 @@ namespace cv colIndex = colIndex+1; } } - + //filter same 3d points, hang in solvePnP double eps = 1e-10; int num_same_points = 0; @@ -190,22 +190,22 @@ namespace cv } if (num_same_points > 0) return; - + Mat localRvec, localTvec; rvecInit.copyTo(localRvec); tvecInit.copyTo(localTvec); - - solvePnP(modelObjectPoints, modelImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, - params.useExtrinsicGuess, params.flags); - - + + solvePnP(modelObjectPoints, modelImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, + params.useExtrinsicGuess, params.flags); + + vector projected_points; projected_points.resize(objectPoints.cols); projectPoints(objectPoints, localRvec, localTvec, params.camera.intrinsics, params.camera.distortion, projected_points); - + Mat rotatedPoints; project3dPoints(objectPoints, localRvec, localTvec, rotatedPoints); - + vector localInliers; for (int i = 0; i < objectPoints.cols; i++) { @@ -216,21 +216,21 @@ namespace cv localInliers.push_back(i); } } - + if (localInliers.size() > inliers.size()) { resultsMutex.lock(); - + inliers.clear(); inliers.resize(localInliers.size()); memcpy(&inliers[0], &localInliers[0], sizeof(int) * localInliers.size()); localRvec.copyTo(rvec); localTvec.copyTo(tvec); - + resultsMutex.unlock(); } } - + class PnPSolver { public: @@ -262,18 +262,18 @@ namespace cv tvec.copyTo(initTvec); } private: - PnPSolver& operator=(const PnPSolver&); - + PnPSolver& operator=(const PnPSolver&); + const Mat& objectPoints; const Mat& imagePoints; const Parameters& parameters; Mat &rvec, &tvec; vector& inliers; Mat initRvec, initTvec; - + static RNG generator; static Mutex syncMutex; - + void generateVar(vector& mask) const { int size = (int)mask.size(); @@ -287,10 +287,10 @@ namespace cv } } }; - + Mutex PnPSolver::syncMutex; RNG PnPSolver::generator; - + } } @@ -302,21 +302,21 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints, { Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat(); Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat(); - + CV_Assert(opoints.isContinuous()); CV_Assert(opoints.depth() == CV_32F); CV_Assert((opoints.rows == 1 && opoints.channels() == 3) || opoints.cols*opoints.channels() == 3); CV_Assert(ipoints.isContinuous()); CV_Assert(ipoints.depth() == CV_32F); CV_Assert((ipoints.rows == 1 && ipoints.channels() == 2) || ipoints.cols*ipoints.channels() == 2); - + _rvec.create(3, 1, CV_64FC1); _tvec.create(3, 1, CV_64FC1); Mat rvec = _rvec.getMat(); Mat tvec = _tvec.getMat(); - + Mat objectPoints = opoints.reshape(3, 1), imagePoints = ipoints.reshape(2, 1); - + if (minInliersCount <= 0) minInliersCount = objectPoints.cols; cv::pnpransac::Parameters params; @@ -325,36 +325,36 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints, params.reprojectionError = reprojectionError; params.useExtrinsicGuess = useExtrinsicGuess; params.camera.init(cameraMatrix, distCoeffs); - params.flags = flags; - + params.flags = flags; + vector localInliers; Mat localRvec, localTvec; rvec.copyTo(localRvec); tvec.copyTo(localTvec); - + if (objectPoints.cols >= pnpransac::MIN_POINTS_COUNT) { parallel_for(BlockedRange(0,iterationsCount), cv::pnpransac::PnPSolver(objectPoints, imagePoints, params, localRvec, localTvec, localInliers)); } - + if (localInliers.size() >= (size_t)pnpransac::MIN_POINTS_COUNT) { - if (flags != CV_P3P) - { - int i, pointsCount = (int)localInliers.size(); - Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2); - for (i = 0; i < pointsCount; i++) - { - int index = localInliers[i]; - Mat colInlierImagePoints = inlierImagePoints(Rect(i, 0, 1, 1)); - imagePoints.col(index).copyTo(colInlierImagePoints); - Mat colInlierObjectPoints = inlierObjectPoints(Rect(i, 0, 1, 1)); - objectPoints.col(index).copyTo(colInlierObjectPoints); - } - solvePnP(inlierObjectPoints, inlierImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, true, flags); - } - localRvec.copyTo(rvec); + if (flags != CV_P3P) + { + int i, pointsCount = (int)localInliers.size(); + Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2); + for (i = 0; i < pointsCount; i++) + { + int index = localInliers[i]; + Mat colInlierImagePoints = inlierImagePoints(Rect(i, 0, 1, 1)); + imagePoints.col(index).copyTo(colInlierImagePoints); + Mat colInlierObjectPoints = inlierObjectPoints(Rect(i, 0, 1, 1)); + objectPoints.col(index).copyTo(colInlierObjectPoints); + } + solvePnP(inlierObjectPoints, inlierImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, true, flags); + } + localRvec.copyTo(rvec); localTvec.copyTo(tvec); if (_inliers.needed()) Mat(localInliers).copyTo(_inliers); diff --git a/modules/contrib/src/ba.cpp b/modules/contrib/src/ba.cpp index 636ba59..f08bdda 100644 --- a/modules/contrib/src/ba.cpp +++ b/modules/contrib/src/ba.cpp @@ -55,36 +55,36 @@ LevMarqSparse::LevMarqSparse() { LevMarqSparse::~LevMarqSparse() { clear(); -} +} LevMarqSparse::LevMarqSparse(int npoints, // number of points - int ncameras, // number of cameras - int nPointParams, // number of params per one point (3 in case of 3D points) - int nCameraParams, // number of parameters per one camera - int nErrParams, // number of parameters in measurement vector - // for 1 point at one camera (2 in case of 2D projections) - Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras - // 1 - point is visible for the camera, 0 - invisible - Mat& P0, // starting vector of parameters, first cameras then points - Mat& X_, // measurements, in order of visibility. non visible cases are skipped - TermCriteria criteria, // termination criteria - - // callback for estimation of Jacobian matrices - void (CV_CDECL * fjac)(int i, int j, Mat& point_params, - Mat& cam_params, Mat& A, Mat& B, void* data), - // callback for estimation of backprojection errors - void (CV_CDECL * func)(int i, int j, Mat& point_params, - Mat& cam_params, Mat& estim, void* data), - void* data, // user-specific data passed to the callbacks - BundleAdjustCallback _cb, void* _user_data - ) { + int ncameras, // number of cameras + int nPointParams, // number of params per one point (3 in case of 3D points) + int nCameraParams, // number of parameters per one camera + int nErrParams, // number of parameters in measurement vector + // for 1 point at one camera (2 in case of 2D projections) + Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras + // 1 - point is visible for the camera, 0 - invisible + Mat& P0, // starting vector of parameters, first cameras then points + Mat& X_, // measurements, in order of visibility. non visible cases are skipped + TermCriteria criteria, // termination criteria + + // callback for estimation of Jacobian matrices + void (CV_CDECL * fjac)(int i, int j, Mat& point_params, + Mat& cam_params, Mat& A, Mat& B, void* data), + // callback for estimation of backprojection errors + void (CV_CDECL * func)(int i, int j, Mat& point_params, + Mat& cam_params, Mat& estim, void* data), + void* data, // user-specific data passed to the callbacks + BundleAdjustCallback _cb, void* _user_data + ) { Vis_index = X = prevP = P = deltaP = err = JtJ_diag = S = hX = NULL; U = ea = V = inv_V_star = eb = Yj = NULL; A = B = W = NULL; cb = _cb; user_data = _user_data; - + run(npoints, ncameras, nPointParams, nCameraParams, nErrParams, visibility, P0, X_, criteria, fjac, func, data); } @@ -95,19 +95,19 @@ void LevMarqSparse::clear() { //CvMat* tmp = ((CvMat**)(A->data.ptr + i * A->step))[j]; CvMat* tmp = A[j+i*num_cams]; if (tmp) - cvReleaseMat( &tmp ); + cvReleaseMat( &tmp ); //tmp = ((CvMat**)(B->data.ptr + i * B->step))[j]; tmp = B[j+i*num_cams]; if (tmp) - cvReleaseMat( &tmp ); - + cvReleaseMat( &tmp ); + //tmp = ((CvMat**)(W->data.ptr + j * W->step))[i]; tmp = W[j+i*num_cams]; if (tmp) - cvReleaseMat( &tmp ); + cvReleaseMat( &tmp ); } - } + } delete A; //cvReleaseMat(&A); delete B;//cvReleaseMat(&B); delete W;//cvReleaseMat(&W); @@ -122,7 +122,7 @@ void LevMarqSparse::clear() { cvReleaseMat( &ea[j] ); } delete ea; - + //allocate V and inv_V_star for( int i = 0; i < num_points; i++ ) { cvReleaseMat(&V[i]); @@ -138,16 +138,16 @@ void LevMarqSparse::clear() { for( int i = 0; i < num_points; i++ ) { cvReleaseMat(&Yj[i]); - } + } delete Yj; - + cvReleaseMat(&X); cvReleaseMat(&prevP); cvReleaseMat(&P); cvReleaseMat(&deltaP); - cvReleaseMat(&err); - + cvReleaseMat(&err); + cvReleaseMat(&JtJ_diag); cvReleaseMat(&S); cvReleaseMat(&hX); @@ -165,28 +165,28 @@ void LevMarqSparse::clear() { //num_errors - number of measurements. void LevMarqSparse::run( int num_points_, //number of points - int num_cams_, //number of cameras - int num_point_param_, //number of params per one point (3 in case of 3D points) - int num_cam_param_, //number of parameters per one camera - int num_err_param_, //number of parameters in measurement vector for 1 point at one camera (2 in case of 2D projections) - Mat& visibility, //visibility matrix . rows correspond to points, columns correspond to cameras - // 0 - point is visible for the camera, 0 - invisible - Mat& P0, //starting vector of parameters, first cameras then points - Mat& X_init, //measurements, in order of visibility. non visible cases are skipped - TermCriteria criteria_init, - void (*fjac_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data), - void (*func_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data), - void* data_ - ) { //termination criteria + int num_cams_, //number of cameras + int num_point_param_, //number of params per one point (3 in case of 3D points) + int num_cam_param_, //number of parameters per one camera + int num_err_param_, //number of parameters in measurement vector for 1 point at one camera (2 in case of 2D projections) + Mat& visibility, //visibility matrix . rows correspond to points, columns correspond to cameras + // 0 - point is visible for the camera, 0 - invisible + Mat& P0, //starting vector of parameters, first cameras then points + Mat& X_init, //measurements, in order of visibility. non visible cases are skipped + TermCriteria criteria_init, + void (*fjac_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data), + void (*func_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data), + void* data_ + ) { //termination criteria //clear(); - + func = func_; //assign evaluation function fjac = fjac_; //assign jacobian data = data_; num_cams = num_cams_; num_points = num_points_; - num_err_param = num_err_param_; + num_err_param = num_err_param_; num_cam_param = num_cam_param_; num_point_param = num_point_param_; @@ -204,9 +204,9 @@ void LevMarqSparse::run( int num_points_, //number of points int Wij_width = Bij_width; //allocate memory for all Aij, Bij, U, V, W - + //allocate num_points*num_cams matrices A - + //Allocate matrix A whose elements are nointers to Aij //if Aij is zero (point i is not visible in camera j) then A(i,j) contains NULL //A = cvCreateMat( num_points, num_cams, CV_32S /*pointer is stored here*/ ); @@ -221,39 +221,39 @@ void LevMarqSparse::run( int num_points_, //number of points //cvSetZero( B ); //cvSetZero( W ); cvSet( Vis_index, cvScalar(-1) ); - + //fill matrices A and B based on visibility CvMat _vis = visibility; int index = 0; for (int i = 0; i < num_points; i++ ) { for (int j = 0; j < num_cams; j++ ) { if (((int*)(_vis.data.ptr+ i * _vis.step))[j] ) { - ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j] = index; - index += num_err_param; - - //create matrices Aij, Bij - CvMat* tmp = cvCreateMat(Aij_height, Aij_width, CV_64F ); - //((CvMat**)(A->data.ptr + i * A->step))[j] = tmp; - cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0)); - A[j+i*num_cams] = tmp; - - tmp = cvCreateMat( Bij_height, Bij_width, CV_64F ); - //((CvMat**)(B->data.ptr + i * B->step))[j] = tmp; - cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0)); - B[j+i*num_cams] = tmp; - - tmp = cvCreateMat( Wij_height, Wij_width, CV_64F ); - //((CvMat**)(W->data.ptr + j * W->step))[i] = tmp; //note indices i and j swapped - cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0)); - W[j+i*num_cams] = tmp; + ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j] = index; + index += num_err_param; + + //create matrices Aij, Bij + CvMat* tmp = cvCreateMat(Aij_height, Aij_width, CV_64F ); + //((CvMat**)(A->data.ptr + i * A->step))[j] = tmp; + cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0)); + A[j+i*num_cams] = tmp; + + tmp = cvCreateMat( Bij_height, Bij_width, CV_64F ); + //((CvMat**)(B->data.ptr + i * B->step))[j] = tmp; + cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0)); + B[j+i*num_cams] = tmp; + + tmp = cvCreateMat( Wij_height, Wij_width, CV_64F ); + //((CvMat**)(W->data.ptr + j * W->step))[i] = tmp; //note indices i and j swapped + cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0)); + W[j+i*num_cams] = tmp; } else{ - A[j+i*num_cams] = NULL; - B[j+i*num_cams] = NULL; - W[j+i*num_cams] = NULL; + A[j+i*num_cams] = NULL; + B[j+i*num_cams] = NULL; + W[j+i*num_cams] = NULL; } - } + } } - + //allocate U U = new CvMat* [num_cams]; for (int j = 0; j < num_cams; j++ ) { @@ -267,7 +267,7 @@ void LevMarqSparse::run( int num_points_, //number of points ea[j] = cvCreateMat( U_size, 1, CV_64F ); cvSetZero(ea[j]); } - + //allocate V and inv_V_star V = new CvMat* [num_points]; inv_V_star = new CvMat* [num_points]; @@ -277,36 +277,36 @@ void LevMarqSparse::run( int num_points_, //number of points cvSetZero(V[i]); cvSetZero(inv_V_star[i]); } - + //allocate eb eb = new CvMat* [num_points]; for (int i = 0; i < num_points; i++ ) { eb[i] = cvCreateMat( V_size, 1, CV_64F ); cvSetZero(eb[i]); - } - + } + //allocate Yj Yj = new CvMat* [num_points]; for (int i = 0; i < num_points; i++ ) { Yj[i] = cvCreateMat( Wij_height, Wij_width, CV_64F ); //Yij has the same size as Wij cvSetZero(Yj[i]); - } - + } + //allocate matrix S S = cvCreateMat( num_cams * num_cam_param, num_cams * num_cam_param, CV_64F); cvSetZero(S); JtJ_diag = cvCreateMat( num_cams * num_cam_param + num_points * num_point_param, 1, CV_64F ); cvSetZero(JtJ_diag); - + //set starting parameters - CvMat _tmp_ = CvMat(P0); - prevP = cvCloneMat( &_tmp_ ); + CvMat _tmp_ = CvMat(P0); + prevP = cvCloneMat( &_tmp_ ); P = cvCloneMat( &_tmp_ ); deltaP = cvCloneMat( &_tmp_ ); - + //set measurements _tmp_ = CvMat(X_init); - X = cvCloneMat( &_tmp_ ); + X = cvCloneMat( &_tmp_ ); //create vector for estimated measurements hX = cvCreateMat( X->rows, X->cols, CV_64F ); cvSetZero(hX); @@ -334,9 +334,9 @@ void LevMarqSparse::run( int num_points_, //number of points prevErrNorm = cvNorm( err, 0, CV_L2 ); // std::cerr<<"prevErrNorm = "<data.ptr + i * Vis_index->step))[j]); ind+=1; - } - } + } + } } } @@ -372,20 +372,20 @@ void LevMarqSparse::ask_for_proj(CvMat &/*_vis*/,bool once) { void LevMarqSparse::ask_for_projac(CvMat &/*_vis*/) //should be evaluated at point prevP { // compute jacobians Aij and Bij - for (int i = 0; i < num_points; i++ ) + for (int i = 0; i < num_points; i++ ) { CvMat point_mat; cvGetSubRect( prevP, &point_mat, cvRect( 0, num_cams * num_cam_param + num_point_param * i, 1, num_point_param )); //CvMat** A_line = (CvMat**)(A->data.ptr + A->step * i); //CvMat** B_line = (CvMat**)(B->data.ptr + B->step * i); - for( int j = 0; j < num_cams; j++ ) + for( int j = 0; j < num_cams; j++ ) { //CvMat* Aij = A_line[j]; //if( Aij ) //Aij is not zero CvMat* Aij = A[j+i*num_cams]; CvMat* Bij = B[j+i*num_cams]; - if(Aij) + if(Aij) { //CvMat** A_line = (CvMat**)(A->data.ptr + A->step * i); //CvMat** B_line = (CvMat**)(B->data.ptr + B->step * i); @@ -403,13 +403,13 @@ void LevMarqSparse::ask_for_projac(CvMat &/*_vis*/) //should be evaluated at p } } } -} +} void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimization bool done = false; - - CvMat* YWt = cvCreateMat( num_cam_param, num_cam_param, CV_64F ); //this matrix used to store Yij*Wik' - CvMat* E = cvCreateMat( S->height, 1 , CV_64F ); //this is right part of system with S + + CvMat* YWt = cvCreateMat( num_cam_param, num_cam_param, CV_64F ); //this matrix used to store Yij*Wik' + CvMat* E = cvCreateMat( S->height, 1 , CV_64F ); //this is right part of system with S cvSetZero(YWt); cvSetZero(E); @@ -419,26 +419,26 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati int invisible_count=0; //compute U_j and ea_j for (int j = 0; j < num_cams; j++ ) { - cvSetZero(U[j]); + cvSetZero(U[j]); cvSetZero(ea[j]); //summ by i (number of points) for (int i = 0; i < num_points; i++ ) { - //get Aij - //CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j]; - CvMat* Aij = A[j+i*num_cams]; - if (Aij ) { - //Uj+= AijT*Aij - cvGEMM( Aij, Aij, 1, U[j], 1, U[j], CV_GEMM_A_T ); - //ea_j += AijT * e_ij - CvMat eij; - - int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j]; - - cvGetSubRect( err, &eij, cvRect( 0, index, 1, Aij->height ) ); //width of transposed Aij - cvGEMM( Aij, &eij, 1, ea[j], 1, ea[j], CV_GEMM_A_T ); - } - else - invisible_count++; + //get Aij + //CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j]; + CvMat* Aij = A[j+i*num_cams]; + if (Aij ) { + //Uj+= AijT*Aij + cvGEMM( Aij, Aij, 1, U[j], 1, U[j], CV_GEMM_A_T ); + //ea_j += AijT * e_ij + CvMat eij; + + int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j]; + + cvGetSubRect( err, &eij, cvRect( 0, index, 1, Aij->height ) ); //width of transposed Aij + cvGEMM( Aij, &eij, 1, ea[j], 1, ea[j], CV_GEMM_A_T ); + } + else + invisible_count++; } } //U_j and ea_j computed for all j @@ -450,272 +450,272 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati cb(iters, prevErrNorm, user_data); //compute V_i and eb_i for (int i = 0; i < num_points; i++ ) { - cvSetZero(V[i]); + cvSetZero(V[i]); cvSetZero(eb[i]); - + //summ by i (number of points) for( int j = 0; j < num_cams; j++ ) { - //get Bij - //CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j]; - CvMat* Bij = B[j+i*num_cams]; - if (Bij ) { - //Vi+= BijT*Bij - cvGEMM( Bij, Bij, 1, V[i], 1, V[i], CV_GEMM_A_T ); - - //eb_i += BijT * e_ij - int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j]; - - CvMat eij; - cvGetSubRect( err, &eij, cvRect( 0, index, 1, Bij->height ) ); //width of transposed Bij - cvGEMM( Bij, &eij, 1, eb[i], 1, eb[i], CV_GEMM_A_T ); - } + //get Bij + //CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j]; + CvMat* Bij = B[j+i*num_cams]; + if (Bij ) { + //Vi+= BijT*Bij + cvGEMM( Bij, Bij, 1, V[i], 1, V[i], CV_GEMM_A_T ); + + //eb_i += BijT * e_ij + int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j]; + + CvMat eij; + cvGetSubRect( err, &eij, cvRect( 0, index, 1, Bij->height ) ); //width of transposed Bij + cvGEMM( Bij, &eij, 1, eb[i], 1, eb[i], CV_GEMM_A_T ); + } } } //V_i and eb_i computed for all i //compute W_ij for( int i = 0; i < num_points; i++ ) { for( int j = 0; j < num_cams; j++ ) { - //CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j]; - CvMat* Aij = A[j+i*num_cams]; - if( Aij ) { //visible - //CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j]; - CvMat* Bij = B[j+i*num_cams]; - //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; - CvMat* Wij = W[j+i*num_cams]; - - //multiply - cvGEMM( Aij, Bij, 1, NULL, 0, Wij, CV_GEMM_A_T ); - } + //CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j]; + CvMat* Aij = A[j+i*num_cams]; + if( Aij ) { //visible + //CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j]; + CvMat* Bij = B[j+i*num_cams]; + //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; + CvMat* Wij = W[j+i*num_cams]; + + //multiply + cvGEMM( Aij, Bij, 1, NULL, 0, Wij, CV_GEMM_A_T ); + } } } //Wij computed //backup diagonal of JtJ before we start augmenting it - { + { CvMat dia; CvMat subr; for( int j = 0; j < num_cams; j++ ) { - cvGetDiag(U[j], &dia); - cvGetSubRect(JtJ_diag, &subr, - cvRect(0, j*num_cam_param, 1, num_cam_param )); - cvCopy( &dia, &subr ); - } + cvGetDiag(U[j], &dia); + cvGetSubRect(JtJ_diag, &subr, + cvRect(0, j*num_cam_param, 1, num_cam_param )); + cvCopy( &dia, &subr ); + } for( int i = 0; i < num_points; i++ ) { - cvGetDiag(V[i], &dia); - cvGetSubRect(JtJ_diag, &subr, - cvRect(0, num_cams*num_cam_param + i * num_point_param, 1, num_point_param )); - cvCopy( &dia, &subr ); - } - } + cvGetDiag(V[i], &dia); + cvGetSubRect(JtJ_diag, &subr, + cvRect(0, num_cams*num_cam_param + i * num_point_param, 1, num_point_param )); + cvCopy( &dia, &subr ); + } + } if( iters == 0 ) { //initialize lambda. It is set to 1e-3 * average diagonal element in JtJ double average_diag = 0; for( int j = 0; j < num_cams; j++ ) { - average_diag += cvTrace( U[j] ).val[0]; + average_diag += cvTrace( U[j] ).val[0]; } for( int i = 0; i < num_points; i++ ) { - average_diag += cvTrace( V[i] ).val[0]; + average_diag += cvTrace( V[i] ).val[0]; } average_diag /= (num_cams*num_cam_param + num_points * num_point_param ); - - // lambda = 1e-3 * average_diag; - lambda = 1e-3 * average_diag; + + // lambda = 1e-3 * average_diag; + lambda = 1e-3 * average_diag; lambda = 0.245560; } - + //now we are going to find good step and make it for(;;) { //augmentation of diagonal for(int j = 0; j < num_cams; j++ ) { - CvMat diag; - cvGetDiag( U[j], &diag ); + CvMat diag; + cvGetDiag( U[j], &diag ); #if 1 - cvAddS( &diag, cvScalar( lambda ), &diag ); + cvAddS( &diag, cvScalar( lambda ), &diag ); #else - cvScale( &diag, &diag, 1 + lambda ); + cvScale( &diag, &diag, 1 + lambda ); #endif } for(int i = 0; i < num_points; i++ ) { - CvMat diag; - cvGetDiag( V[i], &diag ); + CvMat diag; + cvGetDiag( V[i], &diag ); #if 1 - cvAddS( &diag, cvScalar( lambda ), &diag ); + cvAddS( &diag, cvScalar( lambda ), &diag ); #else - cvScale( &diag, &diag, 1 + lambda ); + cvScale( &diag, &diag, 1 + lambda ); #endif - } + } bool error = false; //compute inv(V*) bool inverted_ok = true; for(int i = 0; i < num_points; i++ ) { - double det = cvInvert( V[i], inv_V_star[i] ); + double det = cvInvert( V[i], inv_V_star[i] ); - if( fabs(det) <= FLT_EPSILON ) { - inverted_ok = false; - std::cerr<<"V["<data.ptr + W->step * j))[i]; - CvMat* Wij = W[j+i*num_cams]; - if( Wij ) { - cvMatMul( Wij, inv_V_star[i], Yj[i] ); - } - } - - //compute Sjk for k>=j (because Sjk = Skj) - for( int k = j; k < num_cams; k++ ) { - cvSetZero( YWt ); - for( int i = 0; i < num_points; i++ ) { - //check that both Wij and Wik exist - // CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; - CvMat* Wij = W[j+i*num_cams]; - //CvMat* Wik = ((CvMat**)(W->data.ptr + W->step * k))[i]; - CvMat* Wik = W[k+i*num_cams]; - - if( Wij && Wik ) { - //multiply YWt += Yj[i]*Wik' - cvGEMM( Yj[i], Wik, 1, YWt, 1, YWt, CV_GEMM_B_T ); ///*transpose Wik - } - } - - //copy result to matrix S - - CvMat Sjk; - //extract submat - cvGetSubRect( S, &Sjk, cvRect( k * num_cam_param, j * num_cam_param, num_cam_param, num_cam_param )); - - - //if j==k, add diagonal - if( j != k ) { - //just copy with minus - cvScale( YWt, &Sjk, -1 ); //if we set initial S to zero then we can use cvSub( Sjk, YWt, Sjk); - } else { - //add diagonal value - - //subtract YWt from augmented Uj - cvSub( U[j], YWt, &Sjk ); - } - } - - //compute right part of equation involving matrix S - // e_j=ea_j - \sum_i Y_ij eb_i - { - CvMat e_j; - - //select submat - cvGetSubRect( E, &e_j, cvRect( 0, j * num_cam_param, 1, num_cam_param ) ); - - for( int i = 0; i < num_points; i++ ) { - //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; - CvMat* Wij = W[j+i*num_cams]; - if( Wij ) - cvMatMulAdd( Yj[i], eb[i], &e_j, &e_j ); - } - - cvSub( ea[j], &e_j, &e_j ); - } - - } - //fill below diagonal elements of matrix S - cvCompleteSymm( S, 0 ); ///*from upper to low //operation may be done by nonzero blocks or during upper diagonal computation - - //Solve linear system S * deltaP_a = E - CvMat dpa; - cvGetSubRect( deltaP, &dpa, cvRect(0, 0, 1, S->width ) ); - int res = cvSolve( S, E, &dpa, CV_CHOLESKY ); - - if( res ) { //system solved ok - //compute db_i - for( int i = 0; i < num_points; i++ ) { - CvMat dbi; - cvGetSubRect( deltaP, &dbi, cvRect( 0, dpa.height + i * num_point_param, 1, num_point_param ) ); - - // compute \sum_j W_ij^T da_j - for( int j = 0; j < num_cams; j++ ) { - //get Wij - //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; - CvMat* Wij = W[j+i*num_cams]; - if( Wij ) { - //get da_j - CvMat daj; - cvGetSubRect( &dpa, &daj, cvRect( 0, j * num_cam_param, 1, num_cam_param )); - cvGEMM( Wij, &daj, 1, &dbi, 1, &dbi, CV_GEMM_A_T ); ///* transpose Wij - } - } - //finalize dbi - cvSub( eb[i], &dbi, &dbi ); - cvMatMul(inv_V_star[i], &dbi, &dbi ); //here we get final dbi - } //now we computed whole deltaP - - //add deltaP to delta - cvAdd( prevP, deltaP, P ); - - //evaluate function with new parameters - ask_for_proj(_vis); // func( P, hX ); - - //compute error - errNorm = cvNorm( X, hX, CV_L2 ); - - } else { - error = true; - } + cvSetZero( E ); + //loop through cameras, compute upper diagonal blocks of matrix S + for( int j = 0; j < num_cams; j++ ) { + //compute Yij = Wij (V*_i)^-1 for all i (if Wij exists/nonzero) + for( int i = 0; i < num_points; i++ ) { + // + //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; + CvMat* Wij = W[j+i*num_cams]; + if( Wij ) { + cvMatMul( Wij, inv_V_star[i], Yj[i] ); + } + } + + //compute Sjk for k>=j (because Sjk = Skj) + for( int k = j; k < num_cams; k++ ) { + cvSetZero( YWt ); + for( int i = 0; i < num_points; i++ ) { + //check that both Wij and Wik exist + // CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; + CvMat* Wij = W[j+i*num_cams]; + //CvMat* Wik = ((CvMat**)(W->data.ptr + W->step * k))[i]; + CvMat* Wik = W[k+i*num_cams]; + + if( Wij && Wik ) { + //multiply YWt += Yj[i]*Wik' + cvGEMM( Yj[i], Wik, 1, YWt, 1, YWt, CV_GEMM_B_T ); ///*transpose Wik + } + } + + //copy result to matrix S + + CvMat Sjk; + //extract submat + cvGetSubRect( S, &Sjk, cvRect( k * num_cam_param, j * num_cam_param, num_cam_param, num_cam_param )); + + + //if j==k, add diagonal + if( j != k ) { + //just copy with minus + cvScale( YWt, &Sjk, -1 ); //if we set initial S to zero then we can use cvSub( Sjk, YWt, Sjk); + } else { + //add diagonal value + + //subtract YWt from augmented Uj + cvSub( U[j], YWt, &Sjk ); + } + } + + //compute right part of equation involving matrix S + // e_j=ea_j - \sum_i Y_ij eb_i + { + CvMat e_j; + + //select submat + cvGetSubRect( E, &e_j, cvRect( 0, j * num_cam_param, 1, num_cam_param ) ); + + for( int i = 0; i < num_points; i++ ) { + //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; + CvMat* Wij = W[j+i*num_cams]; + if( Wij ) + cvMatMulAdd( Yj[i], eb[i], &e_j, &e_j ); + } + + cvSub( ea[j], &e_j, &e_j ); + } + + } + //fill below diagonal elements of matrix S + cvCompleteSymm( S, 0 ); ///*from upper to low //operation may be done by nonzero blocks or during upper diagonal computation + + //Solve linear system S * deltaP_a = E + CvMat dpa; + cvGetSubRect( deltaP, &dpa, cvRect(0, 0, 1, S->width ) ); + int res = cvSolve( S, E, &dpa, CV_CHOLESKY ); + + if( res ) { //system solved ok + //compute db_i + for( int i = 0; i < num_points; i++ ) { + CvMat dbi; + cvGetSubRect( deltaP, &dbi, cvRect( 0, dpa.height + i * num_point_param, 1, num_point_param ) ); + + // compute \sum_j W_ij^T da_j + for( int j = 0; j < num_cams; j++ ) { + //get Wij + //CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i]; + CvMat* Wij = W[j+i*num_cams]; + if( Wij ) { + //get da_j + CvMat daj; + cvGetSubRect( &dpa, &daj, cvRect( 0, j * num_cam_param, 1, num_cam_param )); + cvGEMM( Wij, &daj, 1, &dbi, 1, &dbi, CV_GEMM_A_T ); ///* transpose Wij + } + } + //finalize dbi + cvSub( eb[i], &dbi, &dbi ); + cvMatMul(inv_V_star[i], &dbi, &dbi ); //here we get final dbi + } //now we computed whole deltaP + + //add deltaP to delta + cvAdd( prevP, deltaP, P ); + + //evaluate function with new parameters + ask_for_proj(_vis); // func( P, hX ); + + //compute error + errNorm = cvNorm( X, hX, CV_L2 ); + + } else { + error = true; + } } else { - error = true; + error = true; } //check solution if( error || ///* singularities somewhere - errNorm > prevErrNorm ) { //step was not accepted - //increase lambda and reject change - lambda *= 10; - int nviz = X->rows / num_err_param; - double e2 = errNorm*errNorm, e2_prev = prevErrNorm*prevErrNorm; - double e2n = e2/nviz, e2n_prev = e2_prev/nviz; - std::cerr<<"move failed: lambda = "< "< prevErrNorm ) { //step was not accepted + //increase lambda and reject change + lambda *= 10; + int nviz = X->rows / num_err_param; + double e2 = errNorm*errNorm, e2_prev = prevErrNorm*prevErrNorm; + double e2n = e2/nviz, e2n_prev = e2_prev/nviz; + std::cerr<<"move failed: lambda = "< "< criteria.max_iter ) || - (criteria.type&CV_TERMCRIT_EPS && param_change_norm < criteria.epsilon) ) { + if( (criteria.type&CV_TERMCRIT_ITER && iters > criteria.max_iter ) || + (criteria.type&CV_TERMCRIT_EPS && param_change_norm < criteria.epsilon) ) { // std::cerr<<"relative norm change "<data.db[8]; intr_data[5] = cam_params->data.db[9]; - CvMat _A = cvMat(3,3, CV_64F, intr_data ); + CvMat _A = cvMat(3,3, CV_64F, intr_data ); CvMat _dpdr, _dpdt, _dpdf, _dpdc, _dpdk; - + bool have_dk = cam_params->height - 10 ? true : false; cvGetCols( A, &_dpdr, 0, 3 ); cvGetCols( A, &_dpdt, 3, 6 ); cvGetCols( A, &_dpdf, 6, 8 ); cvGetCols( A, &_dpdc, 8, 10 ); - + if( have_dk ) { cvGetRows( cam_params, &_k, 10, cam_params->height ); cvGetCols( A, &_dpdk, 10, A->width ); } cvProjectPoints2(&_Mi, &_ri, &_ti, &_A, have_dk ? &_k : NULL, _mp, &_dpdr, &_dpdt, - &_dpdf, &_dpdc, have_dk ? &_dpdk : NULL, 0); + &_dpdf, &_dpdc, have_dk ? &_dpdk : NULL, 0); - cvReleaseMat( &_mp ); + cvReleaseMat( &_mp ); //compute jacobian for point params //compute dMeasure/dPoint3D @@ -781,30 +781,30 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A // y' = y/z //d(x') = ( dx*z - x*dz)/(z*z) - //d(y') = ( dy*z - y*dz)/(z*z) + //d(y') = ( dy*z - y*dz)/(z*z) //g = 1 + k1*r_2 + k2*r_4 + k3*r_6 //r_2 = x'*x' + y'*y' //d(r_2) = 2*x'*dx' + 2*y'*dy' - //dg = k1* d(r_2) + k2*2*r_2*d(r_2) + k3*3*r_2*r_2*d(r_2) + //dg = k1* d(r_2) + k2*2*r_2*d(r_2) + k3*3*r_2*r_2*d(r_2) //x" = x'*g + 2*p1*x'*y' + p2(r_2+2*x'_2) //y" = y'*g + p1(r_2+2*y'_2) + 2*p2*x'*y' - + //d(x") = d(x') * g + x' * d(g) + 2*p1*( d(x')*y' + x'*dy) + p2*(d(r_2) + 2*2*x'* dx') - //d(y") = d(y') * g + y' * d(g) + 2*p2*( d(x')*y' + x'*dy) + p1*(d(r_2) + 2*2*y'* dy') + //d(y") = d(y') * g + y' * d(g) + 2*p2*( d(x')*y' + x'*dy) + p1*(d(r_2) + 2*2*y'* dy') // u = fx*( x") + cx // v = fy*( y") + cy - + // du = fx * d(x") = fx * ( dx*z - x*dz)/ (z*z) // dv = fy * d(y") = fy * ( dy*z - y*dz)/ (z*z) - // dx/dX = r11, dx/dY = r12, dx/dZ = r13 + // dx/dX = r11, dx/dY = r12, dx/dZ = r13 // dy/dX = r21, dy/dY = r22, dy/dZ = r23 - // dz/dX = r31, dz/dY = r32, dz/dZ = r33 + // dz/dX = r31, dz/dY = r32, dz/dZ = r33 // du/dX = fx*(r11*z-x*r31)/(z*z) // du/dY = fx*(r12*z-x*r32)/(z*z) @@ -833,27 +833,27 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A double y = R[3] * X + R[4] * Y + R[5] * Z + t[1]; double z = R[6] * X + R[7] * Y + R[8] * Z + t[2]; -#if 1 +#if 1 //compute x',y' double x_strike = x/z; - double y_strike = y/z; + double y_strike = y/z; //compute dx',dy' matrix // - // dx'/dX dx'/dY dx'/dZ = + // dx'/dX dx'/dY dx'/dZ = // dy'/dX dy'/dY dy'/dZ double coeff[6] = { z, 0, -x, - 0, z, -y }; + 0, z, -y }; CvMat coeffmat = cvMat( 2, 3, CV_64F, coeff ); CvMat* dstrike_dbig = cvCreateMat(2,3,CV_64F); cvMatMul(&coeffmat, &_R, dstrike_dbig); - cvScale(dstrike_dbig, dstrike_dbig, 1/(z*z) ); - + cvScale(dstrike_dbig, dstrike_dbig, 1/(z*z) ); + if( have_dk ) { double strike_[2] = {x_strike, y_strike}; - CvMat strike = cvMat(1, 2, CV_64F, strike_); - + CvMat strike = cvMat(1, 2, CV_64F, strike_); + //compute r_2 double r_2 = x_strike*x_strike + y_strike*y_strike; double r_4 = r_2*r_2; @@ -867,24 +867,24 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A double& k1 = _k.data.db[0]; double& k2 = _k.data.db[1]; double& p1 = _k.data.db[2]; - double& p2 = _k.data.db[3]; + double& p2 = _k.data.db[3]; double k3 = 0; if( _k.cols*_k.rows == 5 ) { k3 = _k.data.db[4]; - } + } //compute dg/dbig double dg_dr2 = k1 + k2*2*r_2 + k3*3*r_4; double g = 1+k1*r_2+k2*r_4+k3*r_6; CvMat* dg_dbig = cvCreateMat(1,3,CV_64F); - cvScale( dr2_dbig, dg_dbig, dg_dr2 ); + cvScale( dr2_dbig, dg_dbig, dg_dr2 ); CvMat* tmp = cvCreateMat( 2, 3, CV_64F ); CvMat* dstrike2_dbig = cvCreateMat( 2, 3, CV_64F ); - + double c[4] = { g+2*p1*y_strike+4*p2*x_strike, 2*p1*x_strike, - 2*p2*y_strike, g+2*p2*x_strike + 4*p1*y_strike }; + 2*p2*y_strike, g+2*p2*x_strike + 4*p1*y_strike }; CvMat coeffmat = cvMat(2,2,CV_64F, c ); @@ -897,7 +897,7 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A CvMat pmat = cvMat(2, 1, CV_64F, p ); cvMatMul( &pmat, dr2_dbig ,tmp); - cvAdd( dstrike2_dbig, tmp, dstrike2_dbig ); + cvAdd( dstrike2_dbig, tmp, dstrike2_dbig ); cvCopy( dstrike2_dbig, B ); @@ -906,15 +906,15 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A cvReleaseMat(&tmp); cvReleaseMat(&dstrike2_dbig); - cvReleaseMat(&tmp); + cvReleaseMat(&tmp); } else { cvCopy(dstrike_dbig, B); } //multiply by fx, fy CvMat row; cvGetRows( B, &row, 0, 1 ); - cvScale( &row, &row, fx ); - + cvScale( &row, &row, fx ); + cvGetRows( B, &row, 1, 2 ); cvScale( &row, &row, fy ); @@ -925,17 +925,17 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A cvmSet( B, 0, 0, k*(R[0]*z-x*R[6])); cvmSet( B, 0, 1, k*(R[1]*z-x*R[7])); cvmSet( B, 0, 2, k*(R[2]*z-x*R[8])); - - k = fy/(z*z); - + + k = fy/(z*z); + cvmSet( B, 1, 0, k*(R[3]*z-y*R[6])); cvmSet( B, 1, 1, k*(R[4]*z-y*R[7])); cvmSet( B, 1, 2, k*(R[5]*z-y*R[8])); - + #endif - + }; -void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* estim, void* /*data*/) { +static void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* estim, void* /*data*/) { //just do projections CvMat _Mi; cvReshape( point_params, &_Mi, 3, 1 ); @@ -955,19 +955,19 @@ void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* e intr_data[2] = cam_params->data.db[8]; intr_data[5] = cam_params->data.db[9]; - CvMat _A = cvMat(3,3, CV_64F, intr_data ); + CvMat _A = cvMat(3,3, CV_64F, intr_data ); //int cn = CV_MAT_CN(_Mi.type); bool have_dk = cam_params->height - 10 ? true : false; - + if( have_dk ) { - cvGetRows( cam_params, &_k, 10, cam_params->height ); - } + cvGetRows( cam_params, &_k, 10, cam_params->height ); + } cvProjectPoints2( &_Mi, &_ri, &_ti, &_A, have_dk ? &_k : NULL, _mp, NULL, NULL, - NULL, NULL, NULL, 0); + NULL, NULL, NULL, 0); // std::cerr<<"_mp = "<<_mp->data.db[0]<<","<<_mp->data.db[1]<data.db[0] = _mp->data.db[0]; _mp2->data.db[1] = _mp->data.db[1]; cvTranspose( _mp2, estim ); @@ -975,41 +975,41 @@ void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* e cvReleaseMat( &_mp2 ); }; -void fjac_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data) { +static void fjac_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data) { CvMat _point_params = point_params, _cam_params = cam_params, _Al = A, _Bl = B; fjac(i,j, &_point_params, &_cam_params, &_Al, &_Bl, data); }; -void func_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data) { +static void func_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data) { CvMat _point_params = point_params, _cam_params = cam_params, _estim = estim; func(i,j,&_point_params,&_cam_params,&_estim,data); -}; +}; void LevMarqSparse::bundleAdjust( vector& points, //positions of points in global coordinate system (input and output) - const vector >& imagePoints, //projections of 3d points for every camera - const vector >& visibility, //visibility of 3d points for every camera - vector& cameraMatrix, //intrinsic matrices of all cameras (input and output) - vector& R, //rotation matrices of all cameras (input and output) - vector& T, //translation vector of all cameras (input and output) - vector& distCoeffs, //distortion coefficients of all cameras (input and output) - const TermCriteria& criteria, - BundleAdjustCallback cb, void* user_data) { + const vector >& imagePoints, //projections of 3d points for every camera + const vector >& visibility, //visibility of 3d points for every camera + vector& cameraMatrix, //intrinsic matrices of all cameras (input and output) + vector& R, //rotation matrices of all cameras (input and output) + vector& T, //translation vector of all cameras (input and output) + vector& distCoeffs, //distortion coefficients of all cameras (input and output) + const TermCriteria& criteria, + BundleAdjustCallback cb, void* user_data) { //,enum{MOTION_AND_STRUCTURE,MOTION,STRUCTURE}) int num_points = (int)points.size(); int num_cameras = (int)cameraMatrix.size(); - CV_Assert( imagePoints.size() == (size_t)num_cameras && - visibility.size() == (size_t)num_cameras && - R.size() == (size_t)num_cameras && - T.size() == (size_t)num_cameras && - (distCoeffs.size() == (size_t)num_cameras || distCoeffs.size() == 0) ); + CV_Assert( imagePoints.size() == (size_t)num_cameras && + visibility.size() == (size_t)num_cameras && + R.size() == (size_t)num_cameras && + T.size() == (size_t)num_cameras && + (distCoeffs.size() == (size_t)num_cameras || distCoeffs.size() == 0) ); int numdist = distCoeffs.size() ? (distCoeffs[0].rows * distCoeffs[0].cols) : 0; int num_cam_param = 3 /* rotation vector */ + 3 /* translation vector */ - + 2 /* fx, fy */ + 2 /* cx, cy */ + numdist; + + 2 /* fx, fy */ + 2 /* cx, cy */ + numdist; - int num_point_param = 3; + int num_point_param = 3; //collect camera parameters into vector Mat params( num_cameras * num_cam_param + num_points * num_point_param, 1, CV_64F ); @@ -1023,8 +1023,8 @@ void LevMarqSparse::bundleAdjust( vector& points, //positions of points //translation dst = params.rowRange(i*num_cam_param + 3, i*num_cam_param+6); - T[i].copyTo(dst); - + T[i].copyTo(dst); + //intrinsic camera matrix double* intr_data = (double*)cameraMatrix[i].data; double* intr = (double*)(params.data + params.step * (i*num_cam_param+6)); @@ -1033,14 +1033,14 @@ void LevMarqSparse::bundleAdjust( vector& points, //positions of points intr[1] = intr_data[4]; //fy //center of projection intr[2] = intr_data[2]; //cx - intr[3] = intr_data[5]; //cy + intr[3] = intr_data[5]; //cy //add distortion if exists if( distCoeffs.size() ) { dst = params.rowRange(i*num_cam_param + 10, i*num_cam_param+10+numdist); - distCoeffs[i].copyTo(dst); + distCoeffs[i].copyTo(dst); } - } + } //fill point params Mat ptparams(num_points, 1, CV_64FC3, params.data + num_cameras*num_cam_param*params.step); @@ -1059,26 +1059,26 @@ void LevMarqSparse::bundleAdjust( vector& points, //positions of points int num_proj = countNonZero(vismat); //total number of points projections //collect measurements - Mat X(num_proj*2,1,CV_64F); //measurement vector - + Mat X(num_proj*2,1,CV_64F); //measurement vector + int counter = 0; for(int i = 0; i < num_points; i++ ) { for(int j = 0; j < num_cameras; j++ ) { //check visibility if( visibility[j][i] ) { - //extract point and put tu vector - Point2d p = imagePoints[j][i]; - ((double*)(X.data))[counter] = p.x; - ((double*)(X.data))[counter+1] = p.y; - assert(p.x != -1 || p.y != -1); - counter+=2; - } - } + //extract point and put tu vector + Point2d p = imagePoints[j][i]; + ((double*)(X.data))[counter] = p.x; + ((double*)(X.data))[counter+1] = p.y; + assert(p.x != -1 || p.y != -1); + counter+=2; + } + } } LevMarqSparse levmar( num_points, num_cameras, num_point_param, num_cam_param, 2, vismat, params, X, - TermCriteria(criteria), fjac_new, func_new, NULL, - cb, user_data); + TermCriteria(criteria), fjac_new, func_new, NULL, + cb, user_data); //extract results //fill point params /*Mat final_points(num_points, 1, CV_64FC3, @@ -1101,7 +1101,7 @@ void LevMarqSparse::bundleAdjust( vector& points, //positions of points Mat rot_vec = Mat(levmar.P).rowRange(i*num_cam_param, i*num_cam_param+3); Rodrigues( rot_vec, R[i] ); //translation - T[i] = Mat(levmar.P).rowRange(i*num_cam_param + 3, i*num_cam_param+6); + T[i] = Mat(levmar.P).rowRange(i*num_cam_param + 3, i*num_cam_param+6); //intrinsic camera matrix double* intr_data = (double*)cameraMatrix[i].data; @@ -1111,11 +1111,11 @@ void LevMarqSparse::bundleAdjust( vector& points, //positions of points intr_data[4] = intr[1]; //fy //center of projection intr_data[2] = intr[2]; //cx - intr_data[5] = intr[3]; //cy + intr_data[5] = intr[3]; //cy //add distortion if exists if( distCoeffs.size() ) { Mat(levmar.P).rowRange(i*num_cam_param + 10, i*num_cam_param+10+numdist).copyTo(distCoeffs[i]); } - } -} + } +} diff --git a/modules/contrib/src/chamfermatching.cpp b/modules/contrib/src/chamfermatching.cpp index 37c1d10..42fcd29 100644 --- a/modules/contrib/src/chamfermatching.cpp +++ b/modules/contrib/src/chamfermatching.cpp @@ -81,6 +81,7 @@ private: { public: virtual ImageIterator* iterator() const = 0; + virtual ~ImageRange() {} }; // Sliding window diff --git a/modules/contrib/src/colormap.cpp b/modules/contrib/src/colormap.cpp index c0081c1..ce5c8f4 100644 --- a/modules/contrib/src/colormap.cpp +++ b/modules/contrib/src/colormap.cpp @@ -59,8 +59,8 @@ static Mat sortMatrixRowsByIndices(InputArray src, InputArray indices) return dst; } - -Mat argsort(InputArray _src, bool ascending=true) + +static Mat argsort(InputArray _src, bool ascending=true) { Mat src = _src.getMat(); if (src.rows != 1 && src.cols != 1) @@ -70,14 +70,14 @@ Mat argsort(InputArray _src, bool ascending=true) sortIdx(src.reshape(1,1),sorted_indices,flags); return sorted_indices; } - + template static Mat interp1_(const Mat& X_, const Mat& Y_, const Mat& XI) { int n = XI.rows; // sort input table vector sort_indices = argsort(X_); - + Mat X = sortMatrixRowsByIndices(X_,sort_indices); Mat Y = sortMatrixRowsByIndices(Y_,sort_indices); // interpolated values @@ -131,7 +131,7 @@ static Mat interp1(InputArray _x, InputArray _Y, InputArray _xi) } return Mat(); } - + namespace colormap { @@ -531,7 +531,7 @@ namespace colormap n); // number of sample points } }; - + void ColorMap::operator()(InputArray _src, OutputArray _dst) const { if(_lut.total() != 256) @@ -550,7 +550,7 @@ namespace colormap // Apply the ColorMap. LUT(src, _lut, _dst); } - + Mat ColorMap::linear_colormap(InputArray X, InputArray r, InputArray g, InputArray b, InputArray xi) { @@ -581,12 +581,12 @@ namespace colormap colormap == COLORMAP_HOT ? (colormap::ColorMap*)(new colormap::Hot) : colormap == COLORMAP_MKPJ1 ? (colormap::ColorMap*)(new colormap::MKPJ1) : colormap == COLORMAP_MKPJ2 ? (colormap::ColorMap*)(new colormap::MKPJ2) : 0; - + if( !cm ) CV_Error( CV_StsBadArg, "Unknown colormap id; use one of COLORMAP_*"); - + (*cm)(src, dst); - + delete cm; } } diff --git a/modules/contrib/src/detection_based_tracker.cpp b/modules/contrib/src/detection_based_tracker.cpp index bbf27b8..d65e9d9 100644 --- a/modules/contrib/src/detection_based_tracker.cpp +++ b/modules/contrib/src/detection_based_tracker.cpp @@ -3,7 +3,7 @@ #define DEBUGLOGS 1 -#if ANDROID +#ifdef ANDROID #include #define LOG_TAG "OBJECT_DETECTOR" #define LOGD0(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) @@ -25,7 +25,7 @@ #define LOGI(_str, ...) LOGI0(_str , ## __VA_ARGS__) #define LOGW(_str, ...) LOGW0(_str , ## __VA_ARGS__) #define LOGE(_str, ...) LOGE0(_str , ## __VA_ARGS__) -#else +#else #define LOGD(...) do{} while(0) #define LOGI(...) do{} while(0) #define LOGW(...) do{} while(0) @@ -193,7 +193,7 @@ do { } catch(...) { \ LOGE0("\n ERROR: UNKNOWN Exception caught\n\n"); \ } \ -} while(0) +} while(0) #endif void* workcycleObjectDetectorFunction(void* p) @@ -214,7 +214,7 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() vector objects; CV_Assert(stateThread==STATE_THREAD_WORKING_SLEEPING); - pthread_mutex_lock(&mutex); + pthread_mutex_lock(&mutex); { pthread_cond_signal(&objectDetectorThreadStartStop); @@ -268,7 +268,7 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- imageSeparateDetecting is empty, continue"); continue; } - LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start handling imageSeparateDetecting, img.size=%dx%d, img.data=0x%p", + LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start handling imageSeparateDetecting, img.size=%dx%d, img.data=0x%p", imageSeparateDetecting.size().width, imageSeparateDetecting.size().height, (void*)imageSeparateDetecting.data); @@ -368,7 +368,7 @@ void DetectionBasedTracker::SeparateDetectionWork::resetTracking() pthread_mutex_unlock(&mutex); - + } bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread(const Mat& imageGray, vector& rectsWhereRegions) @@ -398,7 +398,7 @@ bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThrea if (timeWhenDetectingThreadStartedWork > 0) { double time_from_previous_launch_in_ms=1000.0 * (((double)(getTickCount() - timeWhenDetectingThreadStartedWork )) / freq); //the same formula as for lastBigDetectionDuration shouldSendNewDataToWorkThread = (time_from_previous_launch_in_ms >= detectionBasedTracker.parameters.minDetectionPeriod); - LOGD("DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: shouldSendNewDataToWorkThread was 1, now it is %d, since time_from_previous_launch_in_ms=%.2f, minDetectionPeriod=%d", + LOGD("DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: shouldSendNewDataToWorkThread was 1, now it is %d, since time_from_previous_launch_in_ms=%.2f, minDetectionPeriod=%d", (shouldSendNewDataToWorkThread?1:0), time_from_previous_launch_in_ms, detectionBasedTracker.parameters.minDetectionPeriod); } @@ -454,7 +454,7 @@ DetectionBasedTracker::DetectionBasedTracker(const std::string& cascadeFilename, && (params.scaleFactor > 1.0) && (params.maxTrackLifetime >= 0) ); - if (!cascadeForTracking.load(cascadeFilename)) { + if (!cascadeForTracking.load(cascadeFilename)) { CV_Error(CV_StsBadArg, "DetectionBasedTracker::DetectionBasedTracker: Cannot load a cascade from the file '"+cascadeFilename+"'"); } @@ -495,7 +495,7 @@ void DetectionBasedTracker::process(const Mat& imageGray) Mat imageDetect=imageGray; int D=parameters.minObjectSize; - if (D < 1) + if (D < 1) D=1; vector rectsWhereRegions; @@ -633,7 +633,7 @@ void DetectionBasedTracker::updateTrackedObjects(const vector& detectedObj LOGD("DetectionBasedTracker::updateTrackedObjects: j=%d is rejected, because it is intersected with another rectangle", j); continue; } - LOGD("DetectionBasedTracker::updateTrackedObjects: detectedObjects[%d]={%d, %d, %d x %d}", + LOGD("DetectionBasedTracker::updateTrackedObjects: detectedObjects[%d]={%d, %d, %d x %d}", j, detectedObjects[j].x, detectedObjects[j].y, detectedObjects[j].width, detectedObjects[j].height); Rect r=prevRect & detectedObjects[j]; @@ -691,9 +691,9 @@ void DetectionBasedTracker::updateTrackedObjects(const vector& detectedObj std::vector::iterator it=trackedObjects.begin(); while( it != trackedObjects.end() ) { - if ( (it->numFramesNotDetected > parameters.maxTrackLifetime) + if ( (it->numFramesNotDetected > parameters.maxTrackLifetime) || - ( + ( (it->numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow) && (it->numFramesNotDetected > innerParameters.numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown) @@ -718,7 +718,7 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const return Rect(); } if (trackedObjects[i].numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow){ - LOGI("DetectionBasedTracker::calcTrackedObjectPositionToShow: trackedObjects[%d].numDetectedFrames=%d <= numStepsToWaitBeforeFirstShow=%d --- return empty Rect()", + LOGI("DetectionBasedTracker::calcTrackedObjectPositionToShow: trackedObjects[%d].numDetectedFrames=%d <= numStepsToWaitBeforeFirstShow=%d --- return empty Rect()", i, trackedObjects[i].numDetectedFrames, innerParameters.numStepsToWaitBeforeFirstShow); return Rect(); } diff --git a/modules/contrib/src/gencolors.cpp b/modules/contrib/src/gencolors.cpp index 12ef9d9..42fc411 100644 --- a/modules/contrib/src/gencolors.cpp +++ b/modules/contrib/src/gencolors.cpp @@ -46,7 +46,7 @@ using namespace cv; -void downsamplePoints( const Mat& src, Mat& dst, size_t count ) +static void downsamplePoints( const Mat& src, Mat& dst, size_t count ) { CV_Assert( count >= 2 ); CV_Assert( src.cols == 1 || src.rows == 1 ); diff --git a/modules/contrib/src/lda.cpp b/modules/contrib/src/lda.cpp index 5983530..d9c9fb1 100644 --- a/modules/contrib/src/lda.cpp +++ b/modules/contrib/src/lda.cpp @@ -28,7 +28,7 @@ using std::map; using std::set; using std::cout; using std::endl; - + // Removes duplicate elements in a given vector. template inline vector<_Tp> remove_dups(const vector<_Tp>& src) { @@ -42,7 +42,7 @@ inline vector<_Tp> remove_dups(const vector<_Tp>& src) { elems.push_back(*it); return elems; } - + static Mat argsort(InputArray _src, bool ascending=true) { Mat src = _src.getMat(); @@ -72,8 +72,8 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double } return data; } - -void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) { + +static void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) { if(_indices.getMat().type() != CV_32SC1) CV_Error(CV_StsUnsupportedFormat, "cv::sortColumnsByIndices only works on integer indices!"); Mat src = _src.getMat(); @@ -87,13 +87,13 @@ void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArra } } -Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices) { +static Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices) { Mat dst; sortMatrixColumnsByIndices(src, indices, dst); return dst; } - - + + template static bool isSymmetric_(InputArray src) { Mat _src = src.getMat(); @@ -151,7 +151,7 @@ static bool isSymmetric(InputArray src, double eps=1e-16) return false; } - + //------------------------------------------------------------------------------ // subspace::project //------------------------------------------------------------------------------ @@ -198,32 +198,32 @@ Mat subspaceReconstruct(InputArray _W, InputArray _mean, InputArray _src) return X; } - + class EigenvalueDecomposition { private: - + // Holds the data dimension. int n; - + // Stores real/imag part of a complex division. double cdivr, cdivi; - + // Pointer to internal memory. double *d, *e, *ort; double **V, **H; - + // Holds the computed eigenvalues. Mat _eigenvalues; - + // Holds the computed eigenvectors. Mat _eigenvectors; - + // Allocates memory. template _Tp *alloc_1d(int m) { return new _Tp[m]; } - + // Allocates memory. template _Tp *alloc_1d(int m, _Tp val) { @@ -232,7 +232,7 @@ private: arr[i] = val; return arr; } - + // Allocates memory. template _Tp **alloc_2d(int m, int n) { @@ -241,7 +241,7 @@ private: arr[i] = new _Tp[n]; return arr; } - + // Allocates memory. template _Tp **alloc_2d(int m, int n, _Tp val) { @@ -253,7 +253,7 @@ private: } return arr; } - + void cdiv(double xr, double xi, double yr, double yi) { double r, d; if (std::abs(yr) > std::abs(yi)) { @@ -268,16 +268,16 @@ private: cdivi = (r * xi - xr) / d; } } - + // Nonsymmetric reduction from Hessenberg to real Schur form. - + void hqr2() { - + // This is derived from the Algol procedure hqr2, // by Martin and Wilkinson, Handbook for Auto. Comp., // Vol.ii-Linear Algebra, and the corresponding // Fortran subroutine in EISPACK. - + // Initialize int nn = this->n; int n = nn - 1; @@ -286,9 +286,9 @@ private: double eps = pow(2.0, -52.0); double exshift = 0.0; double p = 0, q = 0, r = 0, s = 0, z = 0, t, w, x, y; - + // Store roots isolated by balanc and compute matrix norm - + double norm = 0.0; for (int i = 0; i < nn; i++) { if (i < low || i > high) { @@ -299,11 +299,11 @@ private: norm = norm + std::abs(H[i][j]); } } - + // Outer loop over eigenvalue index int iter = 0; while (n >= low) { - + // Look for single small sub-diagonal element int l = n; while (l > low) { @@ -316,19 +316,19 @@ private: } l--; } - + // Check for convergence // One root found - + if (l == n) { H[n][n] = H[n][n] + exshift; d[n] = H[n][n]; e[n] = 0.0; n--; iter = 0; - + // Two roots found - + } else if (l == n - 1) { w = H[n][n - 1] * H[n - 1][n]; p = (H[n - 1][n - 1] - H[n][n]) / 2.0; @@ -337,9 +337,9 @@ private: H[n][n] = H[n][n] + exshift; H[n - 1][n - 1] = H[n - 1][n - 1] + exshift; x = H[n][n]; - + // Real pair - + if (q >= 0) { if (p >= 0) { z = p + z; @@ -360,33 +360,33 @@ private: r = sqrt(p * p + q * q); p = p / r; q = q / r; - + // Row modification - + for (int j = n - 1; j < nn; j++) { z = H[n - 1][j]; H[n - 1][j] = q * z + p * H[n][j]; H[n][j] = q * H[n][j] - p * z; } - + // Column modification - + for (int i = 0; i <= n; i++) { z = H[i][n - 1]; H[i][n - 1] = q * z + p * H[i][n]; H[i][n] = q * H[i][n] - p * z; } - + // Accumulate transformations - + for (int i = low; i <= high; i++) { z = V[i][n - 1]; V[i][n - 1] = q * z + p * V[i][n]; V[i][n] = q * V[i][n] - p * z; } - + // Complex pair - + } else { d[n - 1] = x + p; d[n] = x + p; @@ -395,13 +395,13 @@ private: } n = n - 2; iter = 0; - + // No convergence yet - + } else { - + // Form shift - + x = H[n][n]; y = 0.0; w = 0.0; @@ -409,9 +409,9 @@ private: y = H[n - 1][n - 1]; w = H[n][n - 1] * H[n - 1][n]; } - + // Wilkinson's original ad hoc shift - + if (iter == 10) { exshift += x; for (int i = low; i <= n; i++) { @@ -421,9 +421,9 @@ private: x = y = 0.75 * s; w = -0.4375 * s * s; } - + // MATLAB's new ad hoc shift - + if (iter == 30) { s = (y - x) / 2.0; s = s * s + w; @@ -440,9 +440,9 @@ private: x = y = w = 0.964; } } - + iter = iter + 1; // (Could check iteration count here.) - + // Look for two consecutive small sub-diagonal elements int m = n - 2; while (m >= l) { @@ -466,16 +466,16 @@ private: } m--; } - + for (int i = m + 2; i <= n; i++) { H[i][i - 2] = 0.0; if (i > m + 2) { H[i][i - 3] = 0.0; } } - + // Double QR step involving rows l:n and columns m:n - + for (int k = m; k <= n - 1; k++) { bool notlast = (k != n - 1); if (k != m) { @@ -508,9 +508,9 @@ private: z = r / s; q = q / p; r = r / p; - + // Row modification - + for (int j = k; j < nn; j++) { p = H[k][j] + q * H[k + 1][j]; if (notlast) { @@ -520,9 +520,9 @@ private: H[k][j] = H[k][j] - p * x; H[k + 1][j] = H[k + 1][j] - p * y; } - + // Column modification - + for (int i = 0; i <= min(n, k + 3); i++) { p = x * H[i][k] + y * H[i][k + 1]; if (notlast) { @@ -532,9 +532,9 @@ private: H[i][k] = H[i][k] - p; H[i][k + 1] = H[i][k + 1] - p * q; } - + // Accumulate transformations - + for (int i = low; i <= high; i++) { p = x * V[i][k] + y * V[i][k + 1]; if (notlast) { @@ -548,19 +548,19 @@ private: } // k loop } // check convergence } // while (n >= low) - + // Backsubstitute to find vectors of upper triangular form - + if (norm == 0.0) { return; } - + for (n = nn - 1; n >= 0; n--) { p = d[n]; q = e[n]; - + // Real vector - + if (q == 0) { int l = n; H[n][n] = 1.0; @@ -581,9 +581,9 @@ private: } else { H[i][n] = -r / (eps * norm); } - + // Solve real equations - + } else { x = H[i][i + 1]; y = H[i + 1][i]; @@ -596,9 +596,9 @@ private: H[i + 1][n] = (-s - y * t) / z; } } - + // Overflow control - + t = std::abs(H[i][n]); if ((eps * t) * t > 1) { for (int j = i; j <= n; j++) { @@ -607,14 +607,14 @@ private: } } } - + // Complex vector - + } else if (q < 0) { int l = n - 1; - + // Last vector component imaginary so matrix is triangular - + if (std::abs(H[n][n - 1]) > std::abs(H[n - 1][n])) { H[n - 1][n - 1] = q / H[n][n - 1]; H[n - 1][n] = -(H[n][n] - p) / H[n][n - 1]; @@ -634,7 +634,7 @@ private: sa = sa + H[i][j] * H[j][n]; } w = H[i][i] - p; - + if (e[i] < 0.0) { z = w; r = ra; @@ -646,9 +646,9 @@ private: H[i][n - 1] = cdivr; H[i][n] = cdivi; } else { - + // Solve complex equations - + x = H[i][i + 1]; y = H[i + 1][i]; vr = (d[i] - p) * (d[i] - p) + e[i] * e[i] - q * q; @@ -673,9 +673,9 @@ private: H[i + 1][n] = cdivi; } } - + // Overflow control - + t = max(std::abs(H[i][n - 1]), std::abs(H[i][n])); if ((eps * t) * t > 1) { for (int j = i; j <= n; j++) { @@ -687,9 +687,9 @@ private: } } } - + // Vectors of isolated roots - + for (int i = 0; i < nn; i++) { if (i < low || i > high) { for (int j = i; j < nn; j++) { @@ -697,9 +697,9 @@ private: } } } - + // Back transformation to get eigenvectors of original matrix - + for (int j = nn - 1; j >= low; j--) { for (int i = low; i <= high; i++) { z = 0.0; @@ -710,7 +710,7 @@ private: } } } - + // Nonsymmetric reduction to Hessenberg form. void orthes() { // This is derived from the Algol procedures orthes and ortran, @@ -719,19 +719,19 @@ private: // Fortran subroutines in EISPACK. int low = 0; int high = n - 1; - + for (int m = low + 1; m <= high - 1; m++) { - + // Scale column. - + double scale = 0.0; for (int i = m; i <= high; i++) { scale = scale + std::abs(H[i][m - 1]); } if (scale != 0.0) { - + // Compute Householder transformation. - + double h = 0.0; for (int i = high; i >= m; i--) { ort[i] = H[i][m - 1] / scale; @@ -743,10 +743,10 @@ private: } h = h - ort[m] * g; ort[m] = ort[m] - g; - + // Apply Householder similarity transformation // H = (I-u*u'/h)*H*(I-u*u')/h) - + for (int j = m; j < n; j++) { double f = 0.0; for (int i = high; i >= m; i--) { @@ -757,7 +757,7 @@ private: H[i][j] -= f * ort[i]; } } - + for (int i = 0; i <= high; i++) { double f = 0.0; for (int j = high; j >= m; j--) { @@ -772,15 +772,15 @@ private: H[m][m - 1] = scale * g; } } - + // Accumulate transformations (Algol's ortran). - + for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { V[i][j] = (i == j ? 1.0 : 0.0); } } - + for (int m = high - 1; m >= low + 1; m--) { if (H[m][m - 1] != 0.0) { for (int i = m + 1; i <= high; i++) { @@ -800,7 +800,7 @@ private: } } } - + // Releases all internal working memory. void release() { // releases the working data @@ -814,7 +814,7 @@ private: delete[] H; delete[] V; } - + // Computes the Eigenvalue Decomposition for a matrix given in H. void compute() { // Allocate memory for the working data. @@ -839,11 +839,11 @@ private: // Deallocate the memory by releasing all internal working data. release(); } - + public: EigenvalueDecomposition() : n(0) { } - + // Initializes & computes the Eigenvalue Decomposition for a general matrix // given in src. This function is a port of the EigenvalueSolver in JAMA, // which has been released to public domain by The MathWorks and the @@ -851,7 +851,7 @@ public: EigenvalueDecomposition(InputArray src) { compute(src); } - + // This function computes the Eigenvalue Decomposition for a general matrix // given in src. This function is a port of the EigenvalueSolver in JAMA, // which has been released to public domain by The MathWorks and the @@ -883,9 +883,9 @@ public: compute(); } } - + ~EigenvalueDecomposition() {} - + // Returns the eigenvalues of the Eigenvalue Decomposition. Mat eigenvalues() { return _eigenvalues; } // Returns the eigenvectors of the Eigenvalue Decomposition. @@ -1045,6 +1045,6 @@ Mat LDA::project(InputArray src) { Mat LDA::reconstruct(InputArray src) { return subspaceReconstruct(_eigenvectors, Mat(), _dataAsRow ? src : src.getMat().t()); } - + } diff --git a/modules/contrib/src/octree.cpp b/modules/contrib/src/octree.cpp index e62cfb8..cb0f12e 100644 --- a/modules/contrib/src/octree.cpp +++ b/modules/contrib/src/octree.cpp @@ -43,98 +43,99 @@ #include "precomp.hpp" #include -namespace cv +namespace { + using namespace cv; const size_t MAX_STACK_SIZE = 255; const size_t MAX_LEAFS = 8; - + bool checkIfNodeOutsideSphere(const Octree::Node& node, const Point3f& c, float r) { if (node.x_max < (c.x - r) || node.y_max < (c.y - r) || node.z_max < (c.z - r)) return true; - + if ((c.x + r) < node.x_min || (c.y + r) < node.y_min || (c.z + r) < node.z_min) return true; - + return false; } - + bool checkIfNodeInsideSphere(const Octree::Node& node, const Point3f& c, float r) { r *= r; - + float d2_xmin = (node.x_min - c.x) * (node.x_min - c.x); float d2_ymin = (node.y_min - c.y) * (node.y_min - c.y); float d2_zmin = (node.z_min - c.z) * (node.z_min - c.z); - + if (d2_xmin + d2_ymin + d2_zmin > r) return false; - + float d2_zmax = (node.z_max - c.z) * (node.z_max - c.z); - + if (d2_xmin + d2_ymin + d2_zmax > r) return false; - + float d2_ymax = (node.y_max - c.y) * (node.y_max - c.y); - + if (d2_xmin + d2_ymax + d2_zmin > r) return false; - + if (d2_xmin + d2_ymax + d2_zmax > r) return false; - + float d2_xmax = (node.x_max - c.x) * (node.x_max - c.x); - + if (d2_xmax + d2_ymin + d2_zmin > r) return false; - + if (d2_xmax + d2_ymin + d2_zmax > r) return false; - + if (d2_xmax + d2_ymax + d2_zmin > r) return false; - + if (d2_xmax + d2_ymax + d2_zmax > r) return false; - + return true; } - + void fillMinMax(const vector& points, Octree::Node& node) { node.x_max = node.y_max = node.z_max = std::numeric_limits::min(); node.x_min = node.y_min = node.z_min = std::numeric_limits::max(); - + for (size_t i = 0; i < points.size(); ++i) { const Point3f& point = points[i]; - + if (node.x_max < point.x) node.x_max = point.x; - + if (node.y_max < point.y) node.y_max = point.y; - + if (node.z_max < point.z) node.z_max = point.z; - + if (node.x_min > point.x) node.x_min = point.x; - + if (node.y_min > point.y) node.y_min = point.y; - + if (node.z_min > point.z) node.z_min = point.z; } } - + size_t findSubboxForPoint(const Point3f& point, const Octree::Node& node) { size_t ind_x = point.x < (node.x_max + node.x_min) / 2 ? 0 : 1; size_t ind_y = point.y < (node.y_max + node.y_min) / 2 ? 0 : 1; size_t ind_z = point.z < (node.z_max + node.z_min) / 2 ? 0 : 1; - + return (ind_x << 2) + (ind_y << 1) + (ind_z << 0); } void initChildBox(const Octree::Node& parent, size_t boxIndex, Octree::Node& child) @@ -142,58 +143,61 @@ namespace cv child.x_min = child.x_max = (parent.x_max + parent.x_min) / 2; child.y_min = child.y_max = (parent.y_max + parent.y_min) / 2; child.z_min = child.z_max = (parent.z_max + parent.z_min) / 2; - + if ((boxIndex >> 0) & 1) child.z_max = parent.z_max; else child.z_min = parent.z_min; - + if ((boxIndex >> 1) & 1) child.y_max = parent.y_max; else child.y_min = parent.y_min; - + if ((boxIndex >> 2) & 1) child.x_max = parent.x_max; else child.x_min = parent.x_min; } - + +}//namespace + //////////////////////////////////////////////////////////////////////////////////////// /////////////////////////// Octree ////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// - +namespace cv +{ Octree::Octree() { } - + Octree::Octree(const vector& points3d, int maxLevels, int minPoints) { buildTree(points3d, maxLevels, minPoints); } - + Octree::~Octree() { } - + void Octree::getPointsWithinSphere(const Point3f& center, float radius, vector& out) const { out.clear(); - + if (nodes.empty()) return; - + int stack[MAX_STACK_SIZE]; int pos = 0; stack[pos] = 0; - + while (pos >= 0) { const Node& cur = nodes[stack[pos--]]; - + if (checkIfNodeOutsideSphere(cur, center, radius)) continue; - + if (checkIfNodeInsideSphere(cur, center, radius)) { size_t sz = out.size(); @@ -202,133 +206,133 @@ namespace cv out[sz++] = points[i]; continue; } - + if (cur.isLeaf) { double r2 = radius * radius; size_t sz = out.size(); out.resize(sz + (cur.end - cur.begin)); - + for (int i = cur.begin; i < cur.end; ++i) { const Point3f& point = points[i]; - + double dx = (point.x - center.x); double dy = (point.y - center.y); double dz = (point.z - center.z); - + double dist2 = dx * dx + dy * dy + dz * dz; - + if (dist2 < r2) out[sz++] = point; }; out.resize(sz); continue; } - + if (cur.children[0]) stack[++pos] = cur.children[0]; - + if (cur.children[1]) stack[++pos] = cur.children[1]; - + if (cur.children[2]) stack[++pos] = cur.children[2]; - + if (cur.children[3]) stack[++pos] = cur.children[3]; - + if (cur.children[4]) stack[++pos] = cur.children[4]; - + if (cur.children[5]) stack[++pos] = cur.children[5]; - + if (cur.children[6]) stack[++pos] = cur.children[6]; - + if (cur.children[7]) stack[++pos] = cur.children[7]; } } - + void Octree::buildTree(const vector& points3d, int maxLevels, int minPoints) { assert((size_t)maxLevels * 8 < MAX_STACK_SIZE); points.resize(points3d.size()); std::copy(points3d.begin(), points3d.end(), points.begin()); this->minPoints = minPoints; - + nodes.clear(); nodes.push_back(Node()); Node& root = nodes[0]; fillMinMax(points, root); - + root.isLeaf = true; root.maxLevels = maxLevels; root.begin = 0; root.end = (int)points.size(); for (size_t i = 0; i < MAX_LEAFS; i++) root.children[i] = 0; - + if (maxLevels != 1 && (root.end - root.begin) > minPoints) { root.isLeaf = false; buildNext(0); } } - + void Octree::buildNext(size_t nodeInd) { size_t size = nodes[nodeInd].end - nodes[nodeInd].begin; - + vector boxBorders(MAX_LEAFS+1, 0); vector boxIndices(size); vector tempPoints(size); - + for (int i = nodes[nodeInd].begin, j = 0; i < nodes[nodeInd].end; ++i, ++j) { const Point3f& p = points[i]; - + size_t subboxInd = findSubboxForPoint(p, nodes[nodeInd]); - + boxBorders[subboxInd+1]++; boxIndices[j] = subboxInd; tempPoints[j] = p; } - + for (size_t i = 1; i < boxBorders.size(); ++i) boxBorders[i] += boxBorders[i-1]; - + vector writeInds(boxBorders.begin(), boxBorders.end()); - + for (size_t i = 0; i < size; ++i) { size_t boxIndex = boxIndices[i]; Point3f& curPoint = tempPoints[i]; - + size_t copyTo = nodes[nodeInd].begin + writeInds[boxIndex]++; points[copyTo] = curPoint; } - + for (size_t i = 0; i < MAX_LEAFS; ++i) { if (boxBorders[i] == boxBorders[i+1]) continue; - + nodes.push_back(Node()); Node& child = nodes.back(); initChildBox(nodes[nodeInd], i, child); - + child.isLeaf = true; child.maxLevels = nodes[nodeInd].maxLevels - 1; child.begin = nodes[nodeInd].begin + (int)boxBorders[i+0]; child.end = nodes[nodeInd].begin + (int)boxBorders[i+1]; for (size_t k = 0; k < MAX_LEAFS; k++) child.children[k] = 0; - + nodes[nodeInd].children[i] = (int)(nodes.size() - 1); - + if (child.maxLevels != 1 && (child.end - child.begin) > minPoints) { child.isLeaf = false; @@ -336,5 +340,5 @@ namespace cv } } } - + } diff --git a/modules/contrib/src/precomp.hpp b/modules/contrib/src/precomp.hpp index 1f0ef9b..0a1cb10 100644 --- a/modules/contrib/src/precomp.hpp +++ b/modules/contrib/src/precomp.hpp @@ -43,11 +43,11 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4710 4711 4514 4996 ) #endif -#ifdef HAVE_CVCONFIG_H +#ifdef HAVE_CVCONFIG_H #include "cvconfig.h" #endif diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 1e005c3..101f7b0 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -1299,6 +1299,7 @@ public: GPU_MAT = 9 << KIND_SHIFT }; _InputArray(); + _InputArray(const Mat& m); _InputArray(const MatExpr& expr); template _InputArray(const _Tp* vec, int n); @@ -1328,6 +1329,8 @@ public: virtual int channels(int i=-1) const; virtual bool empty() const; + virtual ~_InputArray(); + int flags; void* obj; Size sz; @@ -1384,6 +1387,8 @@ public: virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; virtual void release() const; virtual void clear() const; + + virtual ~_OutputArray(); }; typedef const _InputArray& InputArray; @@ -3977,7 +3982,7 @@ public: CV_WRAP virtual bool isOpened() const; //! closes the file and releases all the memory buffers CV_WRAP virtual void release(); - //! closes the file, releases all the memory buffers and returns the text string + //! closes the file, releases all the memory buffers and returns the text string CV_WRAP virtual string releaseAndGetString(); //! returns the first element of the top-level mapping diff --git a/modules/core/include/opencv2/core/internal.hpp b/modules/core/include/opencv2/core/internal.hpp index d0b3cd4..39f8292 100644 --- a/modules/core/include/opencv2/core/internal.hpp +++ b/modules/core/include/opencv2/core/internal.hpp @@ -60,34 +60,34 @@ #endif #if defined WIN32 || defined WINCE -#ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?) -#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx -#endif -#include -#undef small -#undef min -#undef max +# ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?) +# define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx +# endif +# include +# undef small +# undef min +# undef max #else -#include +# include #endif #ifdef __BORLANDC__ -#ifndef WIN32 - #define WIN32 -#endif -#ifndef _WIN32 - #define _WIN32 -#endif - #define CV_DLL - #undef _CV_ALWAYS_PROFILE_ - #define _CV_ALWAYS_NO_PROFILE_ +# ifndef WIN32 +# define WIN32 +# endif +# ifndef _WIN32 +# define _WIN32 +# endif +# define CV_DLL +# undef _CV_ALWAYS_PROFILE_ +# define _CV_ALWAYS_NO_PROFILE_ #endif #ifndef FALSE -#define FALSE 0 +# define FALSE 0 #endif #ifndef TRUE -#define TRUE 1 +# define TRUE 1 #endif #define __BEGIN__ __CV_BEGIN__ @@ -95,7 +95,7 @@ #define EXIT __CV_EXIT__ #ifdef HAVE_IPP -#include "ipp.h" +# include "ipp.h" CV_INLINE IppiSize ippiSize(int width, int height) { @@ -104,137 +104,132 @@ CV_INLINE IppiSize ippiSize(int width, int height) } #endif -#if defined __SSE2__ || _MSC_VER >= 1300 -#include "emmintrin.h" -#define CV_SSE 1 -#define CV_SSE2 1 -#if defined __SSE3__ || _MSC_VER >= 1500 -#include "pmmintrin.h" -#define CV_SSE3 1 -#endif -#if defined __SSSE3__ -#include "tmmintrin.h" -#define CV_SSSE3 1 -#endif +#if defined __SSE2__ || (defined _MSC_VER && _MSC_VER >= 1300) +# include "emmintrin.h" +# define CV_SSE 1 +# define CV_SSE2 1 +# if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500) +# include "pmmintrin.h" +# define CV_SSE3 1 +# else +# define CV_SSE3 0 +# endif +# if defined __SSSE3__ +# include "tmmintrin.h" +# define CV_SSSE3 1 +# else +# define CV_SSSE3 0 +# endif #else -#define CV_SSE 0 -#define CV_SSE2 0 -#define CV_SSE3 0 -#define CV_SSSE3 0 +# define CV_SSE 0 +# define CV_SSE2 0 +# define CV_SSE3 0 +# define CV_SSSE3 0 #endif -#if defined ANDROID && defined __ARM_NEON__ && defined __GNUC__ -#include "arm_neon.h" -#define CV_NEON 1 +#if defined ANDROID && defined __ARM_NEON__ +# include "arm_neon.h" +# define CV_NEON 1 -#define CPU_HAS_NEON_FEATURE (true) +# define CPU_HAS_NEON_FEATURE (true) //TODO: make real check using stuff from "cpu-features.h" //((bool)android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) #else -#define CV_NEON 0 -#define CPU_HAS_NEON_FEATURE (false) -#endif - -#ifdef CV_ICC -#define CV_ENABLE_UNROLLED 0 -#else -#define CV_ENABLE_UNROLLED 1 +# define CV_NEON 0 +# define CPU_HAS_NEON_FEATURE (false) #endif #ifndef IPPI_CALL -#define IPPI_CALL(func) CV_Assert((func) >= 0) +# define IPPI_CALL(func) CV_Assert((func) >= 0) #endif #ifdef HAVE_TBB - #include "tbb/tbb_stddef.h" - #if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 - #include "tbb/tbb.h" - #include "tbb/task.h" - #undef min - #undef max - #else - #undef HAVE_TBB - #endif +# include "tbb/tbb_stddef.h" +# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 +# include "tbb/tbb.h" +# include "tbb/task.h" +# undef min +# undef max +# else +# undef HAVE_TBB +# endif #endif #ifdef HAVE_EIGEN - #include - #include "opencv2/core/eigen.hpp" +# include +# include "opencv2/core/eigen.hpp" #endif #ifdef __cplusplus +namespace cv +{ #ifdef HAVE_TBB - namespace cv + + typedef tbb::blocked_range BlockedRange; + + template static inline + void parallel_for( const BlockedRange& range, const Body& body ) { - typedef tbb::blocked_range BlockedRange; - - template static inline - void parallel_for( const BlockedRange& range, const Body& body ) - { - tbb::parallel_for(range, body); - } - - template static inline - void parallel_do( Iterator first, Iterator last, const Body& body ) - { - tbb::parallel_do(first, last, body); - } - - typedef tbb::split Split; - - template static inline - void parallel_reduce( const BlockedRange& range, Body& body ) - { - tbb::parallel_reduce(range, body); - } - - typedef tbb::concurrent_vector ConcurrentRectVector; - typedef tbb::concurrent_vector ConcurrentDoubleVector; + tbb::parallel_for(range, body); } + + template static inline + void parallel_do( Iterator first, Iterator last, const Body& body ) + { + tbb::parallel_do(first, last, body); + } + + typedef tbb::split Split; + + template static inline + void parallel_reduce( const BlockedRange& range, Body& body ) + { + tbb::parallel_reduce(range, body); + } + + typedef tbb::concurrent_vector ConcurrentRectVector; + typedef tbb::concurrent_vector ConcurrentDoubleVector; #else - namespace cv + class BlockedRange + { + public: + BlockedRange() : _begin(0), _end(0), _grainsize(0) {} + BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {} + int begin() const { return _begin; } + int end() const { return _end; } + int grainsize() const { return _grainsize; } + + protected: + int _begin, _end, _grainsize; + }; + + template static inline + void parallel_for( const BlockedRange& range, const Body& body ) { - class BlockedRange - { - public: - BlockedRange() : _begin(0), _end(0), _grainsize(0) {} - BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {} - int begin() const { return _begin; } - int end() const { return _end; } - int grainsize() const { return _grainsize; } - - protected: - int _begin, _end, _grainsize; - }; - - template static inline - void parallel_for( const BlockedRange& range, const Body& body ) - { - body(range); - } - typedef std::vector ConcurrentRectVector; - typedef std::vector ConcurrentDoubleVector; - - template static inline - void parallel_do( Iterator first, Iterator last, const Body& body ) - { - for( ; first != last; ++first ) - body(*first); - } - - class Split {}; - - template static inline - void parallel_reduce( const BlockedRange& range, Body& body ) - { - body(range); - } - + body(range); + } + typedef std::vector ConcurrentRectVector; + typedef std::vector ConcurrentDoubleVector; + + template static inline + void parallel_do( Iterator first, Iterator last, const Body& body ) + { + for( ; first != last; ++first ) + body(*first); + } + + class Split {}; + + template static inline + void parallel_reduce( const BlockedRange& range, Body& body ) + { + body(range); } #endif +} //namespace cv - #define CV_INIT_ALGORITHM(classname, algname, memberinit) \ +#define CV_INIT_ALGORITHM(classname, algname, memberinit) \ static Algorithm* create##classname() \ { \ return new classname; \ @@ -261,7 +256,7 @@ CV_INLINE IppiSize ippiSize(int width, int height) return &classname##_info(); \ } -#endif +#endif //__cplusplus /* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */ #define CV_MAX_INLINE_MAT_OP_SIZE 10 @@ -305,9 +300,9 @@ CV_INLINE IppiSize ippiSize(int width, int height) #define CV_MAX_STRLEN 1024 #if 0 /*def CV_CHECK_FOR_NANS*/ - #define CV_CHECK_NANS( arr ) cvCheckArray((arr)) +# define CV_CHECK_NANS( arr ) cvCheckArray((arr)) #else - #define CV_CHECK_NANS( arr ) +# define CV_CHECK_NANS( arr ) #endif /****************************************************************************************\ @@ -316,38 +311,38 @@ CV_INLINE IppiSize ippiSize(int width, int height) /* get alloca declaration */ #ifdef __GNUC__ - #undef alloca - #define alloca __builtin_alloca - #define CV_HAVE_ALLOCA 1 +# undef alloca +# define alloca __builtin_alloca +# define CV_HAVE_ALLOCA 1 #elif defined WIN32 || defined _WIN32 || \ defined WINCE || defined _MSC_VER || defined __BORLANDC__ - #include - #define CV_HAVE_ALLOCA 1 +# include +# define CV_HAVE_ALLOCA 1 #elif defined HAVE_ALLOCA_H - #include - #define CV_HAVE_ALLOCA 1 +# include +# define CV_HAVE_ALLOCA 1 #elif defined HAVE_ALLOCA - #include - #define CV_HAVE_ALLOCA 1 +# include +# define CV_HAVE_ALLOCA 1 #else - #undef CV_HAVE_ALLOCA +# undef CV_HAVE_ALLOCA #endif #ifdef __GNUC__ -#define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x))) +# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x))) #elif defined _MSC_VER -#define CV_DECL_ALIGNED(x) __declspec(align(x)) +# define CV_DECL_ALIGNED(x) __declspec(align(x)) #else -#define CV_DECL_ALIGNED(x) +# define CV_DECL_ALIGNED(x) #endif #if CV_HAVE_ALLOCA /* ! DO NOT make it an inline function */ -#define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN ) +# define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN ) #endif #ifndef CV_IMPL -#define CV_IMPL CV_EXTERN_C +# define CV_IMPL CV_EXTERN_C #endif #define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; } @@ -687,25 +682,25 @@ typedef enum CvStatus CV_UNSUPPORTED_DEPTH_ERR = -101, CV_UNSUPPORTED_FORMAT_ERR = -100, - CV_BADARG_ERR = -49, //ipp comp - CV_NOTDEFINED_ERR = -48, //ipp comp - - CV_BADCHANNELS_ERR = -47, //ipp comp - CV_BADRANGE_ERR = -44, //ipp comp - CV_BADSTEP_ERR = -29, //ipp comp - - CV_BADFLAG_ERR = -12, - CV_DIV_BY_ZERO_ERR = -11, //ipp comp - CV_BADCOEF_ERR = -10, - - CV_BADFACTOR_ERR = -7, - CV_BADPOINT_ERR = -6, - CV_BADSCALE_ERR = -4, - CV_OUTOFMEM_ERR = -3, - CV_NULLPTR_ERR = -2, - CV_BADSIZE_ERR = -1, - CV_NO_ERR = 0, - CV_OK = CV_NO_ERR + CV_BADARG_ERR = -49, //ipp comp + CV_NOTDEFINED_ERR = -48, //ipp comp + + CV_BADCHANNELS_ERR = -47, //ipp comp + CV_BADRANGE_ERR = -44, //ipp comp + CV_BADSTEP_ERR = -29, //ipp comp + + CV_BADFLAG_ERR = -12, + CV_DIV_BY_ZERO_ERR = -11, //ipp comp + CV_BADCOEF_ERR = -10, + + CV_BADFACTOR_ERR = -7, + CV_BADPOINT_ERR = -6, + CV_BADSCALE_ERR = -4, + CV_OUTOFMEM_ERR = -3, + CV_NULLPTR_ERR = -2, + CV_BADSIZE_ERR = -1, + CV_NO_ERR = 0, + CV_OK = CV_NO_ERR } CvStatus; @@ -720,8 +715,7 @@ CvFuncTable; typedef struct CvBigFuncTable { void* fn_2d[CV_DEPTH_MAX*4]; -} -CvBigFuncTable; +} CvBigFuncTable; #define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \ (tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \ @@ -732,13 +726,14 @@ CvBigFuncTable; (tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \ (tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG +#ifdef __cplusplus //! OpenGL extension table class CV_EXPORTS CvOpenGlFuncTab { public: virtual ~CvOpenGlFuncTab(); - virtual void genBuffers(int n, unsigned int* buffers) const = 0; + virtual void genBuffers(int n, unsigned int* buffers) const = 0; virtual void deleteBuffers(int n, const unsigned int* buffers) const = 0; virtual void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const = 0; @@ -764,4 +759,6 @@ CV_EXPORTS bool icvCheckGlError(const char* file, const int line, const char* fu #define CV_CheckGlError() CV_DbgAssert( (::icvCheckGlError(__FILE__, __LINE__)) ) #endif -#endif +#endif //__cplusplus + +#endif // __OPENCV_CORE_INTERNAL_HPP__ diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 1d8d42f..0420a75 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -55,7 +55,7 @@ #if defined __INTEL_COMPILER && !(defined WIN32 || defined _WIN32) // atomic increment on the linux version of the Intel(tm) compiler #define CV_XADD(addr,delta) _InterlockedExchangeAdd(const_cast(reinterpret_cast(addr)), delta) #elif defined __GNUC__ - + #if __GNUC__*10 + __GNUC_MINOR__ >= 42 #if !defined WIN32 && (defined __i486__ || defined __i586__ || \ @@ -74,7 +74,7 @@ #define CV_XADD __exchange_and_add #endif #endif - + #elif defined WIN32 || defined _WIN32 #define WIN32_MEAN_AND_LEAN #ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?) @@ -88,14 +88,14 @@ #else static inline int CV_XADD(int* addr, int delta) - { int tmp = *addr; *addr += delta; return tmp; } + { int tmp = *addr; *addr += delta; return tmp; } #endif #include namespace cv { - + using std::cos; using std::sin; using std::max; @@ -105,7 +105,7 @@ using std::log; using std::pow; using std::sqrt; - + /////////////// saturate_cast (used in image & signal processing) /////////////////// template static inline _Tp saturate_cast(uchar v) { return _Tp(v); } @@ -184,7 +184,7 @@ template<> inline int saturate_cast(double v) { return cvRound(v); } // we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. template<> inline unsigned saturate_cast(float v){ return cvRound(v); } template<> inline unsigned saturate_cast(double v) { return cvRound(v); } - + inline int fast_abs(uchar v) { return v; } inline int fast_abs(schar v) { return std::abs((int)v); } inline int fast_abs(ushort v) { return v; } @@ -284,7 +284,7 @@ template inline Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1 for(int i = 10; i < channels; i++) val[i] = _Tp(0); } - + template inline Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, @@ -349,7 +349,7 @@ template inline _Tp Matx<_Tp, m, n>::dot(const Matx< return s; } - + template inline double Matx<_Tp, m, n>::ddot(const Matx<_Tp, m, n>& M) const { double s = 0; @@ -376,7 +376,7 @@ Matx<_Tp,m,n> Matx<_Tp,m,n>::randu(_Tp a, _Tp b) cv::randu(matM, Scalar(a), Scalar(b)); return M; } - + template inline Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b) { @@ -385,7 +385,7 @@ Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b) cv::randn(matM, Scalar(a), Scalar(b)); return M; } - + template template inline Matx<_Tp, m, n>::operator Matx() const { @@ -393,7 +393,7 @@ inline Matx<_Tp, m, n>::operator Matx() const for( int i = 0; i < m*n; i++ ) M.val[i] = saturate_cast(val[i]); return M; } - + template template inline Matx<_Tp, m1, n1> Matx<_Tp, m, n>::reshape() const @@ -423,7 +423,7 @@ Matx<_Tp, 1, n> Matx<_Tp, m, n>::row(int i) const return Matx<_Tp, 1, n>(&val[i*n]); } - + template inline Matx<_Tp, m, 1> Matx<_Tp, m, n>::col(int j) const { @@ -434,7 +434,7 @@ Matx<_Tp, m, 1> Matx<_Tp, m, n>::col(int j) const return v; } - + template inline typename Matx<_Tp, m, n>::diag_type Matx<_Tp, m, n>::diag() const { @@ -444,7 +444,7 @@ typename Matx<_Tp, m, n>::diag_type Matx<_Tp, m, n>::diag() const return d; } - + template inline const _Tp& Matx<_Tp, m, n>::operator ()(int i, int j) const { @@ -452,7 +452,7 @@ const _Tp& Matx<_Tp, m, n>::operator ()(int i, int j) const return this->val[i*n + j]; } - + template inline _Tp& Matx<_Tp, m, n>::operator ()(int i, int j) { @@ -476,23 +476,23 @@ _Tp& Matx<_Tp, m, n>::operator ()(int i) return val[i]; } - + template static inline Matx<_Tp1, m, n>& operator += (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) { for( int i = 0; i < m*n; i++ ) a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); return a; -} +} + - template static inline Matx<_Tp1, m, n>& operator -= (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) { for( int i = 0; i < m*n; i++ ) a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); return a; -} +} template inline @@ -502,31 +502,31 @@ Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_Add val[i] = saturate_cast<_Tp>(a.val[i] + b.val[i]); } - + template inline Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp) { for( int i = 0; i < m*n; i++ ) val[i] = saturate_cast<_Tp>(a.val[i] - b.val[i]); } - - + + template template inline Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp) { for( int i = 0; i < m*n; i++ ) val[i] = saturate_cast<_Tp>(a.val[i] * alpha); } - - + + template inline Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp) { for( int i = 0; i < m*n; i++ ) val[i] = saturate_cast<_Tp>(a.val[i] * b.val[i]); } - - + + template template inline Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp) { @@ -539,8 +539,8 @@ Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_Mat val[i*n + j] = s; } } - - + + template inline Matx<_Tp,m,n>::Matx(const Matx<_Tp, n, m>& a, Matx_TOp) { @@ -549,20 +549,20 @@ Matx<_Tp,m,n>::Matx(const Matx<_Tp, n, m>& a, Matx_TOp) val[i*n + j] = a(j, i); } - + template static inline Matx<_Tp, m, n> operator + (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) { return Matx<_Tp, m, n>(a, b, Matx_AddOp()); } - - + + template static inline Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) { return Matx<_Tp, m, n>(a, b, Matx_SubOp()); -} - +} + template static inline Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, int alpha) @@ -570,15 +570,15 @@ Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, int alpha) for( int i = 0; i < m*n; i++ ) a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); return a; -} - +} + template static inline Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, float alpha) { for( int i = 0; i < m*n; i++ ) a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); return a; -} +} template static inline Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, double alpha) @@ -586,44 +586,44 @@ Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, double alpha) for( int i = 0; i < m*n; i++ ) a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); return a; -} +} template static inline Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, int alpha) { return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); -} +} template static inline Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, float alpha) { return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); -} +} template static inline Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, double alpha) { return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); -} - +} + template static inline Matx<_Tp, m, n> operator * (int alpha, const Matx<_Tp, m, n>& a) { return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); -} +} template static inline Matx<_Tp, m, n> operator * (float alpha, const Matx<_Tp, m, n>& a) { return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); -} +} template static inline Matx<_Tp, m, n> operator * (double alpha, const Matx<_Tp, m, n>& a) { return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); -} - +} + template static inline Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a) { @@ -637,15 +637,15 @@ Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b) return Matx<_Tp, m, n>(a, b, Matx_MatMulOp()); } - + template static inline Vec<_Tp, m> operator * (const Matx<_Tp, m, n>& a, const Vec<_Tp, n>& b) { Matx<_Tp, m, 1> c(a, b, Matx_MatMulOp()); return reinterpret_cast&>(c); } - - + + template static inline Point_<_Tp> operator * (const Matx<_Tp, 2, 2>& a, const Point_<_Tp>& b) { @@ -653,13 +653,13 @@ Point_<_Tp> operator * (const Matx<_Tp, 2, 2>& a, const Point_<_Tp>& b) return Point_<_Tp>(tmp.val[0], tmp.val[1]); } - + template static inline Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point3_<_Tp>& b) { Matx<_Tp, 3, 1> tmp = a*Vec<_Tp,3>(b.x, b.y, b.z); return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); -} +} template static inline @@ -667,14 +667,14 @@ Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b) { Matx<_Tp, 3, 1> tmp = a*Vec<_Tp,3>(b.x, b.y, 1); return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); -} +} + - template static inline Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b) { return a*Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1); -} +} template static inline @@ -684,7 +684,7 @@ Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b) return reinterpret_cast(c); } - + static inline Scalar operator * (const Matx& a, const Scalar& b) { @@ -692,18 +692,18 @@ Scalar operator * (const Matx& a, const Scalar& b) return reinterpret_cast(c); } - + template inline Matx<_Tp, m, n> Matx<_Tp, m, n>::mul(const Matx<_Tp, m, n>& a) const { return Matx<_Tp, m, n>(*this, a, Matx_MulOp()); } - + CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); -CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); template struct CV_EXPORTS Matx_DetOp @@ -719,7 +719,7 @@ template struct CV_EXPORTS Matx_DetOp return p; } }; - + template struct CV_EXPORTS Matx_DetOp<_Tp, 1> { @@ -748,13 +748,13 @@ template struct CV_EXPORTS Matx_DetOp<_Tp, 3> a(0,2)*(a(1,0)*a(2,1) - a(2,0)*a(1,1)); } }; - + template static inline double determinant(const Matx<_Tp, m, m>& a) { - return Matx_DetOp<_Tp, m>()(a); + return Matx_DetOp<_Tp, m>()(a); } - + template static inline double trace(const Matx<_Tp, m, n>& a) @@ -763,9 +763,9 @@ double trace(const Matx<_Tp, m, n>& a) for( int i = 0; i < std::min(m, n); i++ ) s += a(i,i); return s; -} +} + - template inline Matx<_Tp, n, m> Matx<_Tp, m, n>::t() const { @@ -778,19 +778,19 @@ template struct CV_EXPORTS Matx_FastInvOp bool operator()(const Matx<_Tp, m, m>& a, Matx<_Tp, m, m>& b, int method) const { Matx<_Tp, m, m> temp = a; - + // assume that b is all 0's on input => make it a unity matrix for( int i = 0; i < m; i++ ) b(i, i) = (_Tp)1; - + if( method == DECOMP_CHOLESKY ) return Cholesky(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m); - + return LU(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m) != 0; } }; - + template struct CV_EXPORTS Matx_FastInvOp<_Tp, 2> { bool operator()(const Matx<_Tp, 2, 2>& a, Matx<_Tp, 2, 2>& b, int) const @@ -807,7 +807,7 @@ template struct CV_EXPORTS Matx_FastInvOp<_Tp, 2> } }; - + template struct CV_EXPORTS Matx_FastInvOp<_Tp, 3> { bool operator()(const Matx<_Tp, 3, 3>& a, Matx<_Tp, 3, 3>& b, int) const @@ -819,11 +819,11 @@ template struct CV_EXPORTS Matx_FastInvOp<_Tp, 3> b(0,0) = (a(1,1) * a(2,2) - a(1,2) * a(2,1)) * d; b(0,1) = (a(0,2) * a(2,1) - a(0,1) * a(2,2)) * d; b(0,2) = (a(0,1) * a(1,2) - a(0,2) * a(1,1)) * d; - + b(1,0) = (a(1,2) * a(2,0) - a(1,0) * a(2,2)) * d; b(1,1) = (a(0,0) * a(2,2) - a(0,2) * a(2,0)) * d; b(1,2) = (a(0,2) * a(1,0) - a(0,0) * a(1,2)) * d; - + b(2,0) = (a(1,0) * a(2,1) - a(1,1) * a(2,0)) * d; b(2,1) = (a(0,1) * a(2,0) - a(0,0) * a(2,1)) * d; b(2,2) = (a(0,0) * a(1,1) - a(0,1) * a(1,0)) * d; @@ -831,7 +831,7 @@ template struct CV_EXPORTS Matx_FastInvOp<_Tp, 3> } }; - + template inline Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method) const { @@ -857,7 +857,7 @@ template struct CV_EXPORTS Matx_FastSolveOp x = b; if( method == DECOMP_CHOLESKY ) return Cholesky(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n); - + return LU(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n) != 0; } }; @@ -878,7 +878,7 @@ template struct CV_EXPORTS Matx_FastSolveOp<_Tp, 2, 1> } }; - + template struct CV_EXPORTS Matx_FastSolveOp<_Tp, 3, 1> { bool operator()(const Matx<_Tp, 3, 3>& a, const Matx<_Tp, 3, 1>& b, @@ -891,19 +891,19 @@ template struct CV_EXPORTS Matx_FastSolveOp<_Tp, 3, 1> x(0) = d*(b(0)*(a(1,1)*a(2,2) - a(1,2)*a(2,1)) - a(0,1)*(b(1)*a(2,2) - a(1,2)*b(2)) + a(0,2)*(b(1)*a(2,1) - a(1,1)*b(2))); - + x(1) = d*(a(0,0)*(b(1)*a(2,2) - a(1,2)*b(2)) - b(0)*(a(1,0)*a(2,2) - a(1,2)*a(2,0)) + a(0,2)*(a(1,0)*b(2) - b(1)*a(2,0))); - + x(2) = d*(a(0,0)*(a(1,1)*b(2) - b(1)*a(2,1)) - a(0,1)*(a(1,0)*b(2) - b(1)*a(2,0)) + b(0)*(a(1,0)*a(2,1) - a(1,1)*a(2,0))); return true; } }; - - + + template template inline Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) const { @@ -920,13 +920,13 @@ Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) c return ok ? x : Matx<_Tp, n, l>::zeros(); } -template inline +template inline Vec<_Tp, n> Matx<_Tp, m, n>::solve(const Vec<_Tp, m>& rhs, int method) const { Matx<_Tp, n, 1> x = solve(reinterpret_cast&>(rhs), method); return reinterpret_cast&>(x); } - + template static inline _AccTp normL2Sqr(const _Tp* a, int n) { @@ -974,8 +974,8 @@ _AccTp normInf(const _Tp* a, int n) s = std::max(s, (_AccTp)fast_abs(a[i])); return s; } - - + + template static inline _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n) { @@ -1001,7 +1001,7 @@ CV_EXPORTS float normL1_(const float* a, const float* b, int n); CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n); CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n); CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize); - + template<> inline float normL2Sqr(const float* a, const float* b, int n) { if( n >= 8 ) @@ -1015,7 +1015,7 @@ template<> inline float normL2Sqr(const float* a, const float* b, int n) return s; } - + template static inline _AccTp normL1(const _Tp* a, const _Tp* b, int n) { @@ -1052,7 +1052,7 @@ template<> inline float normL1(const float* a, const float* b, int n) template<> inline int normL1(const uchar* a, const uchar* b, int n) { return normL1_(a, b, n); -} +} template static inline _AccTp normInf(const _Tp* a, const _Tp* b, int n) @@ -1065,7 +1065,7 @@ _AccTp normInf(const _Tp* a, const _Tp* b, int n) } return s; } - + template static inline double norm(const Matx<_Tp, m, n>& M) @@ -1073,7 +1073,7 @@ double norm(const Matx<_Tp, m, n>& M) return std::sqrt(normL2Sqr<_Tp, double>(M.val, m*n)); } - + template static inline double norm(const Matx<_Tp, m, n>& M, int normType) { @@ -1081,8 +1081,8 @@ double norm(const Matx<_Tp, m, n>& M, int normType) normType == NORM_L1 ? (double)normL1<_Tp, DataType<_Tp>::work_type>(M.val, m*n) : std::sqrt((double)normL2Sqr<_Tp, DataType<_Tp>::work_type>(M.val, m*n)); } - - + + template static inline bool operator == (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) { @@ -1090,7 +1090,7 @@ bool operator == (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) if( a.val[i] != b.val[i] ) return false; return true; } - + template static inline bool operator != (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) { @@ -1123,7 +1123,7 @@ Matx<_Tp, m, n> MatxCommaInitializer<_Tp, m, n>::operator *() const { CV_DbgAssert( idx == n*m ); return *dst; -} +} /////////////////////////// short vector (Vec) ///////////////////////////// @@ -1175,11 +1175,11 @@ template inline Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v8, _Tp v9) : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {} - + template inline Vec<_Tp, cn>::Vec(const _Tp* values) : Matx<_Tp, cn, 1>(values) {} - + template inline Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m) : Matx<_Tp, cn, 1>(m.val) @@ -1198,8 +1198,8 @@ Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_Sub template template inline Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp op) : Matx<_Tp, cn, 1>(a, alpha, op) -{} - +{} + template inline Vec<_Tp, cn> Vec<_Tp, cn>::all(_Tp alpha) { Vec v; @@ -1222,8 +1222,8 @@ template Vec<_Tp, 2> conjugate(const Vec<_Tp, 2>& v) template Vec<_Tp, 4> conjugate(const Vec<_Tp, 4>& v) { return Vec<_Tp, 4>(v[0], -v[1], -v[2], -v[3]); -} - +} + template<> inline Vec Vec::conj() const { return conjugate(*this); @@ -1243,13 +1243,13 @@ template<> inline Vec Vec::conj() const { return conjugate(*this); } - + template inline Vec<_Tp, cn> Vec<_Tp, cn>::cross(const Vec<_Tp, cn>& v) const { CV_Error(CV_StsError, "for arbitrary-size vector there is no cross-product defined"); return Vec<_Tp, cn>(); } - + template template inline Vec<_Tp, cn>::operator Vec() const { @@ -1272,7 +1272,7 @@ template inline const _Tp& Vec<_Tp, cn>::operator [](int i CV_DbgAssert( (unsigned)i < (unsigned)cn ); return this->val[i]; } - + template inline _Tp& Vec<_Tp, cn>::operator [](int i) { CV_DbgAssert( (unsigned)i < (unsigned)cn ); @@ -1289,15 +1289,15 @@ template inline _Tp& Vec<_Tp, cn>::operator ()(int i) { CV_DbgAssert( (unsigned)i < (unsigned)cn ); return this->val[i]; -} - +} + template static inline Vec<_Tp1, cn>& operator += (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) { for( int i = 0; i < cn; i++ ) a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); return a; -} +} template static inline Vec<_Tp1, cn>& operator -= (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) @@ -1305,8 +1305,8 @@ operator -= (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) for( int i = 0; i < cn; i++ ) a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); return a; -} - +} + template static inline Vec<_Tp, cn> operator + (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) { @@ -1334,7 +1334,7 @@ Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, float alpha) a[i] = saturate_cast<_Tp>(a[i]*alpha); return a; } - + template static inline Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, double alpha) { @@ -1351,7 +1351,7 @@ Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, int alpha) a[i] = saturate_cast<_Tp>(a[i]*ialpha); return a; } - + template static inline Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, float alpha) { @@ -1368,8 +1368,8 @@ Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, double alpha) for( int i = 0; i < cn; i++ ) a[i] = saturate_cast<_Tp>(a[i]*ialpha); return a; -} - +} + template static inline Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, int alpha) { @@ -1404,7 +1404,7 @@ template static inline Vec<_Tp, cn> operator * (double alpha, const Vec<_Tp, cn>& a) { return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); -} +} template static inline Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, int alpha) @@ -1416,14 +1416,14 @@ template static inline Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, float alpha) { return Vec<_Tp, cn>(a, 1.f/alpha, Matx_ScaleOp()); -} +} template static inline Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, double alpha) { return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); -} - +} + template static inline Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a) { @@ -1439,13 +1439,13 @@ template inline Vec<_Tp, 4> operator * (const Vec<_Tp, 4>& v1, con saturate_cast<_Tp>(v1[0]*v2[2] - v1[1]*v2[3] + v1[2]*v2[0] + v1[3]*v2[1]), saturate_cast<_Tp>(v1[0]*v2[3] + v1[1]*v2[2] - v1[2]*v2[1] + v1[3]*v2[0])); } - + template inline Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) { v1 = v1 * v2; return v1; } - + template<> inline Vec Vec::cross(const Vec& v) const { return Vec(val[1]*v.val[2] - val[2]*v.val[1], @@ -1465,14 +1465,14 @@ template inline Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& double nv = norm(v); return v * (nv ? 1./nv : 0.); } - + template static inline VecCommaInitializer<_Tp, cn> operator << (const Vec<_Tp, cn>& vec, _T2 val) { VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec); return (commaInitializer, val); } - + template inline VecCommaInitializer<_Tp, cn>::VecCommaInitializer(Vec<_Tp, cn>* _vec) : MatxCommaInitializer<_Tp, cn, 1>(_vec) @@ -1491,7 +1491,7 @@ Vec<_Tp, cn> VecCommaInitializer<_Tp, cn>::operator *() const { CV_DbgAssert( this->idx == cn ); return *this->dst; -} +} //////////////////////////////// Complex ////////////////////////////// @@ -1508,8 +1508,8 @@ bool operator == (const Complex<_Tp>& a, const Complex<_Tp>& b) template static inline bool operator != (const Complex<_Tp>& a, const Complex<_Tp>& b) -{ return a.re != b.re || a.im != b.im; } - +{ return a.re != b.re || a.im != b.im; } + template static inline Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b) { return Complex<_Tp>( a.re + b.re, a.im + b.im ); } @@ -1637,7 +1637,7 @@ template inline double Point_<_Tp>::ddot(const Point_& pt) const template inline double Point_<_Tp>::cross(const Point_& pt) const { return (double)x*pt.y - (double)y*pt.x; } - + template static inline Point_<_Tp>& operator += (Point_<_Tp>& a, const Point_<_Tp>& b) { @@ -1676,8 +1676,8 @@ operator *= (Point_<_Tp>& a, double b) a.x = saturate_cast<_Tp>(a.x*b); a.y = saturate_cast<_Tp>(a.y*b); return a; -} - +} + template static inline double norm(const Point_<_Tp>& pt) { return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y); } @@ -1701,7 +1701,7 @@ template static inline Point_<_Tp> operator * (const Point_<_Tp>& template static inline Point_<_Tp> operator * (int a, const Point_<_Tp>& b) { return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); } - + template static inline Point_<_Tp> operator * (const Point_<_Tp>& a, float b) { return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); } @@ -1712,8 +1712,8 @@ template static inline Point_<_Tp> operator * (const Point_<_Tp>& { return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); } template static inline Point_<_Tp> operator * (double a, const Point_<_Tp>& b) -{ return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); } - +{ return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); } + //////////////////////////////// 3D Point //////////////////////////////// template inline Point3_<_Tp>::Point3_() : x(0), y(0), z(0) {} @@ -1740,7 +1740,7 @@ template inline _Tp Point3_<_Tp>::dot(const Point3_& pt) const { return saturate_cast<_Tp>(x*pt.x + y*pt.y + z*pt.z); } template inline double Point3_<_Tp>::ddot(const Point3_& pt) const { return (double)x*pt.x + (double)y*pt.y + (double)z*pt.z; } - + template inline Point3_<_Tp> Point3_<_Tp>::cross(const Point3_<_Tp>& pt) const { return Point3_<_Tp>(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x); @@ -1754,7 +1754,7 @@ operator += (Point3_<_Tp>& a, const Point3_<_Tp>& b) a.z = saturate_cast<_Tp>(a.z + b.z); return a; } - + template static inline Point3_<_Tp>& operator -= (Point3_<_Tp>& a, const Point3_<_Tp>& b) { @@ -1762,8 +1762,8 @@ operator -= (Point3_<_Tp>& a, const Point3_<_Tp>& b) a.y = saturate_cast<_Tp>(a.y - b.y); a.z = saturate_cast<_Tp>(a.z - b.z); return a; -} - +} + template static inline Point3_<_Tp>& operator *= (Point3_<_Tp>& a, int b) { @@ -1789,8 +1789,8 @@ operator *= (Point3_<_Tp>& a, double b) a.y = saturate_cast<_Tp>(a.y*b); a.z = saturate_cast<_Tp>(a.z*b); return a; -} - +} + template static inline double norm(const Point3_<_Tp>& pt) { return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y + (double)pt.z*pt.z); } @@ -1799,7 +1799,7 @@ template static inline bool operator == (const Point3_<_Tp>& a, co template static inline bool operator != (const Point3_<_Tp>& a, const Point3_<_Tp>& b) { return a.x != b.x || a.y != b.y || a.z != b.z; } - + template static inline Point3_<_Tp> operator + (const Point3_<_Tp>& a, const Point3_<_Tp>& b) { return Point3_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y), @@ -1844,7 +1844,7 @@ template static inline Point3_<_Tp> operator * (double a, const Po { return Point3_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a), saturate_cast<_Tp>(b.z*a) ); } - + //////////////////////////////// Size //////////////////////////////// template inline Size_<_Tp>::Size_() @@ -1958,8 +1958,8 @@ template static inline bool operator == (const Rect_<_Tp>& a, cons template static inline bool operator != (const Rect_<_Tp>& a, const Rect_<_Tp>& b) { return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height; -} - +} + template static inline Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Point_<_Tp>& b) { return Rect_<_Tp>( a.x + b.x, a.y + b.y, a.width, a.height ); @@ -2002,7 +2002,7 @@ inline RotatedRect::operator CvBox2D() const CvBox2D box; box.center = center; box.size = size; box.angle = angle; return box; } - + //////////////////////////////// Scalar_ /////////////////////////////// template inline Scalar_<_Tp>::Scalar_() @@ -2117,7 +2117,7 @@ template static inline Scalar_<_Tp> operator - (const Scalar_<_Tp> saturate_cast<_Tp>(-a.val[2]), saturate_cast<_Tp>(-a.val[3])); } - + template static inline Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) { @@ -2126,14 +2126,14 @@ operator * (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) saturate_cast<_Tp>(a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]), saturate_cast<_Tp>(a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0])); } - + template static inline Scalar_<_Tp>& operator *= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) { a = a*b; return a; -} - +} + template inline Scalar_<_Tp> Scalar_<_Tp>::conj() const { return Scalar_<_Tp>(saturate_cast<_Tp>(this->val[0]), @@ -2146,7 +2146,7 @@ template inline bool Scalar_<_Tp>::isReal() const { return this->val[1] == 0 && this->val[2] == 0 && this->val[3] == 0; } - + template static inline Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, _Tp alpha) { @@ -2154,36 +2154,36 @@ Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, _Tp alpha) saturate_cast<_Tp>(a.val[1] / alpha), saturate_cast<_Tp>(a.val[2] / alpha), saturate_cast<_Tp>(a.val[3] / alpha)); -} +} template static inline Scalar_ operator / (const Scalar_& a, float alpha) { float s = 1/alpha; return Scalar_(a.val[0]*s, a.val[1]*s, a.val[2]*s, a.val[3]*s); -} +} template static inline Scalar_ operator / (const Scalar_& a, double alpha) { double s = 1/alpha; return Scalar_(a.val[0]*s, a.val[1]*s, a.val[2]*s, a.val[3]*s); -} - +} + template static inline Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, _Tp alpha) { a = a/alpha; return a; } - + template static inline Scalar_<_Tp> operator / (_Tp a, const Scalar_<_Tp>& b) { _Tp s = a/(b[0]*b[0] + b[1]*b[1] + b[2]*b[2] + b[3]*b[3]); return b.conj()*s; -} - +} + template static inline Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) { @@ -2196,7 +2196,7 @@ Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) a = a/b; return a; } - + //////////////////////////////// Range ///////////////////////////////// inline Range::Range() : start(0), end(0) {} @@ -2251,8 +2251,8 @@ static inline Range operator - (const Range& r1, int delta) inline Range::operator CvSlice() const { return *this != Range::all() ? cvSlice(start, end) : CV_WHOLE_SEQ; } - - + + //////////////////////////////// Vector //////////////////////////////// // template vector class. It is similar to STL's vector, @@ -2268,7 +2268,7 @@ public: typedef const _Tp* const_iterator; typedef _Tp& reference; typedef const _Tp& const_reference; - + struct CV_EXPORTS Hdr { Hdr() : data(0), datastart(0), refcount(0), size(0), capacity(0) {}; @@ -2278,7 +2278,7 @@ public: size_t size; size_t capacity; }; - + Vector() {} Vector(size_t _size) { resize(_size); } Vector(size_t _size, const _Tp& val) @@ -2289,15 +2289,15 @@ public: } Vector(_Tp* _data, size_t _size, bool _copyData=false) { set(_data, _size, _copyData); } - + template Vector(const Vec<_Tp, n>& vec) - { set((_Tp*)&vec.val[0], n, true); } - + { set((_Tp*)&vec.val[0], n, true); } + Vector(const std::vector<_Tp>& vec, bool _copyData=false) - { set(!vec.empty() ? (_Tp*)&vec[0] : 0, vec.size(), _copyData); } - + { set(!vec.empty() ? (_Tp*)&vec[0] : 0, vec.size(), _copyData); } + Vector(const Vector& d) { *this = d; } - + Vector(const Vector& d, const Range& r_) { Range r = r_ == Range::all() ? Range(0, d.size()) : r_; @@ -2313,7 +2313,7 @@ public: hdr.capacity = hdr.size = r.size(); } } - + Vector<_Tp>& operator = (const Vector& d) { if( this != &d ) @@ -2325,12 +2325,12 @@ public: } return *this; } - + ~Vector() { release(); } - + Vector<_Tp> clone() const { return hdr.data ? Vector<_Tp>(hdr.data, hdr.size, true) : Vector<_Tp>(); } - + void copyTo(Vector<_Tp>& vec) const { size_t i, sz = size(); @@ -2340,7 +2340,7 @@ public: for( i = 0; i < sz; i++ ) dst[i] = src[i]; } - + void copyTo(std::vector<_Tp>& vec) const { size_t i, sz = size(); @@ -2350,10 +2350,10 @@ public: for( i = 0; i < sz; i++ ) dst[i] = src[i]; } - + operator CvMat() const { return cvMat((int)size(), 1, type(), (void*)hdr.data); } - + _Tp& operator [] (size_t i) { CV_DbgAssert( i < size() ); return hdr.data[i]; } const _Tp& operator [] (size_t i) const { CV_DbgAssert( i < size() ); return hdr.data[i]; } Vector operator() (const Range& r) const { return Vector(*this, r); } @@ -2361,12 +2361,12 @@ public: const _Tp& back() const { CV_DbgAssert(!empty()); return hdr.data[hdr.size-1]; } _Tp& front() { CV_DbgAssert(!empty()); return hdr.data[0]; } const _Tp& front() const { CV_DbgAssert(!empty()); return hdr.data[0]; } - + _Tp* begin() { return hdr.data; } _Tp* end() { return hdr.data + hdr.size; } const _Tp* begin() const { return hdr.data; } const _Tp* end() const { return hdr.data + hdr.size; } - + void addref() { if( hdr.refcount ) CV_XADD(hdr.refcount, 1); } void release() { @@ -2377,7 +2377,7 @@ public: } hdr = Hdr(); } - + void set(_Tp* _data, size_t _size, bool _copyData=false) { if( !_copyData ) @@ -2395,7 +2395,7 @@ public: hdr.size = _size; } } - + void reserve(size_t newCapacity) { _Tp* newData; @@ -2414,7 +2414,7 @@ public: hdr.size = oldSize; hdr.refcount = newRefcount; } - + void resize(size_t newSize) { size_t i; @@ -2427,7 +2427,7 @@ public: hdr.data[i] = _Tp(); hdr.size = newSize; } - + Vector<_Tp>& push_back(const _Tp& elem) { if( hdr.size == hdr.capacity ) @@ -2435,25 +2435,25 @@ public: hdr.data[hdr.size++] = elem; return *this; } - + Vector<_Tp>& pop_back() { if( hdr.size > 0 ) --hdr.size; return *this; } - + size_t size() const { return hdr.size; } size_t capacity() const { return hdr.capacity; } bool empty() const { return hdr.size == 0; } void clear() { resize(0); } int type() const { return DataType<_Tp>::type; } - + protected: Hdr hdr; -}; +}; + - template inline typename DataType<_Tp>::work_type dot(const Vector<_Tp>& v1, const Vector<_Tp>& v2) { @@ -2475,7 +2475,7 @@ dot(const Vector<_Tp>& v1, const Vector<_Tp>& v2) } return s; } - + // Multiply-with-Carry RNG inline RNG::RNG() { state = 0xffffffff; } inline RNG::RNG(uint64 _state) { state = _state ? _state : 0xffffffff; } @@ -2533,7 +2533,7 @@ inline Point LineIterator::pos() const p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize); return p; } - + /////////////////////////////// AutoBuffer //////////////////////////////////////// template inline AutoBuffer<_Tp, fixed_size>::AutoBuffer() @@ -2653,7 +2653,7 @@ template template inline Ptr<_Tp2> Ptr<_Tp>::ptr() p.refcount = refcount; return p; } - + template template inline const Ptr<_Tp2> Ptr<_Tp>::ptr() const { Ptr<_Tp2> p; @@ -2665,7 +2665,7 @@ template template inline const Ptr<_Tp2> Ptr<_Tp>:: p.refcount = refcount; return p; } - + //// specializied implementations of Ptr::delete_obj() for classic OpenCV types template<> CV_EXPORTS void Ptr::delete_obj(); @@ -2674,7 +2674,7 @@ template<> CV_EXPORTS void Ptr::delete_obj(); template<> CV_EXPORTS void Ptr::delete_obj(); template<> CV_EXPORTS void Ptr::delete_obj(); template<> CV_EXPORTS void Ptr::delete_obj(); - + //////////////////////////////////////// XML & YAML I/O //////////////////////////////////// CV_EXPORTS_W void write( FileStorage& fs, const string& name, int value ); @@ -2870,11 +2870,11 @@ template static inline void write( FileStorage& fs, const string& { WriteStructContext ws(fs, name, CV_NODE_SEQ+(DataType<_Tp>::fmt != 0 ? CV_NODE_FLOW : 0)); write(fs, vec); -} - +} + CV_EXPORTS_W void write( FileStorage& fs, const string& name, const Mat& value ); CV_EXPORTS void write( FileStorage& fs, const string& name, const SparseMat& value ); - + template static inline FileStorage& operator << (FileStorage& fs, const _Tp& value) { if( !fs.isOpened() ) @@ -2923,7 +2923,7 @@ static inline void read(const FileNode& node, int& value, int default_value) CV_NODE_IS_INT(node.node->tag) ? node.node->data.i : CV_NODE_IS_REAL(node.node->tag) ? cvRound(node.node->data.f) : 0x7fffffff; } - + static inline void read(const FileNode& node, bool& value, bool default_value) { int temp; read(node, temp, (int)default_value); @@ -2953,7 +2953,7 @@ static inline void read(const FileNode& node, short& value, short default_value) int temp; read(node, temp, (int)default_value); value = saturate_cast(temp); } - + static inline void read(const FileNode& node, float& value, float default_value) { value = !node.node ? default_value : @@ -2975,7 +2975,7 @@ static inline void read(const FileNode& node, string& value, const string& defau CV_EXPORTS_W void read(const FileNode& node, Mat& mat, const Mat& default_mat=Mat() ); CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat=SparseMat() ); - + inline FileNode::operator int() const { int value; @@ -3019,7 +3019,7 @@ public: } FileNodeIterator* it; }; - + template class CV_EXPORTS VecReaderProxy<_Tp,1> { public: @@ -3055,7 +3055,7 @@ read( const FileNode& node, vector<_Tp>& vec, const vector<_Tp>& default_value=v read( it, vec ); } } - + inline FileNodeIterator FileNode::begin() const { return FileNodeIterator(fs, node); @@ -3459,7 +3459,7 @@ partition( const vector<_Tp>& _vec, vector& labels, return nclasses; } - + ////////////////////////////////////////////////////////////////////////////// // bridge C++ => C Seq API @@ -3473,7 +3473,7 @@ CV_EXPORTS void seqRemove( CvSeq* seq, int index ); CV_EXPORTS void clearSeq( CvSeq* seq ); CV_EXPORTS schar* getSeqElem( const CvSeq* seq, int index ); CV_EXPORTS void seqRemoveSlice( CvSeq* seq, CvSlice slice ); -CV_EXPORTS void seqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); +CV_EXPORTS void seqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); template inline Seq<_Tp>::Seq() : seq(0) {} template inline Seq<_Tp>::Seq( const CvSeq* _seq ) : seq((CvSeq*)_seq) @@ -3528,8 +3528,8 @@ template inline void Seq<_Tp>::push_back(const _Tp* elem, size_t c { cvSeqPushMulti(seq, elem, (int)count, 0); } template inline void Seq<_Tp>::push_front(const _Tp* elem, size_t count) -{ cvSeqPushMulti(seq, elem, (int)count, 1); } - +{ cvSeqPushMulti(seq, elem, (int)count, 1); } + template inline _Tp& Seq<_Tp>::back() { return *(_Tp*)getSeqElem(seq, -1); } @@ -3558,23 +3558,23 @@ template inline void Seq<_Tp>::pop_back(_Tp* elem, size_t count) { seqPopMulti(seq, elem, (int)count, 0); } template inline void Seq<_Tp>::pop_front(_Tp* elem, size_t count) -{ seqPopMulti(seq, elem, (int)count, 1); } +{ seqPopMulti(seq, elem, (int)count, 1); } template inline void Seq<_Tp>::insert(int idx, const _Tp& elem) { seqInsert(seq, idx, &elem); } - + template inline void Seq<_Tp>::insert(int idx, const _Tp* elems, size_t count) { CvMat m = cvMat(1, count, DataType<_Tp>::type, elems); seqInsertSlice(seq, idx, &m); } - + template inline void Seq<_Tp>::remove(int idx) { seqRemove(seq, idx); } - + template inline void Seq<_Tp>::remove(const Range& r) { seqRemoveSlice(seq, r); } - + template inline void Seq<_Tp>::copyTo(vector<_Tp>& vec, const Range& range) const { size_t len = !seq ? 0 : range == Range::all() ? seq->total : range.end - range.start; @@ -3716,7 +3716,7 @@ public: delete obj; return 0; } - + static void write(CvFileStorage* _fs, const char* name, const void* ptr, CvAttrList) { if(ptr && _fs) @@ -3726,7 +3726,7 @@ public: ((const _ClsName*)ptr)->write(fs, string(name)); } } - + static void* clone(const void* ptr) { if(!ptr) @@ -3735,7 +3735,7 @@ public: } }; - + class CV_EXPORTS Formatter { public: @@ -3759,7 +3759,7 @@ struct CV_EXPORTS Formatted vector params; }; - + /** Writes a point to an output stream in Matlab notation */ template inline std::ostream& operator<<(std::ostream& out, const Point_<_Tp>& p) @@ -3774,7 +3774,7 @@ template inline std::ostream& operator<<(std::ostream& out, const { out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; return out; -} +} static inline Formatted format(const Mat& mtx, const char* fmt, const vector& params=vector()) @@ -3800,7 +3800,7 @@ template static inline Formatted format(const vector Mat my_mat = Mat::eye(3,3,CV_32F); std::cout << my_mat; @endverbatim - */ + */ static inline std::ostream& operator << (std::ostream& out, const Mat& mtx) { Formatter::get()->write(out, mtx); @@ -3813,7 +3813,7 @@ static inline std::ostream& operator << (std::ostream& out, const Mat& mtx) Mat my_mat = Mat::eye(3,3,CV_32F); std::cout << my_mat; @endverbatim - */ + */ static inline std::ostream& operator << (std::ostream& out, const Formatted& fmtd) { fmtd.fmt->write(out, fmtd.mtx); @@ -3835,13 +3835,13 @@ template static inline std::ostream& operator << (std::ostream& ou Formatter::get()->write(out, Mat(vec)); return out; } - + template inline Ptr<_Tp> Algorithm::create(const string& name) { return _create(name).ptr<_Tp>(); } - + template inline typename ParamType<_Tp>::member_type Algorithm::get(const string& name) const { typename ParamType<_Tp>::member_type value; @@ -3854,8 +3854,8 @@ template inline typename ParamType<_Tp>::member_type Algorithm::ge typename ParamType<_Tp>::member_type value; info()->get(this, name, ParamType<_Tp>::type, &value); return value; -} - +} + } #endif // __cplusplus diff --git a/modules/core/include/opencv2/core/types_c.h b/modules/core/include/opencv2/core/types_c.h index e11f096..6c483603 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -43,122 +43,132 @@ #ifndef __OPENCV_CORE_TYPES_H__ #define __OPENCV_CORE_TYPES_H__ -#if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300 -#define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */ +#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER +# if _MSC_VER > 1300 +# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */ +# endif #endif #ifndef SKIP_INCLUDES - #include - #include - #include - #include + +#include +#include +#include +#include #if !defined _MSC_VER && !defined __BORLANDC__ - #include +# include +#endif + +#if defined __ICL +# define CV_ICC __ICL +#elif defined __ICC +# define CV_ICC __ICC +#elif defined __ECL +# define CV_ICC __ECL +#elif defined __ECC +# define CV_ICC __ECC +#elif defined __INTEL_COMPILER +# define CV_ICC __INTEL_COMPILER +#endif + +#if defined CV_ICC && !defined CV_ENABLE_UNROLLED +# define CV_ENABLE_UNROLLED 0 +#else +# define CV_ENABLE_UNROLLED 1 +#endif + +#if (defined _M_X64 && _MSC_VER >= 1400) || (__GNUC__ >= 4 && defined __x86_64__) +# if defined WIN32 +# include +# endif +# if __SSE2__ || !defined __GNUC__ +# include +# endif +#endif + +#if defined __BORLANDC__ +# include +#else +# include +#endif + +#ifdef HAVE_IPL +# ifndef __IPL_H__ +# if defined WIN32 || defined _WIN32 +# include +# else +# include +# endif +# endif +#elif defined __IPL_H__ +# define HAVE_IPL #endif - #if defined __ICL - #define CV_ICC __ICL - #elif defined __ICC - #define CV_ICC __ICC - #elif defined __ECL - #define CV_ICC __ECL - #elif defined __ECC - #define CV_ICC __ECC - #elif defined __INTEL_COMPILER - #define CV_ICC __INTEL_COMPILER - #endif - - #if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__) - #if defined WIN32 - #include - #endif - #if __SSE2__ || !defined __GNUC__ - #include - #endif - #endif - - #if defined __BORLANDC__ - #include - #else - #include - #endif - - #ifdef HAVE_IPL - #ifndef __IPL_H__ - #if defined WIN32 || defined _WIN32 - #include - #else - #include - #endif - #endif - #elif defined __IPL_H__ - #define HAVE_IPL - #endif #endif // SKIP_INCLUDES #if defined WIN32 || defined _WIN32 - #define CV_CDECL __cdecl - #define CV_STDCALL __stdcall +# define CV_CDECL __cdecl +# define CV_STDCALL __stdcall #else - #define CV_CDECL - #define CV_STDCALL +# define CV_CDECL +# define CV_STDCALL #endif #ifndef CV_EXTERN_C - #ifdef __cplusplus - #define CV_EXTERN_C extern "C" - #define CV_DEFAULT(val) = val - #else - #define CV_EXTERN_C - #define CV_DEFAULT(val) - #endif +# ifdef __cplusplus +# define CV_EXTERN_C extern "C" +# define CV_DEFAULT(val) = val +# else +# define CV_EXTERN_C +# define CV_DEFAULT(val) +# endif #endif #ifndef CV_EXTERN_C_FUNCPTR - #ifdef __cplusplus - #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; } - #else - #define CV_EXTERN_C_FUNCPTR(x) typedef x - #endif +# ifdef __cplusplus +# define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; } +# else +# define CV_EXTERN_C_FUNCPTR(x) typedef x +# endif #endif #ifndef CV_INLINE -#if defined __cplusplus - #define CV_INLINE inline -#elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__ - #define CV_INLINE __inline -#else - #define CV_INLINE static -#endif +# if defined __cplusplus +# define CV_INLINE inline +# elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__ +# define CV_INLINE __inline +# else +# define CV_INLINE static +# endif #endif /* CV_INLINE */ #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS - #define CV_EXPORTS __declspec(dllexport) +# define CV_EXPORTS __declspec(dllexport) #else - #define CV_EXPORTS +# define CV_EXPORTS #endif #ifndef CVAPI - #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL +# define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL #endif #if defined _MSC_VER || defined __BORLANDC__ -typedef __int64 int64; -typedef unsigned __int64 uint64; -#define CV_BIG_INT(n) n##I64 -#define CV_BIG_UINT(n) n##UI64 + typedef __int64 int64; + typedef unsigned __int64 uint64; +# define CV_BIG_INT(n) n##I64 +# define CV_BIG_UINT(n) n##UI64 #else -typedef int64_t int64; -typedef uint64_t uint64; -#define CV_BIG_INT(n) n##LL -#define CV_BIG_UINT(n) n##ULL + typedef int64_t int64; + typedef uint64_t uint64; +# define CV_BIG_INT(n) n##LL +# define CV_BIG_UINT(n) n##ULL #endif #ifndef HAVE_IPL -typedef unsigned char uchar; -typedef unsigned short ushort; + typedef unsigned char uchar; + typedef unsigned short ushort; #endif typedef signed char schar; @@ -203,7 +213,7 @@ Cv64suf; typedef int CVStatus; -enum { +enum { CV_StsOk= 0, /* everithing is ok */ CV_StsBackTrace= -1, /* pseudo error for back trace */ CV_StsError= -2, /* unknown /unspecified error */ @@ -241,8 +251,8 @@ enum { CV_StsInplaceNotSupported= -203, /* in-place operation is not supported */ CV_StsObjectNotFound= -204, /* request can't be completed */ CV_StsUnmatchedFormats= -205, /* formats of input/output arrays differ */ - CV_StsBadFlag= -206, /* flag is wrong or not supported */ - CV_StsBadPoint= -207, /* bad CvPoint */ + CV_StsBadFlag= -206, /* flag is wrong or not supported */ + CV_StsBadPoint= -207, /* bad CvPoint */ CV_StsBadMask= -208, /* bad format of mask (neither 8uC1 nor 8sC1)*/ CV_StsUnmatchedSizes= -209, /* sizes of input/output structures do not match */ CV_StsUnsupportedFormat= -210, /* the data format/type is not supported by the function*/ @@ -250,8 +260,8 @@ enum { CV_StsParseError= -212, /* invalid syntax/structure of the parsed file */ CV_StsNotImplemented= -213, /* the requested function/feature is not implemented */ CV_StsBadMemBlock= -214, /* an allocated block has been corrupted */ - CV_StsAssert= -215, /* assertion failed */ - CV_GpuNotSupported= -216, + CV_StsAssert= -215, /* assertion failed */ + CV_GpuNotSupported= -216, CV_GpuApiCallError= -217, CV_OpenGlNotSupported= -218, CV_OpenGlApiCallError= -219 @@ -262,7 +272,7 @@ enum { \****************************************************************************************/ #ifdef HAVE_TEGRA_OPTIMIZATION -# include "tegra_round.hpp" +# include "tegra_round.hpp" #endif #define CV_PI 3.1415926535897932384626433832795 @@ -271,11 +281,11 @@ enum { #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) #ifndef MIN -#define MIN(a,b) ((a) > (b) ? (b) : (a)) +# define MIN(a,b) ((a) > (b) ? (b) : (a)) #endif #ifndef MAX -#define MAX(a,b) ((a) < (b) ? (b) : (a)) +# define MAX(a,b) ((a) < (b) ? (b) : (a)) #endif /* min & max without jumps */ @@ -285,9 +295,9 @@ enum { /* absolute value without jumps */ #ifndef __cplusplus -#define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) +# define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) #else -#define CV_IABS(a) abs(a) +# define CV_IABS(a) abs(a) #endif #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) #define CV_SIGN(a) CV_CMP((a),0) @@ -306,11 +316,11 @@ CV_INLINE int cvRound( double value ) } return t; #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__ -# ifdef HAVE_TEGRA_OPTIMIZATION +# ifdef HAVE_TEGRA_OPTIMIZATION TEGRA_ROUND(value); -# else +# else return (int)lrint(value); -# endif +# endif #else // while this is not IEEE754-compliant rounding, it's usually a good enough approximation return (int)(value + (value >= 0 ? 0.5 : -0.5)); @@ -318,7 +328,7 @@ CV_INLINE int cvRound( double value ) } #if defined __SSE2__ || (defined _M_IX86_FP && 2 == _M_IX86_FP) -#include "emmintrin.h" +# include "emmintrin.h" #endif CV_INLINE int cvFloor( double value ) @@ -1886,6 +1896,6 @@ typedef struct CvModuleInfo } CvModuleInfo; -#endif /*_CXCORE_TYPES_H_*/ +#endif /*__OPENCV_CORE_TYPES_H__*/ /* End of file. */ diff --git a/modules/core/perf/perf_precomp.hpp b/modules/core/perf/perf_precomp.hpp index 901f889..8e56cbc 100644 --- a/modules/core/perf/perf_precomp.hpp +++ b/modules/core/perf/perf_precomp.hpp @@ -3,7 +3,7 @@ #include "opencv2/ts/ts.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/core/perf/perf_stat.cpp b/modules/core/perf/perf_stat.cpp index 418cb24..79e849e 100644 --- a/modules/core/perf/perf_stat.cpp +++ b/modules/core/perf/perf_stat.cpp @@ -28,11 +28,11 @@ PERF_TEST_P(Size_MatType, mean, TYPICAL_MATS) Mat src(sz, type); Scalar s; - + declare.in(src, WARMUP_RNG).out(s); - + TEST_CYCLE() s = mean(src); - + SANITY_CHECK(s, 1e-6); } @@ -44,11 +44,11 @@ PERF_TEST_P(Size_MatType, mean_mask, TYPICAL_MATS) Mat src(sz, type); Mat mask = Mat::ones(src.size(), CV_8U); Scalar s; - + declare.in(src, WARMUP_RNG).in(mask).out(s); - + TEST_CYCLE() s = mean(src, mask); - + SANITY_CHECK(s, 1e-6); } @@ -64,7 +64,7 @@ PERF_TEST_P(Size_MatType, meanStdDev, TYPICAL_MATS) declare.in(src, WARMUP_RNG).out(mean, dev); TEST_CYCLE() meanStdDev(src, mean, dev); - + SANITY_CHECK(mean, 1e-6); SANITY_CHECK(dev, 1e-6); } @@ -80,9 +80,9 @@ PERF_TEST_P(Size_MatType, meanStdDev_mask, TYPICAL_MATS) Scalar dev; declare.in(src, WARMUP_RNG).in(mask).out(mean, dev); - + TEST_CYCLE() meanStdDev(src, mean, dev, mask); - + SANITY_CHECK(mean, 1e-6); SANITY_CHECK(dev, 1e-6); } @@ -96,8 +96,8 @@ PERF_TEST_P(Size_MatType, countNonZero, testing::Combine( testing::Values( TYPIC int cnt = 0; declare.in(src, WARMUP_RNG); - + TEST_CYCLE() cnt = countNonZero(src); - + SANITY_CHECK(cnt); } diff --git a/modules/core/src/alloc.cpp b/modules/core/src/alloc.cpp index dfe7252..1944ed1 100644 --- a/modules/core/src/alloc.cpp +++ b/modules/core/src/alloc.cpp @@ -55,7 +55,9 @@ static void* OutOfMemoryError(size_t size) #if CV_USE_SYSTEM_MALLOC +#if defined WIN32 || defined _WIN32 void deleteThreadAllocData() {} +#endif void* fastMalloc( size_t size ) { @@ -66,14 +68,14 @@ void* fastMalloc( size_t size ) adata[-1] = udata; return adata; } - + void fastFree(void* ptr) { if(ptr) { uchar* udata = ((uchar**)ptr)[-1]; CV_DbgAssert(udata < (uchar*)ptr && - ((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+CV_MALLOC_ALIGN)); + ((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+CV_MALLOC_ALIGN)); free(udata); } } @@ -388,7 +390,7 @@ struct ThreadData #ifdef WIN32 #ifdef WINCE -# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF) +# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF) #endif //WINCE static DWORD tlsKey; @@ -535,7 +537,7 @@ void* fastMalloc( size_t size ) freePtr = block; if( !data ) { - block = gcPtr; + block = gcPtr; for( int k = 0; k < 2; k++ ) { SANITY_CHECK(block); @@ -620,7 +622,7 @@ void fastFree( void* ptr ) Block*& startPtr = tls->bins[idx][START]; Block*& freePtr = tls->bins[idx][FREE]; Block*& gcPtr = tls->bins[idx][GC]; - + if( block == block->next ) { CV_DbgAssert( startPtr == block && freePtr == block && gcPtr == block ); diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 454c65c..e252a28 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -974,7 +974,7 @@ void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t bl scbuf[i] = scbuf[i - esz]; } -void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst, +static void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst, InputArray _mask, const BinaryFunc* tab, bool bitwise) { int kind1 = _src1.kind(), kind2 = _src2.kind(); @@ -1216,7 +1216,7 @@ void cv::min(const Mat& src1, double src2, Mat& dst) namespace cv { -void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, +static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, InputArray _mask, int dtype, BinaryFunc* tab, bool muldiv=false, void* usrdata=0) { int kind1 = _src1.kind(), kind2 = _src2.kind(); diff --git a/modules/core/src/cmdparser.cpp b/modules/core/src/cmdparser.cpp index aee5ff9..b5c838c 100644 --- a/modules/core/src/cmdparser.cpp +++ b/modules/core/src/cmdparser.cpp @@ -6,6 +6,7 @@ using namespace std; using namespace cv; +namespace { void helpParser() { printf("\nThe CommandLineParser class is designed for command line arguments parsing\n" @@ -89,6 +90,8 @@ string del_space(string name) return name; } +}//namespace + CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys) { std::string keys_buffer; diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 9a95019..e391b15 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -53,7 +53,7 @@ static const float atan2_p1 = 0.9997878412794807f*(float)(180/CV_PI); static const float atan2_p3 = -0.3258083974640975f*(float)(180/CV_PI); static const float atan2_p5 = 0.1555786518463281f*(float)(180/CV_PI); static const float atan2_p7 = -0.04432655554792128f*(float)(180/CV_PI); - + float fastAtan2( float y, float x ) { float ax = std::abs(x), ay = std::abs(y); @@ -109,18 +109,18 @@ static void FastAtan2_32f(const float *Y, const float *X, float *angle, int len, a = _mm_mul_ps(_mm_add_ps(a, p5), c2); a = _mm_mul_ps(_mm_add_ps(a, p3), c2); a = _mm_mul_ps(_mm_add_ps(a, p1), c); - + __m128 b = _mm_sub_ps(_90, a); a = _mm_xor_ps(a, _mm_and_ps(_mm_xor_ps(a, b), mask)); - + b = _mm_sub_ps(_180, a); mask = _mm_cmplt_ps(x, z); a = _mm_xor_ps(a, _mm_and_ps(_mm_xor_ps(a, b), mask)); - + b = _mm_sub_ps(_360, a); mask = _mm_cmplt_ps(y, z); a = _mm_xor_ps(a, _mm_and_ps(_mm_xor_ps(a, b), mask)); - + a = _mm_mul_ps(a, scale4); _mm_storeu_ps(angle + i, a); } @@ -197,7 +197,7 @@ float cubeRoot( float value ) static void Magnitude_32f(const float* x, const float* y, float* mag, int len) { int i = 0; - + #if CV_SSE if( USE_SSE2 ) { @@ -223,8 +223,8 @@ static void Magnitude_32f(const float* x, const float* y, float* mag, int len) static void Magnitude_64f(const double* x, const double* y, double* mag, int len) { int i = 0; - -#if CV_SSE2 + +#if CV_SSE2 if( USE_SSE2 ) { for( ; i <= len - 4; i += 4 ) @@ -238,7 +238,7 @@ static void Magnitude_64f(const double* x, const double* y, double* mag, int len } } #endif - + for( ; i < len; i++ ) { double x0 = x[i], y0 = y[i]; @@ -246,14 +246,14 @@ static void Magnitude_64f(const double* x, const double* y, double* mag, int len } } - + static void InvSqrt_32f(const float* src, float* dst, int len) { int i = 0; - -#if CV_SSE + +#if CV_SSE if( USE_SSE2 ) - { + { __m128 _0_5 = _mm_set1_ps(0.5f), _1_5 = _mm_set1_ps(1.5f); if( (((size_t)src|(size_t)dst) & 15) == 0 ) for( ; i <= len - 8; i += 8 ) @@ -277,24 +277,24 @@ static void InvSqrt_32f(const float* src, float* dst, int len) } } #endif - + for( ; i < len; i++ ) dst[i] = 1/std::sqrt(src[i]); } - + static void InvSqrt_64f(const double* src, double* dst, int len) { for( int i = 0; i < len; i++ ) dst[i] = 1/std::sqrt(src[i]); -} - - +} + + static void Sqrt_32f(const float* src, float* dst, int len) { int i = 0; - -#if CV_SSE + +#if CV_SSE if( USE_SSE2 ) { if( (((size_t)src|(size_t)dst) & 15) == 0 ) @@ -312,18 +312,18 @@ static void Sqrt_32f(const float* src, float* dst, int len) _mm_storeu_ps(dst + i, t0); _mm_storeu_ps(dst + i + 4, t1); } } -#endif - +#endif + for( ; i < len; i++ ) dst[i] = std::sqrt(src[i]); } - + static void Sqrt_64f(const double* src, double* dst, int len) { int i = 0; - -#if CV_SSE2 + +#if CV_SSE2 if( USE_SSE2 ) { if( (((size_t)src|(size_t)dst) & 15) == 0 ) @@ -342,7 +342,7 @@ static void Sqrt_64f(const double* src, double* dst, int len) } } #endif - + for( ; i < len; i++ ) dst[i] = std::sqrt(src[i]); } @@ -359,12 +359,12 @@ void magnitude( InputArray src1, InputArray src2, OutputArray dst ) CV_Assert( X.size == Y.size && type == Y.type() && (depth == CV_32F || depth == CV_64F)); dst.create(X.dims, X.size, X.type()); Mat Mag = dst.getMat(); - + const Mat* arrays[] = {&X, &Y, &Mag, 0}; uchar* ptrs[3]; NAryMatIterator it(arrays, ptrs); int len = (int)it.size*cn; - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { if( depth == CV_32F ) @@ -382,7 +382,7 @@ void magnitude( InputArray src1, InputArray src2, OutputArray dst ) } } - + void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegrees ) { Mat X = src1.getMat(), Y = src2.getMat(); @@ -390,7 +390,7 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre CV_Assert( X.size == Y.size && type == Y.type() && (depth == CV_32F || depth == CV_64F)); dst.create( X.dims, X.size, type ); Mat Angle = dst.getMat(); - + const Mat* arrays[] = {&X, &Y, &Angle, 0}; uchar* ptrs[3]; NAryMatIterator it(arrays, ptrs); @@ -398,7 +398,7 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre float* buf[2] = {0, 0}; int j, k, total = (int)(it.size*cn), blockSize = total; size_t esz1 = X.elemSize1(); - + if( depth == CV_64F ) { blockSize = std::min(blockSize, ((BLOCK_SIZE+cn-1)/cn)*cn); @@ -406,7 +406,7 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre buf[0] = _buf; buf[1] = buf[0] + blockSize; } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -427,7 +427,7 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre buf[0][k] = (float)x[k]; buf[1][k] = (float)y[k]; } - + FastAtan2_32f( buf[1], buf[0], buf[0], len, angleInDegrees ); for( k = 0; k < len; k++ ) angle[k] = buf[0][k]; @@ -438,8 +438,8 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre } } } - - + + void cartToPolar( InputArray src1, InputArray src2, OutputArray dst1, OutputArray dst2, bool angleInDegrees ) { @@ -449,7 +449,7 @@ void cartToPolar( InputArray src1, InputArray src2, dst1.create( X.dims, X.size, type ); dst2.create( X.dims, X.size, type ); Mat Mag = dst1.getMat(), Angle = dst2.getMat(); - + const Mat* arrays[] = {&X, &Y, &Mag, &Angle, 0}; uchar* ptrs[4]; NAryMatIterator it(arrays, ptrs); @@ -457,14 +457,14 @@ void cartToPolar( InputArray src1, InputArray src2, float* buf[2] = {0, 0}; int j, k, total = (int)(it.size*cn), blockSize = std::min(total, ((BLOCK_SIZE+cn-1)/cn)*cn); size_t esz1 = X.elemSize1(); - + if( depth == CV_64F ) { _buf.allocate(blockSize*2); buf[0] = _buf; buf[1] = buf[0] + blockSize; } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -481,14 +481,14 @@ void cartToPolar( InputArray src1, InputArray src2, { const double *x = (const double*)ptrs[0], *y = (const double*)ptrs[1]; double *angle = (double*)ptrs[3]; - + Magnitude_64f(x, y, (double*)ptrs[2], len); for( k = 0; k < len; k++ ) { buf[0][k] = (float)x[k]; buf[1][k] = (float)y[k]; } - + FastAtan2_32f( buf[1], buf[0], buf[0], len, angleInDegrees ); for( k = 0; k < len; k++ ) angle[k] = buf[0][k]; @@ -595,7 +595,7 @@ void polarToCart( InputArray src1, InputArray src2, dst1.create( Angle.dims, Angle.size, type ); dst2.create( Angle.dims, Angle.size, type ); Mat X = dst1.getMat(), Y = dst2.getMat(); - + const Mat* arrays[] = {&Mag, &Angle, &X, &Y, 0}; uchar* ptrs[4]; NAryMatIterator it(arrays, ptrs); @@ -603,14 +603,14 @@ void polarToCart( InputArray src1, InputArray src2, float* buf[2] = {0, 0}; int j, k, total = (int)(it.size*cn), blockSize = std::min(total, ((BLOCK_SIZE+cn-1)/cn)*cn); size_t esz1 = Angle.elemSize1(); - + if( depth == CV_64F ) { _buf.allocate(blockSize*2); buf[0] = _buf; buf[1] = buf[0] + blockSize; } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -620,7 +620,7 @@ void polarToCart( InputArray src1, InputArray src2, { const float *mag = (const float*)ptrs[0], *angle = (const float*)ptrs[1]; float *x = (float*)ptrs[2], *y = (float*)ptrs[3]; - + SinCos_32f( angle, y, x, len, angleInDegrees ); if( mag ) for( k = 0; k < len; k++ ) @@ -633,10 +633,10 @@ void polarToCart( InputArray src1, InputArray src2, { const double *mag = (const double*)ptrs[0], *angle = (const double*)ptrs[1]; double *x = (double*)ptrs[2], *y = (double*)ptrs[3]; - + for( k = 0; k < len; k++ ) buf[0][k] = (float)angle[k]; - + SinCos_32f( buf[0], buf[1], buf[0], len, angleInDegrees ); if( mag ) for( k = 0; k < len; k++ ) @@ -650,7 +650,7 @@ void polarToCart( InputArray src1, InputArray src2, x[k] = buf[0][k]; y[k] = buf[1][k]; } } - + if( ptrs[0] ) ptrs[0] += len*esz1; ptrs[1] += len*esz1; @@ -759,8 +759,8 @@ static const double expTab[] = { (!defined __APPLE__ && defined __GNUC__ && __GNUC__*100 + __GNUC_MINOR__ < 402) #undef CV_SSE2 #define CV_SSE2 0 -#endif - +#endif + static const double exp_prescale = 1.4426950408889634073599246810019 * (1 << EXPTAB_SCALE); static const double exp_postscale = 1./(1 << EXPTAB_SCALE); static const double exp_max_val = 3000.*(1 << EXPTAB_SCALE); // log10(DBL_MAX) < 3000 @@ -772,11 +772,11 @@ static void Exp_32f( const float *_x, float *y, int n ) A3 = (float)(.6931471805521448196800669615864773144641 / EXPPOLY_32F_A0), A2 = (float)(.2402265109513301490103372422686535526573 / EXPPOLY_32F_A0), A1 = (float)(.5550339366753125211915322047004666939128e-1 / EXPPOLY_32F_A0); - + #undef EXPPOLY #define EXPPOLY(x) \ (((((x) + A1)*(x) + A2)*(x) + A3)*(x) + A4) - + int i = 0; const Cv32suf* x = (const Cv32suf*)_x; Cv32suf buf[4]; @@ -788,90 +788,90 @@ static void Exp_32f( const float *_x, float *y, int n ) static const __m128 postscale4 = _mm_set1_ps((float)exp_postscale); static const __m128 maxval4 = _mm_set1_ps((float)(exp_max_val/exp_prescale)); static const __m128 minval4 = _mm_set1_ps((float)(-exp_max_val/exp_prescale)); - + static const __m128 mA1 = _mm_set1_ps(A1); static const __m128 mA2 = _mm_set1_ps(A2); static const __m128 mA3 = _mm_set1_ps(A3); static const __m128 mA4 = _mm_set1_ps(A4); bool y_aligned = (size_t)(void*)y % 16 == 0; - + ushort CV_DECL_ALIGNED(16) tab_idx[8]; - + for( ; i <= n - 8; i += 8 ) { __m128 xf0, xf1; xf0 = _mm_loadu_ps(&x[i].f); xf1 = _mm_loadu_ps(&x[i+4].f); __m128i xi0, xi1, xi2, xi3; - + xf0 = _mm_min_ps(_mm_max_ps(xf0, minval4), maxval4); xf1 = _mm_min_ps(_mm_max_ps(xf1, minval4), maxval4); - + __m128d xd0 = _mm_cvtps_pd(xf0); __m128d xd2 = _mm_cvtps_pd(_mm_movehl_ps(xf0, xf0)); __m128d xd1 = _mm_cvtps_pd(xf1); __m128d xd3 = _mm_cvtps_pd(_mm_movehl_ps(xf1, xf1)); - + xd0 = _mm_mul_pd(xd0, prescale2); xd2 = _mm_mul_pd(xd2, prescale2); xd1 = _mm_mul_pd(xd1, prescale2); xd3 = _mm_mul_pd(xd3, prescale2); - + xi0 = _mm_cvtpd_epi32(xd0); xi2 = _mm_cvtpd_epi32(xd2); - + xi1 = _mm_cvtpd_epi32(xd1); xi3 = _mm_cvtpd_epi32(xd3); - + xd0 = _mm_sub_pd(xd0, _mm_cvtepi32_pd(xi0)); xd2 = _mm_sub_pd(xd2, _mm_cvtepi32_pd(xi2)); xd1 = _mm_sub_pd(xd1, _mm_cvtepi32_pd(xi1)); xd3 = _mm_sub_pd(xd3, _mm_cvtepi32_pd(xi3)); - + xf0 = _mm_movelh_ps(_mm_cvtpd_ps(xd0), _mm_cvtpd_ps(xd2)); xf1 = _mm_movelh_ps(_mm_cvtpd_ps(xd1), _mm_cvtpd_ps(xd3)); - + xf0 = _mm_mul_ps(xf0, postscale4); xf1 = _mm_mul_ps(xf1, postscale4); xi0 = _mm_unpacklo_epi64(xi0, xi2); xi1 = _mm_unpacklo_epi64(xi1, xi3); xi0 = _mm_packs_epi32(xi0, xi1); - + _mm_store_si128((__m128i*)tab_idx, _mm_and_si128(xi0, _mm_set1_epi16(EXPTAB_MASK))); - + xi0 = _mm_add_epi16(_mm_srai_epi16(xi0, EXPTAB_SCALE), _mm_set1_epi16(127)); xi0 = _mm_max_epi16(xi0, _mm_setzero_si128()); xi0 = _mm_min_epi16(xi0, _mm_set1_epi16(255)); xi1 = _mm_unpackhi_epi16(xi0, _mm_setzero_si128()); xi0 = _mm_unpacklo_epi16(xi0, _mm_setzero_si128()); - + __m128d yd0 = _mm_unpacklo_pd(_mm_load_sd(expTab + tab_idx[0]), _mm_load_sd(expTab + tab_idx[1])); __m128d yd1 = _mm_unpacklo_pd(_mm_load_sd(expTab + tab_idx[2]), _mm_load_sd(expTab + tab_idx[3])); __m128d yd2 = _mm_unpacklo_pd(_mm_load_sd(expTab + tab_idx[4]), _mm_load_sd(expTab + tab_idx[5])); __m128d yd3 = _mm_unpacklo_pd(_mm_load_sd(expTab + tab_idx[6]), _mm_load_sd(expTab + tab_idx[7])); - + __m128 yf0 = _mm_movelh_ps(_mm_cvtpd_ps(yd0), _mm_cvtpd_ps(yd1)); __m128 yf1 = _mm_movelh_ps(_mm_cvtpd_ps(yd2), _mm_cvtpd_ps(yd3)); yf0 = _mm_mul_ps(yf0, _mm_castsi128_ps(_mm_slli_epi32(xi0, 23))); yf1 = _mm_mul_ps(yf1, _mm_castsi128_ps(_mm_slli_epi32(xi1, 23))); - + __m128 zf0 = _mm_add_ps(xf0, mA1); __m128 zf1 = _mm_add_ps(xf1, mA1); - + zf0 = _mm_add_ps(_mm_mul_ps(zf0, xf0), mA2); zf1 = _mm_add_ps(_mm_mul_ps(zf1, xf1), mA2); - + zf0 = _mm_add_ps(_mm_mul_ps(zf0, xf0), mA3); zf1 = _mm_add_ps(_mm_mul_ps(zf1, xf1), mA3); - + zf0 = _mm_add_ps(_mm_mul_ps(zf0, xf0), mA4); zf1 = _mm_add_ps(_mm_mul_ps(zf1, xf1), mA4); - + zf0 = _mm_mul_ps(zf0, yf0); zf1 = _mm_mul_ps(zf1, yf1); - + if( y_aligned ) { _mm_store_ps(y + i, zf0); @@ -893,77 +893,77 @@ static void Exp_32f( const float *_x, float *y, int n ) double x2 = x[i + 2].f * exp_prescale; double x3 = x[i + 3].f * exp_prescale; int val0, val1, val2, val3, t; - + if( ((x[i].i >> 23) & 255) > 127 + 10 ) x0 = x[i].i < 0 ? -exp_max_val : exp_max_val; - + if( ((x[i+1].i >> 23) & 255) > 127 + 10 ) x1 = x[i+1].i < 0 ? -exp_max_val : exp_max_val; - + if( ((x[i+2].i >> 23) & 255) > 127 + 10 ) x2 = x[i+2].i < 0 ? -exp_max_val : exp_max_val; - + if( ((x[i+3].i >> 23) & 255) > 127 + 10 ) x3 = x[i+3].i < 0 ? -exp_max_val : exp_max_val; - + val0 = cvRound(x0); val1 = cvRound(x1); val2 = cvRound(x2); val3 = cvRound(x3); - + x0 = (x0 - val0)*exp_postscale; x1 = (x1 - val1)*exp_postscale; x2 = (x2 - val2)*exp_postscale; x3 = (x3 - val3)*exp_postscale; - + t = (val0 >> EXPTAB_SCALE) + 127; t = !(t & ~255) ? t : t < 0 ? 0 : 255; buf[0].i = t << 23; - + t = (val1 >> EXPTAB_SCALE) + 127; t = !(t & ~255) ? t : t < 0 ? 0 : 255; buf[1].i = t << 23; - + t = (val2 >> EXPTAB_SCALE) + 127; t = !(t & ~255) ? t : t < 0 ? 0 : 255; buf[2].i = t << 23; - + t = (val3 >> EXPTAB_SCALE) + 127; t = !(t & ~255) ? t : t < 0 ? 0 : 255; buf[3].i = t << 23; - + x0 = buf[0].f * expTab[val0 & EXPTAB_MASK] * EXPPOLY( x0 ); x1 = buf[1].f * expTab[val1 & EXPTAB_MASK] * EXPPOLY( x1 ); - + y[i] = (float)x0; y[i + 1] = (float)x1; - + x2 = buf[2].f * expTab[val2 & EXPTAB_MASK] * EXPPOLY( x2 ); x3 = buf[3].f * expTab[val3 & EXPTAB_MASK] * EXPPOLY( x3 ); - + y[i + 2] = (float)x2; y[i + 3] = (float)x3; } - + for( ; i < n; i++ ) { double x0 = x[i].f * exp_prescale; int val0, t; - + if( ((x[i].i >> 23) & 255) > 127 + 10 ) x0 = x[i].i < 0 ? -exp_max_val : exp_max_val; - + val0 = cvRound(x0); t = (val0 >> EXPTAB_SCALE) + 127; t = !(t & ~255) ? t : t < 0 ? 0 : 255; - + buf[0].i = t << 23; x0 = (x0 - val0)*exp_postscale; - + y[i] = (float)(buf[0].f * expTab[val0 & EXPTAB_MASK] * EXPPOLY(x0)); } } - + static void Exp_64f( const double *_x, double *y, int n ) { @@ -974,14 +974,14 @@ static void Exp_64f( const double *_x, double *y, int n ) A2 = .55504108793649567998466049042729e-1 / EXPPOLY_32F_A0, A1 = .96180973140732918010002372686186e-2 / EXPPOLY_32F_A0, A0 = .13369713757180123244806654839424e-2 / EXPPOLY_32F_A0; - + #undef EXPPOLY #define EXPPOLY(x) (((((A0*(x) + A1)*(x) + A2)*(x) + A3)*(x) + A4)*(x) + A5) - + int i = 0; Cv64suf buf[4]; const Cv64suf* x = (const Cv64suf*)_x; - + #if CV_SSE2 if( USE_SSE2 ) { @@ -989,16 +989,16 @@ static void Exp_64f( const double *_x, double *y, int n ) static const __m128d postscale2 = _mm_set1_pd(exp_postscale); static const __m128d maxval2 = _mm_set1_pd(exp_max_val); static const __m128d minval2 = _mm_set1_pd(-exp_max_val); - + static const __m128d mA0 = _mm_set1_pd(A0); static const __m128d mA1 = _mm_set1_pd(A1); static const __m128d mA2 = _mm_set1_pd(A2); static const __m128d mA3 = _mm_set1_pd(A3); static const __m128d mA4 = _mm_set1_pd(A4); static const __m128d mA5 = _mm_set1_pd(A5); - + int CV_DECL_ALIGNED(16) tab_idx[4]; - + for( ; i <= n - 4; i += 4 ) { __m128d xf0 = _mm_loadu_pd(&x[i].f), xf1 = _mm_loadu_pd(&x[i+2].f); @@ -1007,15 +1007,15 @@ static void Exp_64f( const double *_x, double *y, int n ) xf1 = _mm_min_pd(_mm_max_pd(xf1, minval2), maxval2); xf0 = _mm_mul_pd(xf0, prescale2); xf1 = _mm_mul_pd(xf1, prescale2); - + xi0 = _mm_cvtpd_epi32(xf0); xi1 = _mm_cvtpd_epi32(xf1); xf0 = _mm_mul_pd(_mm_sub_pd(xf0, _mm_cvtepi32_pd(xi0)), postscale2); xf1 = _mm_mul_pd(_mm_sub_pd(xf1, _mm_cvtepi32_pd(xi1)), postscale2); - + xi0 = _mm_unpacklo_epi64(xi0, xi1); _mm_store_si128((__m128i*)tab_idx, _mm_and_si128(xi0, _mm_set1_epi32(EXPTAB_MASK))); - + xi0 = _mm_add_epi32(_mm_srai_epi32(xi0, EXPTAB_SCALE), _mm_set1_epi32(1023)); xi0 = _mm_packs_epi32(xi0, xi0); xi0 = _mm_max_epi16(xi0, _mm_setzero_si128()); @@ -1023,30 +1023,30 @@ static void Exp_64f( const double *_x, double *y, int n ) xi0 = _mm_unpacklo_epi16(xi0, _mm_setzero_si128()); xi1 = _mm_unpackhi_epi32(xi0, _mm_setzero_si128()); xi0 = _mm_unpacklo_epi32(xi0, _mm_setzero_si128()); - + __m128d yf0 = _mm_unpacklo_pd(_mm_load_sd(expTab + tab_idx[0]), _mm_load_sd(expTab + tab_idx[1])); __m128d yf1 = _mm_unpacklo_pd(_mm_load_sd(expTab + tab_idx[2]), _mm_load_sd(expTab + tab_idx[3])); yf0 = _mm_mul_pd(yf0, _mm_castsi128_pd(_mm_slli_epi64(xi0, 52))); yf1 = _mm_mul_pd(yf1, _mm_castsi128_pd(_mm_slli_epi64(xi1, 52))); - + __m128d zf0 = _mm_add_pd(_mm_mul_pd(mA0, xf0), mA1); __m128d zf1 = _mm_add_pd(_mm_mul_pd(mA0, xf1), mA1); - + zf0 = _mm_add_pd(_mm_mul_pd(zf0, xf0), mA2); zf1 = _mm_add_pd(_mm_mul_pd(zf1, xf1), mA2); - + zf0 = _mm_add_pd(_mm_mul_pd(zf0, xf0), mA3); zf1 = _mm_add_pd(_mm_mul_pd(zf1, xf1), mA3); - + zf0 = _mm_add_pd(_mm_mul_pd(zf0, xf0), mA4); zf1 = _mm_add_pd(_mm_mul_pd(zf1, xf1), mA4); - + zf0 = _mm_add_pd(_mm_mul_pd(zf0, xf0), mA5); zf1 = _mm_add_pd(_mm_mul_pd(zf1, xf1), mA5); - + zf0 = _mm_mul_pd(zf0, yf0); zf1 = _mm_mul_pd(zf1, yf1); - + _mm_storeu_pd(y + i, zf0); _mm_storeu_pd(y + i + 2, zf1); } @@ -1059,81 +1059,81 @@ static void Exp_64f( const double *_x, double *y, int n ) double x1 = x[i + 1].f * exp_prescale; double x2 = x[i + 2].f * exp_prescale; double x3 = x[i + 3].f * exp_prescale; - + double y0, y1, y2, y3; int val0, val1, val2, val3, t; - + t = (int)(x[i].i >> 52); if( (t & 2047) > 1023 + 10 ) x0 = t < 0 ? -exp_max_val : exp_max_val; - + t = (int)(x[i+1].i >> 52); if( (t & 2047) > 1023 + 10 ) x1 = t < 0 ? -exp_max_val : exp_max_val; - + t = (int)(x[i+2].i >> 52); if( (t & 2047) > 1023 + 10 ) x2 = t < 0 ? -exp_max_val : exp_max_val; - + t = (int)(x[i+3].i >> 52); if( (t & 2047) > 1023 + 10 ) x3 = t < 0 ? -exp_max_val : exp_max_val; - + val0 = cvRound(x0); val1 = cvRound(x1); val2 = cvRound(x2); val3 = cvRound(x3); - + x0 = (x0 - val0)*exp_postscale; x1 = (x1 - val1)*exp_postscale; x2 = (x2 - val2)*exp_postscale; x3 = (x3 - val3)*exp_postscale; - + t = (val0 >> EXPTAB_SCALE) + 1023; t = !(t & ~2047) ? t : t < 0 ? 0 : 2047; buf[0].i = (int64)t << 52; - + t = (val1 >> EXPTAB_SCALE) + 1023; t = !(t & ~2047) ? t : t < 0 ? 0 : 2047; buf[1].i = (int64)t << 52; - + t = (val2 >> EXPTAB_SCALE) + 1023; t = !(t & ~2047) ? t : t < 0 ? 0 : 2047; buf[2].i = (int64)t << 52; - + t = (val3 >> EXPTAB_SCALE) + 1023; t = !(t & ~2047) ? t : t < 0 ? 0 : 2047; buf[3].i = (int64)t << 52; - + y0 = buf[0].f * expTab[val0 & EXPTAB_MASK] * EXPPOLY( x0 ); y1 = buf[1].f * expTab[val1 & EXPTAB_MASK] * EXPPOLY( x1 ); - + y[i] = y0; y[i + 1] = y1; - + y2 = buf[2].f * expTab[val2 & EXPTAB_MASK] * EXPPOLY( x2 ); y3 = buf[3].f * expTab[val3 & EXPTAB_MASK] * EXPPOLY( x3 ); - + y[i + 2] = y2; y[i + 3] = y3; } - + for( ; i < n; i++ ) { double x0 = x[i].f * exp_prescale; int val0, t; - + t = (int)(x[i].i >> 52); if( (t & 2047) > 1023 + 10 ) x0 = t < 0 ? -exp_max_val : exp_max_val; - + val0 = cvRound(x0); t = (val0 >> EXPTAB_SCALE) + 1023; t = !(t & ~2047) ? t : t < 0 ? 0 : 2047; - + buf[0].i = (int64)t << 52; x0 = (x0 - val0)*exp_postscale; - + y[i] = buf[0].f * expTab[val0 & EXPTAB_MASK] * EXPPOLY( x0 ); } } @@ -1153,17 +1153,17 @@ void exp( InputArray _src, OutputArray _dst ) { Mat src = _src.getMat(); int type = src.type(), depth = src.depth(), cn = src.channels(); - + _dst.create( src.dims, src.size, type ); Mat dst = _dst.getMat(); - + CV_Assert( depth == CV_32F || depth == CV_64F ); - + const Mat* arrays[] = {&src, &dst, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); int len = (int)(it.size*cn); - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { if( depth == CV_32F ) @@ -1470,26 +1470,26 @@ static void Log_32f( const float *_x, float *y, int n ) static const __m128d ln2_2 = _mm_set1_pd(ln_2); static const __m128 _1_4 = _mm_set1_ps(1.f); static const __m128 shift4 = _mm_set1_ps(-1.f/512); - + static const __m128 mA0 = _mm_set1_ps(A0); static const __m128 mA1 = _mm_set1_ps(A1); static const __m128 mA2 = _mm_set1_ps(A2); - + int CV_DECL_ALIGNED(16) idx[4]; - + for( ; i <= n - 4; i += 4 ) - { + { __m128i h0 = _mm_loadu_si128((const __m128i*)(x + i)); __m128i yi0 = _mm_sub_epi32(_mm_and_si128(_mm_srli_epi32(h0, 23), _mm_set1_epi32(255)), _mm_set1_epi32(127)); __m128d yd0 = _mm_mul_pd(_mm_cvtepi32_pd(yi0), ln2_2); __m128d yd1 = _mm_mul_pd(_mm_cvtepi32_pd(_mm_unpackhi_epi64(yi0,yi0)), ln2_2); - + __m128i xi0 = _mm_or_si128(_mm_and_si128(h0, _mm_set1_epi32(LOGTAB_MASK2_32F)), _mm_set1_epi32(127 << 23)); - + h0 = _mm_and_si128(_mm_srli_epi32(h0, 23 - LOGTAB_SCALE - 1), _mm_set1_epi32(LOGTAB_MASK*2)); _mm_store_si128((__m128i*)idx, h0); h0 = _mm_cmpeq_epi32(h0, _mm_set1_epi32(510)); - + __m128d t0, t1, t2, t3, t4; t0 = _mm_load_pd(icvLogTab + idx[0]); t2 = _mm_load_pd(icvLogTab + idx[1]); @@ -1499,21 +1499,21 @@ static void Log_32f( const float *_x, float *y, int n ) t4 = _mm_load_pd(icvLogTab + idx[3]); t3 = _mm_unpackhi_pd(t2, t4); t2 = _mm_unpacklo_pd(t2, t4); - + yd0 = _mm_add_pd(yd0, t0); yd1 = _mm_add_pd(yd1, t2); - + __m128 yf0 = _mm_movelh_ps(_mm_cvtpd_ps(yd0), _mm_cvtpd_ps(yd1)); - + __m128 xf0 = _mm_sub_ps(_mm_castsi128_ps(xi0), _1_4); xf0 = _mm_mul_ps(xf0, _mm_movelh_ps(_mm_cvtpd_ps(t1), _mm_cvtpd_ps(t3))); xf0 = _mm_add_ps(xf0, _mm_and_ps(_mm_castsi128_ps(h0), shift4)); - + __m128 zf0 = _mm_mul_ps(xf0, mA0); zf0 = _mm_mul_ps(_mm_add_ps(zf0, mA1), xf0); zf0 = _mm_mul_ps(_mm_add_ps(zf0, mA2), xf0); yf0 = _mm_add_ps(yf0, zf0); - + _mm_storeu_ps(y + i, yf0); } } @@ -1626,10 +1626,10 @@ static void Log_64f( const double *x, double *y, int n ) static const __m128d ln2_2 = _mm_set1_pd(ln_2); static const __m128d _1_2 = _mm_set1_pd(1.); static const __m128d shift2 = _mm_set1_pd(-1./512); - + static const __m128i log_and_mask2 = _mm_set_epi32(LOGTAB_MASK2, 0xffffffff, LOGTAB_MASK2, 0xffffffff); static const __m128i log_or_mask2 = _mm_set_epi32(1023 << 20, 0, 1023 << 20, 0); - + static const __m128d mA0 = _mm_set1_pd(A0); static const __m128d mA1 = _mm_set1_pd(A1); static const __m128d mA2 = _mm_set1_pd(A2); @@ -1638,28 +1638,28 @@ static void Log_64f( const double *x, double *y, int n ) static const __m128d mA5 = _mm_set1_pd(A5); static const __m128d mA6 = _mm_set1_pd(A6); static const __m128d mA7 = _mm_set1_pd(A7); - + int CV_DECL_ALIGNED(16) idx[4]; - + for( ; i <= n - 4; i += 4 ) { __m128i h0 = _mm_loadu_si128((const __m128i*)(x + i)); __m128i h1 = _mm_loadu_si128((const __m128i*)(x + i + 2)); - + __m128d xd0 = _mm_castsi128_pd(_mm_or_si128(_mm_and_si128(h0, log_and_mask2), log_or_mask2)); __m128d xd1 = _mm_castsi128_pd(_mm_or_si128(_mm_and_si128(h1, log_and_mask2), log_or_mask2)); - + h0 = _mm_unpackhi_epi32(_mm_unpacklo_epi32(h0, h1), _mm_unpackhi_epi32(h0, h1)); - + __m128i yi0 = _mm_sub_epi32(_mm_and_si128(_mm_srli_epi32(h0, 20), _mm_set1_epi32(2047)), _mm_set1_epi32(1023)); __m128d yd0 = _mm_mul_pd(_mm_cvtepi32_pd(yi0), ln2_2); __m128d yd1 = _mm_mul_pd(_mm_cvtepi32_pd(_mm_unpackhi_epi64(yi0, yi0)), ln2_2); - + h0 = _mm_and_si128(_mm_srli_epi32(h0, 20 - LOGTAB_SCALE - 1), _mm_set1_epi32(LOGTAB_MASK * 2)); _mm_store_si128((__m128i*)idx, h0); h0 = _mm_cmpeq_epi32(h0, _mm_set1_epi32(510)); - + __m128d t0, t1, t2, t3, t4; t0 = _mm_load_pd(icvLogTab + idx[0]); t2 = _mm_load_pd(icvLogTab + idx[1]); @@ -1669,16 +1669,16 @@ static void Log_64f( const double *x, double *y, int n ) t4 = _mm_load_pd(icvLogTab + idx[3]); t3 = _mm_unpackhi_pd(t2, t4); t2 = _mm_unpacklo_pd(t2, t4); - + yd0 = _mm_add_pd(yd0, t0); yd1 = _mm_add_pd(yd1, t2); - + xd0 = _mm_mul_pd(_mm_sub_pd(xd0, _1_2), t1); xd1 = _mm_mul_pd(_mm_sub_pd(xd1, _1_2), t3); - + xd0 = _mm_add_pd(xd0, _mm_and_pd(_mm_castsi128_pd(_mm_unpacklo_epi32(h0, h0)), shift2)); xd1 = _mm_add_pd(xd1, _mm_and_pd(_mm_castsi128_pd(_mm_unpackhi_epi32(h0, h0)), shift2)); - + __m128d zd0 = _mm_mul_pd(xd0, mA0); __m128d zd1 = _mm_mul_pd(xd1, mA0); zd0 = _mm_mul_pd(_mm_add_pd(zd0, mA1), xd0); @@ -1695,10 +1695,10 @@ static void Log_64f( const double *x, double *y, int n ) zd1 = _mm_mul_pd(_mm_add_pd(zd1, mA6), xd1); zd0 = _mm_mul_pd(_mm_add_pd(zd0, mA7), xd0); zd1 = _mm_mul_pd(_mm_add_pd(zd1, mA7), xd1); - + yd0 = _mm_add_pd(yd0, zd0); yd1 = _mm_add_pd(yd1, zd1); - + _mm_storeu_pd(y + i, yd0); _mm_storeu_pd(y + i + 2, yd1); } @@ -1769,7 +1769,7 @@ static void Log_64f( const double *x, double *y, int n ) y[i + 2] = y2; y[i + 3] = y3; } - + for( ; i < n; i++ ) { int h0 = X[i].i.hi; @@ -1798,17 +1798,17 @@ void log( InputArray _src, OutputArray _dst ) { Mat src = _src.getMat(); int type = src.type(), depth = src.depth(), cn = src.channels(); - + _dst.create( src.dims, src.size, type ); Mat dst = _dst.getMat(); - + CV_Assert( depth == CV_32F || depth == CV_64F ); - + const Mat* arrays[] = {&src, &dst, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); int len = (int)(it.size*cn); - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { if( depth == CV_32F ) @@ -1816,7 +1816,7 @@ void log( InputArray _src, OutputArray _dst ) else Log_64f( (const double*)ptrs[0], (double*)ptrs[1], len ); } -} +} /****************************************************************************************\ * P O W E R * @@ -1844,63 +1844,63 @@ iPow_( const T* src, T* dst, int len, int power ) } } - -void iPow8u(const uchar* src, uchar* dst, int len, int power) + +static void iPow8u(const uchar* src, uchar* dst, int len, int power) { iPow_(src, dst, len, power); } -void iPow8s(const schar* src, schar* dst, int len, int power) +static void iPow8s(const schar* src, schar* dst, int len, int power) { iPow_(src, dst, len, power); } - -void iPow16u(const ushort* src, ushort* dst, int len, int power) + +static void iPow16u(const ushort* src, ushort* dst, int len, int power) { iPow_(src, dst, len, power); } -void iPow16s(const short* src, short* dst, int len, int power) +static void iPow16s(const short* src, short* dst, int len, int power) { iPow_(src, dst, len, power); } - -void iPow32s(const int* src, int* dst, int len, int power) + +static void iPow32s(const int* src, int* dst, int len, int power) { iPow_(src, dst, len, power); } -void iPow32f(const float* src, float* dst, int len, int power) +static void iPow32f(const float* src, float* dst, int len, int power) { iPow_(src, dst, len, power); } -void iPow64f(const double* src, double* dst, int len, int power) +static void iPow64f(const double* src, double* dst, int len, int power) { iPow_(src, dst, len, power); } - + typedef void (*IPowFunc)( const uchar* src, uchar* dst, int len, int power ); - + static IPowFunc ipowTab[] = { (IPowFunc)iPow8u, (IPowFunc)iPow8s, (IPowFunc)iPow16u, (IPowFunc)iPow16s, (IPowFunc)iPow32s, (IPowFunc)iPow32f, (IPowFunc)iPow64f, 0 }; - + void pow( InputArray _src, double power, OutputArray _dst ) { Mat src = _src.getMat(); int type = src.type(), depth = src.depth(), cn = src.channels(); - + _dst.create( src.dims, src.size, type ); Mat dst = _dst.getMat(); - + int ipower = cvRound(power); bool is_ipower = false; - + if( fabs(ipower - power) < DBL_EPSILON ) { if( ipower < 0 ) @@ -1911,7 +1911,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) ipower = -ipower; src = dst; } - + switch( ipower ) { case 0: @@ -1929,17 +1929,17 @@ void pow( InputArray _src, double power, OutputArray _dst ) } else CV_Assert( depth == CV_32F || depth == CV_64F ); - + const Mat* arrays[] = {&src, &dst, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); int len = (int)(it.size*cn); - + if( is_ipower ) { IPowFunc func = ipowTab[depth]; CV_Assert( func != 0 ); - + for( size_t i = 0; i < it.nplanes; i++, ++it ) func( ptrs[0], ptrs[1], len, ipower ); } @@ -1948,7 +1948,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) MathFunc func = power < 0 ? (depth == CV_32F ? (MathFunc)InvSqrt_32f : (MathFunc)InvSqrt_64f) : (depth == CV_32F ? (MathFunc)Sqrt_32f : (MathFunc)Sqrt_64f); - + for( size_t i = 0; i < it.nplanes; i++, ++it ) func( ptrs[0], ptrs[1], len ); } @@ -1956,7 +1956,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) { int j, k, blockSize = std::min(len, ((BLOCK_SIZE + cn-1)/cn)*cn); size_t esz1 = src.elemSize1(); - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < len; j += blockSize ) @@ -1966,7 +1966,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) { const float* x = (const float*)ptrs[0]; float* y = (float*)ptrs[1]; - + Log_32f(x, y, bsz); for( k = 0; k < bsz; k++ ) y[k] = (float)(y[k]*power); @@ -1976,7 +1976,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) { const double* x = (const double*)ptrs[0]; double* y = (double*)ptrs[1]; - + Log_64f(x, y, bsz); for( k = 0; k < bsz; k++ ) y[k] *= power; @@ -2036,8 +2036,8 @@ template<> struct mat_type_assotiations template bool checkIntegerRange(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value) { - typedef mat_type_assotiations type_ass; - + typedef mat_type_assotiations type_ass; + if (minVal < type_ass::min_allowable && maxVal > type_ass::max_allowable) { return true; @@ -2051,23 +2051,23 @@ bool checkIntegerRange(cv::Mat src, Point& bad_pt, int minVal, int maxVal, doubl for (int j = 0; j < as_one_channel.rows; ++j) for (int i = 0; i < as_one_channel.cols; ++i) - { + { if (as_one_channel.at(j ,i) < minVal || as_one_channel.at(j ,i) > maxVal) - { - bad_pt.y = j ; + { + bad_pt.y = j ; bad_pt.x = i % src.channels(); bad_value = as_one_channel.at(j ,i); return false; } } bad_value = 0.0; - + return true; } -typedef bool (*check_range_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value); +typedef bool (*check_range_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value); -check_range_function check_range_functions[] = +check_range_function check_range_functions[] = { &checkIntegerRange, &checkIntegerRange, @@ -2085,7 +2085,7 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma const Mat* arrays[] = {&src, 0}; Mat planes[1]; NAryMatIterator it(arrays, planes); - + for ( size_t i = 0; i < it.nplanes; i++, ++it ) { if (!checkRange( it.planes[0], quiet, pt, minVal, maxVal )) @@ -2096,7 +2096,7 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma } return true; } - + int depth = src.depth(); Point badPt(-1, -1); double badValue = 0; @@ -2185,19 +2185,19 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma return badPt.x < 0; } - + void patchNaNs( InputOutputArray _a, double _val ) { Mat a = _a.getMat(); CV_Assert( a.depth() == CV_32F ); - + const Mat* arrays[] = {&a, 0}; int* ptrs[1]; NAryMatIterator it(arrays, (uchar**)ptrs); size_t len = it.size*a.channels(); Cv32suf val; val.f = (float)_val; - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { int* tptr = ptrs[0]; @@ -2207,22 +2207,22 @@ void patchNaNs( InputOutputArray _a, double _val ) } } - + void exp(const float* src, float* dst, int n) { Exp_32f(src, dst, n); } - + void log(const float* src, float* dst, int n) { Log_32f(src, dst, n); } - + void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees) { FastAtan2_32f(y, x, dst, n, angleInDegrees); } - + void magnitude(const float* x, const float* y, float* dst, int n) { Magnitude_32f(x, y, dst, n); @@ -2343,26 +2343,26 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) const int n0 = 3; Mat coeffs = _coeffs.getMat(); int ctype = coeffs.type(); - + CV_Assert( ctype == CV_32F || ctype == CV_64F ); CV_Assert( (coeffs.size() == Size(n0, 1) || coeffs.size() == Size(n0+1, 1) || coeffs.size() == Size(1, n0) || coeffs.size() == Size(1, n0+1)) ); - + _roots.create(n0, 1, ctype, -1, true, DEPTH_MASK_FLT); Mat roots = _roots.getMat(); - + int i = -1, n = 0; double a0 = 1., a1, a2, a3; double x0 = 0., x1 = 0., x2 = 0.; int ncoeffs = coeffs.rows + coeffs.cols - 1; - + if( ctype == CV_32FC1 ) { if( ncoeffs == 4 ) a0 = coeffs.at(++i); - + a1 = coeffs.at(i+1); a2 = coeffs.at(i+2); a3 = coeffs.at(i+3); @@ -2371,12 +2371,12 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) { if( ncoeffs == 4 ) a0 = coeffs.at(++i); - + a1 = coeffs.at(i+1); a2 = coeffs.at(i+2); a3 = coeffs.at(i+3); } - + if( a0 == 0 ) { if( a1 == 0 ) @@ -2419,12 +2419,12 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) a1 *= a0; a2 *= a0; a3 *= a0; - + double Q = (a1 * a1 - 3 * a2) * (1./9); double R = (2 * a1 * a1 * a1 - 9 * a1 * a2 + 27 * a3) * (1./54); double Qcubed = Q * Q * Q; double d = Qcubed - R * R; - + if( d >= 0 ) { double theta = acos(R / sqrt(Qcubed)); @@ -2448,7 +2448,7 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) n = 1; } } - + if( roots.type() == CV_32FC1 ) { roots.at(0) = (float)x0; @@ -2461,7 +2461,7 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots ) roots.at(1) = x1; roots.at(2) = x2; } - + return n; } @@ -2476,15 +2476,15 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) Mat coeffs0 = _coeffs0.getMat(); int ctype = _coeffs0.type(); int cdepth = CV_MAT_DEPTH(ctype); - + CV_Assert( CV_MAT_DEPTH(ctype) >= CV_32F && CV_MAT_CN(ctype) <= 2 ); CV_Assert( coeffs0.rows == 1 || coeffs0.cols == 1 ); - + int n = coeffs0.cols + coeffs0.rows - 2; - _roots0.create(n, 1, CV_MAKETYPE(cdepth, 2), -1, true, DEPTH_MASK_FLT); + _roots0.create(n, 1, CV_MAKETYPE(cdepth, 2), -1, true, DEPTH_MASK_FLT); Mat roots0 = _roots0.getMat(); - + AutoBuffer buf(n*2+2); C *coeffs = buf, *roots = coeffs + n + 1; Mat coeffs1(coeffs0.size(), CV_MAKETYPE(CV_64F, coeffs0.channels()), coeffs0.channels() == 2 ? coeffs : roots); diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 845bd89..5778ee3 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -62,18 +62,18 @@ void swap( Mat& a, Mat& b ) std::swap(a.dataend, b.dataend); std::swap(a.datalimit, b.datalimit); std::swap(a.allocator, b.allocator); - + std::swap(a.size.p, b.size.p); std::swap(a.step.p, b.step.p); std::swap(a.step.buf[0], b.step.buf[0]); std::swap(a.step.buf[1], b.step.buf[1]); - + if( a.step.p == b.step.buf ) { a.step.p = a.step.buf; a.size.p = &a.rows; } - + if( b.step.p == a.step.buf ) { b.step.p = b.step.buf; @@ -102,11 +102,11 @@ static inline void setSize( Mat& m, int _dims, const int* _sz, m.rows = m.cols = -1; } } - + m.dims = _dims; if( !_sz ) return; - + size_t esz = CV_ELEM_SIZE(m.flags), total = esz; int i; for( i = _dims-1; i >= 0; i-- ) @@ -114,7 +114,7 @@ static inline void setSize( Mat& m, int _dims, const int* _sz, int s = _sz[i]; CV_Assert( s >= 0 ); m.size.p[i] = s; - + if( _steps ) m.step.p[i] = i < _dims-1 ? _steps[i] : esz; else if( autoSteps ) @@ -126,7 +126,7 @@ static inline void setSize( Mat& m, int _dims, const int* _sz, total = (size_t)total1; } } - + if( _dims == 1 ) { m.dims = 2; @@ -134,7 +134,7 @@ static inline void setSize( Mat& m, int _dims, const int* _sz, m.step[1] = esz; } } - + static void updateContinuityFlag(Mat& m) { int i, j; @@ -143,20 +143,20 @@ static void updateContinuityFlag(Mat& m) if( m.size[i] > 1 ) break; } - + for( j = m.dims-1; j > i; j-- ) { if( m.step[j]*m.size[j] < m.step[j-1] ) break; } - + int64 t = (int64)m.step[0]*m.size[0]; if( j <= i && t == (int)t ) m.flags |= Mat::CONTINUOUS_FLAG; else m.flags &= ~Mat::CONTINUOUS_FLAG; } - + static void finalizeHdr(Mat& m) { updateContinuityFlag(m); @@ -178,14 +178,14 @@ static void finalizeHdr(Mat& m) else m.dataend = m.datalimit = 0; } - - + + void Mat::create(int d, const int* _sizes, int _type) { int i; CV_Assert(0 <= d && _sizes && d <= CV_MAX_DIM && _sizes); _type = CV_MAT_TYPE(_type); - + if( data && (d == dims || (d == 1 && dims <= 2)) && _type == type() ) { if( d == 2 && rows == _sizes[0] && cols == _sizes[1] ) @@ -196,13 +196,13 @@ void Mat::create(int d, const int* _sizes, int _type) if( i == d && (d > 1 || size[1] == 1)) return; } - + release(); if( d == 0 ) return; flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL; setSize(*this, d, _sizes, 0, true); - + if( total() > 0 ) { #ifdef HAVE_TGPU @@ -218,7 +218,7 @@ void Mat::create(int d, const int* _sizes, int _type) else { #ifdef HAVE_TGPU - try + try { allocator->allocate(dims, size, _type, refcount, datastart, data, step.p); CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) ); @@ -236,7 +236,7 @@ void Mat::create(int d, const int* _sizes, int _type) #endif } } - + finalizeHdr(*this); } @@ -249,7 +249,7 @@ void Mat::copySize(const Mat& m) step[i] = m.step[i]; } } - + void Mat::deallocate() { if( allocator ) @@ -261,7 +261,7 @@ void Mat::deallocate() } } - + Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&rows) { initEmpty(); @@ -276,7 +276,7 @@ Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&row *this = m(rs); return; } - + *this = m; if( rowRange != Range::all() && rowRange != Range(0,rows) ) { @@ -285,7 +285,7 @@ Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&row data += step*rowRange.start; flags |= SUBMATRIX_FLAG; } - + if( colRange != Range::all() && colRange != Range(0,cols) ) { CV_Assert( 0 <= colRange.start && colRange.start <= colRange.end && colRange.end <= m.cols ); @@ -294,18 +294,18 @@ Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&row flags &= cols < m.cols ? ~CONTINUOUS_FLAG : -1; flags |= SUBMATRIX_FLAG; } - + if( rows == 1 ) flags |= CONTINUOUS_FLAG; - + if( rows <= 0 || cols <= 0 ) { release(); rows = cols = 0; } } - - + + Mat::Mat(const Mat& m, const Rect& roi) : flags(m.flags), dims(2), rows(roi.height), cols(roi.width), data(m.data + roi.y*m.step[0]), refcount(m.refcount), @@ -315,7 +315,7 @@ Mat::Mat(const Mat& m, const Rect& roi) CV_Assert( m.dims <= 2 ); flags &= roi.width < m.cols ? ~CONTINUOUS_FLAG : -1; flags |= roi.height == 1 ? CONTINUOUS_FLAG : 0; - + size_t esz = CV_ELEM_SIZE(flags); data += roi.x*esz; CV_Assert( 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && @@ -324,9 +324,9 @@ Mat::Mat(const Mat& m, const Rect& roi) CV_XADD(refcount, 1); if( roi.width < m.cols || roi.height < m.rows ) flags |= SUBMATRIX_FLAG; - + step[0] = m.step[0]; step[1] = esz; - + if( rows <= 0 || cols <= 0 ) { release(); @@ -334,7 +334,7 @@ Mat::Mat(const Mat& m, const Rect& roi) } } - + Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps) : size(&rows) { initEmpty(); @@ -343,13 +343,13 @@ Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _st setSize(*this, _dims, _sizes, _steps, true); finalizeHdr(*this); } - - + + Mat::Mat(const Mat& m, const Range* ranges) : size(&rows) { initEmpty(); int i, d = m.dims; - + CV_Assert(ranges); for( i = 0; i < d; i++ ) { @@ -369,8 +369,8 @@ Mat::Mat(const Mat& m, const Range* ranges) : size(&rows) } updateContinuityFlag(*this); } - - + + Mat::Mat(const CvMatND* m, bool copyData) : size(&rows) { initEmpty(); @@ -380,14 +380,14 @@ Mat::Mat(const CvMatND* m, bool copyData) : size(&rows) flags |= CV_MAT_TYPE(m->type); int _sizes[CV_MAX_DIM]; size_t _steps[CV_MAX_DIM]; - + int i, d = m->dims; for( i = 0; i < d; i++ ) { _sizes[i] = m->dim[i].size; _steps[i] = m->dim[i].step; } - + setSize(*this, d, _sizes, _steps); finalizeHdr(*this); @@ -397,15 +397,15 @@ Mat::Mat(const CvMatND* m, bool copyData) : size(&rows) temp.copyTo(*this); } } - - + + Mat Mat::diag(int d) const { CV_Assert( dims <= 2 ); Mat m = *this; size_t esz = elemSize(); int len; - + if( d >= 0 ) { len = std::min(cols - d, rows); @@ -417,30 +417,30 @@ Mat Mat::diag(int d) const m.data -= step[0]*d; } CV_DbgAssert( len > 0 ); - + m.size[0] = m.rows = len; m.size[1] = m.cols = 1; m.step[0] += (len > 1 ? esz : 0); - + if( m.rows > 1 ) m.flags &= ~CONTINUOUS_FLAG; else m.flags |= CONTINUOUS_FLAG; - + if( size() != Size(1,1) ) m.flags |= SUBMATRIX_FLAG; - + return m; } - + Mat::Mat(const CvMat* m, bool copyData) : size(&rows) { initEmpty(); - + if( !m ) return; - + if( !copyData ) { flags = MAGIC_VAL + (m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG)); @@ -462,17 +462,17 @@ Mat::Mat(const CvMat* m, bool copyData) : size(&rows) } } - + Mat::Mat(const IplImage* img, bool copyData) : size(&rows) { initEmpty(); - + if( !img ) return; - + dims = 2; CV_DbgAssert(CV_IS_IMAGE(img) && img->imageData != 0); - + int depth = IPL2CV_DEPTH(img->depth); size_t esz; step[0] = img->widthStep; @@ -493,8 +493,8 @@ Mat::Mat(const IplImage* img, bool copyData) : size(&rows) rows = img->roi->height; cols = img->roi->width; esz = CV_ELEM_SIZE(flags); data = datastart = (uchar*)img->imageData + - (selectedPlane ? (img->roi->coi - 1)*step*img->height : 0) + - img->roi->yOffset*step[0] + img->roi->xOffset*esz; + (selectedPlane ? (img->roi->coi - 1)*step*img->height : 0) + + img->roi->yOffset*step[0] + img->roi->xOffset*esz; } datalimit = datastart + step.p[0]*rows; dataend = datastart + step.p[0]*(rows-1) + esz*cols; @@ -517,7 +517,7 @@ Mat::Mat(const IplImage* img, bool copyData) : size(&rows) } } - + Mat::operator IplImage() const { CV_Assert( dims <= 2 ); @@ -527,11 +527,11 @@ Mat::operator IplImage() const return img; } - + void Mat::pop_back(size_t nelems) { CV_Assert( nelems <= (size_t)size.p[0] ); - + if( isSubmatrix() ) *this = rowRange(0, size.p[0] - (int)nelems); else @@ -547,14 +547,14 @@ void Mat::pop_back(size_t nelems) }*/ } } - - + + void Mat::push_back_(const void* elem) { int r = size.p[0]; if( isSubmatrix() || dataend + step.p[0] > datalimit ) reserve( std::max(r + 1, (r*3+1)/2) ); - + size_t esz = elemSize(); memcpy(data + r*step.p[0], elem, esz); size.p[0] = r + 1; @@ -566,22 +566,22 @@ void Mat::push_back_(const void* elem) void Mat::reserve(size_t nelems) { const size_t MIN_SIZE = 64; - + CV_Assert( (int)nelems >= 0 ); if( !isSubmatrix() && data + step.p[0]*nelems <= datalimit ) return; - + int r = size.p[0]; - + if( (size_t)r >= nelems ) return; - + size.p[0] = std::max((int)nelems, 1); size_t newsize = total()*elemSize(); - + if( newsize < MIN_SIZE ) size.p[0] = (int)((MIN_SIZE + newsize - 1)*nelems/newsize); - + Mat m(dims, size.p, type()); size.p[0] = r; if( r > 0 ) @@ -589,42 +589,42 @@ void Mat::reserve(size_t nelems) Mat mpart = m.rowRange(0, r); copyTo(mpart); } - + *this = m; size.p[0] = r; dataend = data + step.p[0]*r; } - + void Mat::resize(size_t nelems) { int saveRows = size.p[0]; if( saveRows == (int)nelems ) return; CV_Assert( (int)nelems >= 0 ); - + if( isSubmatrix() || data + step.p[0]*nelems > datalimit ) reserve(nelems); - + size.p[0] = (int)nelems; dataend += (size.p[0] - saveRows)*step.p[0]; - + //updateContinuityFlag(*this); -} +} + - void Mat::resize(size_t nelems, const Scalar& s) { int saveRows = size.p[0]; resize(nelems); - + if( size.p[0] > saveRows ) { Mat part = rowRange(saveRows, size.p[0]); part = s; } -} - +} + void Mat::push_back(const Mat& elems) { int r = size.p[0], delta = elems.size.p[0]; @@ -636,11 +636,11 @@ void Mat::push_back(const Mat& elems) push_back(tmp); return; } - if( !data ) - { - *this = elems.clone(); - return; - } + if( !data ) + { + *this = elems.clone(); + return; + } size.p[0] = elems.size.p[0]; bool eq = size == elems.size; @@ -649,15 +649,15 @@ void Mat::push_back(const Mat& elems) CV_Error(CV_StsUnmatchedSizes, ""); if( type() != elems.type() ) CV_Error(CV_StsUnmatchedFormats, ""); - + if( isSubmatrix() || dataend + step.p[0]*delta > datalimit ) reserve( std::max(r + delta, (r*3+1)/2) ); - + size.p[0] += delta; dataend += step.p[0]*delta; - + //updateContinuityFlag(*this); - + if( isContinuous() && elems.isContinuous() ) memcpy(data + r*step.p[0], elems.data, elems.total()*elems.elemSize()); else @@ -667,7 +667,7 @@ void Mat::push_back(const Mat& elems) } } - + Mat cvarrToMat(const CvArr* arr, bool copyData, bool /*allowND*/, int coiMode) { @@ -703,7 +703,7 @@ void Mat::locateROI( Size& wholeSize, Point& ofs ) const CV_Assert( dims <= 2 && step[0] > 0 ); size_t esz = elemSize(), minstep; ptrdiff_t delta1 = data - datastart, delta2 = dataend - datastart; - + if( delta1 == 0 ) ofs.x = ofs.y = 0; else @@ -735,17 +735,17 @@ Mat& Mat::adjustROI( int dtop, int dbottom, int dleft, int dright ) else flags &= ~CONTINUOUS_FLAG; return *this; -} +} } - + void cv::extractImageCOI(const CvArr* arr, OutputArray _ch, int coi) { Mat mat = cvarrToMat(arr, false, true, 1); _ch.create(mat.dims, mat.size, mat.depth()); Mat ch = _ch.getMat(); if(coi < 0) - { + { CV_Assert( CV_IS_IMAGE(arr) ); coi = cvGetImageCOI((const IplImage*)arr)-1; } @@ -753,12 +753,12 @@ void cv::extractImageCOI(const CvArr* arr, OutputArray _ch, int coi) int _pairs[] = { coi, 0 }; mixChannels( &mat, 1, &ch, 1, _pairs, 1 ); } - + void cv::insertImageCOI(InputArray _ch, CvArr* arr, int coi) { Mat ch = _ch.getMat(), mat = cvarrToMat(arr, false, true, 1); if(coi < 0) - { + { CV_Assert( CV_IS_IMAGE(arr) ); coi = cvGetImageCOI((const IplImage*)arr)-1; } @@ -766,7 +766,7 @@ void cv::insertImageCOI(InputArray _ch, CvArr* arr, int coi) int _pairs[] = { 0, coi }; mixChannels( &ch, 1, &mat, 1, _pairs, 1 ); } - + namespace cv { @@ -774,7 +774,7 @@ Mat Mat::reshape(int new_cn, int new_rows) const { int cn = channels(); Mat hdr = *this; - + if( dims > 2 && new_rows == 0 && new_cn != 0 && size[dims-1]*cn % new_cn == 0 ) { hdr.flags = (hdr.flags & ~CV_MAT_CN_MASK) | ((new_cn-1) << CV_CN_SHIFT); @@ -782,9 +782,9 @@ Mat Mat::reshape(int new_cn, int new_rows) const hdr.size[dims-1] = hdr.size[dims-1]*cn / new_cn; return hdr; } - + CV_Assert( dims <= 2 ); - + if( new_cn == 0 ) new_cn = cn; @@ -825,7 +825,7 @@ Mat Mat::reshape(int new_cn, int new_rows) const return hdr; } - + int Mat::checkVector(int _elemChannels, int _depth, bool _requireContinuous) const { return (depth() == _depth || _depth <= 0) && @@ -911,12 +911,13 @@ void scalarToRawData(const Scalar& s, void* _buf, int type, int unroll_to) } } - + /*************************************************************************************************\ Input/Output Array \*************************************************************************************************/ _InputArray::_InputArray() : flags(0), obj(0) {} +_InputArray::~_InputArray() {} _InputArray::_InputArray(const Mat& m) : flags(MAT), obj((void*)&m) {} _InputArray::_InputArray(const vector& vec) : flags(STD_VECTOR_MAT), obj((void*)&vec) {} _InputArray::_InputArray(const double& val) : flags(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F), obj((void*)&val), sz(Size(1,1)) {} @@ -924,11 +925,11 @@ _InputArray::_InputArray(const MatExpr& expr) : flags(FIXED_TYPE + FIXED_SIZE + _InputArray::_InputArray(const GlBuffer& buf) : flags(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER), obj((void*)&buf) {} _InputArray::_InputArray(const GlTexture& tex) : flags(FIXED_TYPE + FIXED_SIZE + OPENGL_TEXTURE), obj((void*)&tex) {} _InputArray::_InputArray(const gpu::GpuMat& d_mat) : flags(GPU_MAT), obj((void*)&d_mat) {} - + Mat _InputArray::getMat(int i) const { int k = kind(); - + if( k == MAT ) { const Mat* m = (const Mat*)obj; @@ -936,115 +937,115 @@ Mat _InputArray::getMat(int i) const return *m; return m->row(i); } - + if( k == EXPR ) { CV_Assert( i < 0 ); return (Mat)*((const MatExpr*)obj); } - + if( k == MATX ) { CV_Assert( i < 0 ); return Mat(sz, flags, obj); } - + if( k == STD_VECTOR ) { CV_Assert( i < 0 ); int t = CV_MAT_TYPE(flags); const vector& v = *(const vector*)obj; - + return !v.empty() ? Mat(size(), t, (void*)&v[0]) : Mat(); } - + if( k == NONE ) return Mat(); - + if( k == STD_VECTOR_VECTOR ) { int t = type(i); const vector >& vv = *(const vector >*)obj; CV_Assert( 0 <= i && i < (int)vv.size() ); const vector& v = vv[i]; - + return !v.empty() ? Mat(size(i), t, (void*)&v[0]) : Mat(); } - + CV_Assert( k == STD_VECTOR_MAT ); //if( k == STD_VECTOR_MAT ) { const vector& v = *(const vector*)obj; CV_Assert( 0 <= i && i < (int)v.size() ); - + return v[i]; - } + } } - - + + void _InputArray::getMatVector(vector& mv) const { int k = kind(); - + if( k == MAT ) { const Mat& m = *(const Mat*)obj; int i, n = (int)m.size[0]; mv.resize(n); - + for( i = 0; i < n; i++ ) mv[i] = m.dims == 2 ? Mat(1, m.cols, m.type(), (void*)m.ptr(i)) : Mat(m.dims-1, &m.size[1], m.type(), (void*)m.ptr(i), &m.step[1]); return; } - + if( k == EXPR ) { Mat m = *(const MatExpr*)obj; int i, n = m.size[0]; mv.resize(n); - + for( i = 0; i < n; i++ ) mv[i] = m.row(i); return; } - + if( k == MATX ) { size_t i, n = sz.height, esz = CV_ELEM_SIZE(flags); mv.resize(n); - + for( i = 0; i < n; i++ ) mv[i] = Mat(1, sz.width, CV_MAT_TYPE(flags), (uchar*)obj + esz*sz.width*i); return; } - + if( k == STD_VECTOR ) { const vector& v = *(const vector*)obj; - + size_t i, n = v.size(), esz = CV_ELEM_SIZE(flags); int t = CV_MAT_DEPTH(flags), cn = CV_MAT_CN(flags); mv.resize(n); - + for( i = 0; i < n; i++ ) mv[i] = Mat(1, cn, t, (void*)(&v[0] + esz*i)); return; } - + if( k == NONE ) { mv.clear(); return; } - + if( k == STD_VECTOR_VECTOR ) { const vector >& vv = *(const vector >*)obj; int i, n = (int)vv.size(); int t = CV_MAT_TYPE(flags); mv.resize(n); - + for( i = 0; i < n; i++ ) { const vector& v = vv[i]; @@ -1052,7 +1053,7 @@ void _InputArray::getMatVector(vector& mv) const } return; } - + CV_Assert( k == STD_VECTOR_MAT ); //if( k == STD_VECTOR_MAT ) { @@ -1098,34 +1099,34 @@ gpu::GpuMat _InputArray::getGpuMat() const return *d_mat; } } - + int _InputArray::kind() const { return flags & KIND_MASK; } - + Size _InputArray::size(int i) const { int k = kind(); - + if( k == MAT ) { CV_Assert( i < 0 ); return ((const Mat*)obj)->size(); } - + if( k == EXPR ) { CV_Assert( i < 0 ); return ((const MatExpr*)obj)->size(); } - + if( k == MATX ) { CV_Assert( i < 0 ); return sz; } - + if( k == STD_VECTOR ) { CV_Assert( i < 0 ); @@ -1134,10 +1135,10 @@ Size _InputArray::size(int i) const size_t szb = v.size(), szi = iv.size(); return szb == szi ? Size((int)szb, 1) : Size((int)(szb/CV_ELEM_SIZE(flags)), 1); } - + if( k == NONE ) return Size(); - + if( k == STD_VECTOR_VECTOR ) { const vector >& vv = *(const vector >*)obj; @@ -1145,18 +1146,18 @@ Size _InputArray::size(int i) const return vv.empty() ? Size() : Size((int)vv.size(), 1); CV_Assert( i < (int)vv.size() ); const vector >& ivv = *(const vector >*)obj; - + size_t szb = vv[i].size(), szi = ivv[i].size(); return szb == szi ? Size((int)szb, 1) : Size((int)(szb/CV_ELEM_SIZE(flags)), 1); } - + if( k == STD_VECTOR_MAT ) { const vector& vv = *(const vector*)obj; if( i < 0 ) return vv.empty() ? Size() : Size((int)vv.size(), 1); CV_Assert( i < (int)vv.size() ); - + return vv[i].size(); } @@ -1187,106 +1188,107 @@ size_t _InputArray::total(int i) const { return size(i).area(); } - + int _InputArray::type(int i) const { int k = kind(); - + if( k == MAT ) return ((const Mat*)obj)->type(); - + if( k == EXPR ) return ((const MatExpr*)obj)->type(); - + if( k == MATX || k == STD_VECTOR || k == STD_VECTOR_VECTOR ) return CV_MAT_TYPE(flags); - + if( k == NONE ) return -1; - + if( k == STD_VECTOR_MAT ) { const vector& vv = *(const vector*)obj; CV_Assert( i < (int)vv.size() ); - + return vv[i >= 0 ? i : 0].type(); } - + if( k == OPENGL_BUFFER ) return ((const GlBuffer*)obj)->type(); - + if( k == OPENGL_TEXTURE ) return ((const GlTexture*)obj)->type(); - + CV_Assert( k == GPU_MAT ); //if( k == GPU_MAT ) return ((const gpu::GpuMat*)obj)->type(); } - + int _InputArray::depth(int i) const { return CV_MAT_DEPTH(type(i)); } - + int _InputArray::channels(int i) const { return CV_MAT_CN(type(i)); } - + bool _InputArray::empty() const { int k = kind(); - + if( k == MAT ) return ((const Mat*)obj)->empty(); - + if( k == EXPR ) return false; - + if( k == MATX ) return false; - + if( k == STD_VECTOR ) { const vector& v = *(const vector*)obj; return v.empty(); } - + if( k == NONE ) return true; - + if( k == STD_VECTOR_VECTOR ) { const vector >& vv = *(const vector >*)obj; return vv.empty(); } - + if( k == STD_VECTOR_MAT ) { const vector& vv = *(const vector*)obj; return vv.empty(); } - + if( k == OPENGL_BUFFER ) return ((const GlBuffer*)obj)->empty(); - + if( k == OPENGL_TEXTURE ) return ((const GlTexture*)obj)->empty(); - + CV_Assert( k == GPU_MAT ); //if( k == GPU_MAT ) return ((const gpu::GpuMat*)obj)->empty(); } - - + + _OutputArray::_OutputArray() {} +_OutputArray::~_OutputArray() {} _OutputArray::_OutputArray(Mat& m) : _InputArray(m) {} _OutputArray::_OutputArray(vector& vec) : _InputArray(vec) {} _OutputArray::_OutputArray(const Mat& m) : _InputArray(m) {flags |= FIXED_SIZE|FIXED_TYPE;} _OutputArray::_OutputArray(const vector& vec) : _InputArray(vec) {flags |= FIXED_SIZE;} - + bool _OutputArray::fixedSize() const { return (flags & FIXED_SIZE) == FIXED_SIZE; @@ -1296,7 +1298,7 @@ bool _OutputArray::fixedType() const { return (flags & FIXED_TYPE) == FIXED_TYPE; } - + void _OutputArray::create(Size _sz, int type, int i, bool allowTransposed, int fixedDepthMask) const { int k = kind(); @@ -1324,12 +1326,12 @@ void _OutputArray::create(int rows, int cols, int type, int i, bool allowTranspo int sz[] = {rows, cols}; create(2, sz, type, i, allowTransposed, fixedDepthMask); } - + void _OutputArray::create(int dims, const int* size, int type, int i, bool allowTransposed, int fixedDepthMask) const { int k = kind(); type = CV_MAT_TYPE(type); - + if( k == MAT ) { CV_Assert( i < 0 ); @@ -1341,7 +1343,7 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow CV_Assert(!fixedType() && !fixedSize()); m.release(); } - + if( dims == 2 && m.dims == 2 && m.data && m.type() == type && m.rows == size[1] && m.cols == size[0] ) return; @@ -1363,7 +1365,7 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow m.create(dims, size, type); return; } - + if( k == MATX ) { CV_Assert( i < 0 ); @@ -1373,13 +1375,13 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow (allowTransposed && size[0] == sz.width && size[1] == sz.height))); return; } - + if( k == STD_VECTOR || k == STD_VECTOR_VECTOR ) { CV_Assert( dims == 2 && (size[0] == 1 || size[1] == 1 || size[0]*size[1] == 0) ); size_t len = size[0]*size[1] > 0 ? size[0] + size[1] - 1 : 0; vector* v = (vector*)obj; - + if( k == STD_VECTOR_VECTOR ) { vector >& vv = *(vector >*)obj; @@ -1394,10 +1396,10 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow } else CV_Assert( i < 0 ); - + int type0 = CV_MAT_TYPE(flags); CV_Assert( type == type0 || (CV_MAT_CN(type) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0) ); - + int esz = CV_ELEM_SIZE(type0); CV_Assert(!fixedSize() || len == ((vector*)v)->size() / esz); switch( esz ) @@ -1455,23 +1457,23 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow } return; } - + if( k == NONE ) { - CV_Error(CV_StsNullPtr, "create() called for the missing output array" ); + CV_Error(CV_StsNullPtr, "create() called for the missing output array" ); return; } - + CV_Assert( k == STD_VECTOR_MAT ); //if( k == STD_VECTOR_MAT ) { vector& v = *(vector*)obj; - + if( i < 0 ) { CV_Assert( dims == 2 && (size[0] == 1 || size[1] == 1 || size[0]*size[1] == 0) ); size_t len = size[0]*size[1] > 0 ? size[0] + size[1] - 1 : 0, len0 = v.size(); - + CV_Assert(!fixedSize() || len == len0); v.resize(len); if( fixedType() ) @@ -1487,10 +1489,10 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow } return; } - + CV_Assert( i < (int)v.size() ); Mat& m = v[i]; - + if( allowTransposed ) { if( !m.isContinuous() ) @@ -1498,7 +1500,7 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow CV_Assert(!fixedType() && !fixedSize()); m.release(); } - + if( dims == 2 && m.dims == 2 && m.data && m.type() == type && m.rows == size[1] && m.cols == size[0] ) return; @@ -1521,55 +1523,55 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow m.create(dims, size, type); } } - + void _OutputArray::release() const { CV_Assert(!fixedSize()); int k = kind(); - + if( k == MAT ) { ((Mat*)obj)->release(); return; } - + if( k == NONE ) return; - + if( k == STD_VECTOR ) { create(Size(), CV_MAT_TYPE(flags)); return; } - + if( k == STD_VECTOR_VECTOR ) { ((vector >*)obj)->clear(); return; } - + CV_Assert( k == STD_VECTOR_MAT ); //if( k == STD_VECTOR_MAT ) { ((vector*)obj)->clear(); - } + } } void _OutputArray::clear() const { int k = kind(); - + if( k == MAT ) { CV_Assert(!fixedSize()); ((Mat*)obj)->resize(0); return; } - + release(); } - + bool _OutputArray::needed() const { return kind() != NONE; @@ -1594,7 +1596,7 @@ Mat& _OutputArray::getMatRef(int i) const static _OutputArray _none; OutputArray noArray() { return _none; } - + } /*************************************************************************************************\ @@ -1608,7 +1610,7 @@ void cv::hconcat(const Mat* src, size_t nsrc, OutputArray _dst) _dst.release(); return; } - + int totalCols = 0, cols = 0; size_t i; for( i = 0; i < nsrc; i++ ) @@ -1627,13 +1629,13 @@ void cv::hconcat(const Mat* src, size_t nsrc, OutputArray _dst) cols += src[i].cols; } } - + void cv::hconcat(InputArray src1, InputArray src2, OutputArray dst) { Mat src[] = {src1.getMat(), src2.getMat()}; hconcat(src, 2, dst); } - + void cv::hconcat(InputArray _src, OutputArray dst) { vector src; @@ -1648,7 +1650,7 @@ void cv::vconcat(const Mat* src, size_t nsrc, OutputArray _dst) _dst.release(); return; } - + int totalRows = 0, rows = 0; size_t i; for( i = 0; i < nsrc; i++ ) @@ -1667,12 +1669,12 @@ void cv::vconcat(const Mat* src, size_t nsrc, OutputArray _dst) rows += src[i].rows; } } - + void cv::vconcat(InputArray src1, InputArray src2, OutputArray dst) { Mat src[] = {src1.getMat(), src2.getMat()}; vconcat(src, 2, dst); -} +} void cv::vconcat(InputArray _src, OutputArray dst) { @@ -1680,14 +1682,14 @@ void cv::vconcat(InputArray _src, OutputArray dst) _src.getMatVector(src); vconcat(!src.empty() ? &src[0] : 0, src.size(), dst); } - + //////////////////////////////////////// set identity //////////////////////////////////////////// void cv::setIdentity( InputOutputArray _m, const Scalar& s ) { Mat m = _m.getMat(); CV_Assert( m.dims <= 2 ); int i, j, rows = m.rows, cols = m.cols, type = m.type(); - + if( type == CV_32FC1 ) { float* data = (float*)m.data; @@ -1721,15 +1723,15 @@ void cv::setIdentity( InputOutputArray _m, const Scalar& s ) } } -//////////////////////////////////////////// trace /////////////////////////////////////////// - +//////////////////////////////////////////// trace /////////////////////////////////////////// + cv::Scalar cv::trace( InputArray _m ) { Mat m = _m.getMat(); CV_Assert( m.dims <= 2 ); int i, type = m.type(); int nm = std::min(m.rows, m.cols); - + if( type == CV_32FC1 ) { const float* ptr = (const float*)m.data; @@ -1739,7 +1741,7 @@ cv::Scalar cv::trace( InputArray _m ) _s += ptr[i*step]; return _s; } - + if( type == CV_64FC1 ) { const double* ptr = (const double*)m.data; @@ -1749,7 +1751,7 @@ cv::Scalar cv::trace( InputArray _m ) _s += ptr[i*step]; return _s; } - + return cv::sum(m.diag()); } @@ -1763,27 +1765,27 @@ transpose_( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size sz ) { int i=0, j, m = sz.width, n = sz.height; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for(; i <= m - 4; i += 4 ) { T* d0 = (T*)(dst + dstep*i); T* d1 = (T*)(dst + dstep*(i+1)); T* d2 = (T*)(dst + dstep*(i+2)); T* d3 = (T*)(dst + dstep*(i+3)); - + for( j = 0; j <= n - 4; j += 4 ) { const T* s0 = (const T*)(src + i*sizeof(T) + sstep*j); const T* s1 = (const T*)(src + i*sizeof(T) + sstep*(j+1)); const T* s2 = (const T*)(src + i*sizeof(T) + sstep*(j+2)); const T* s3 = (const T*)(src + i*sizeof(T) + sstep*(j+3)); - + d0[j] = s0[0]; d0[j+1] = s1[0]; d0[j+2] = s2[0]; d0[j+3] = s3[0]; d1[j] = s0[1]; d1[j+1] = s1[1]; d1[j+2] = s2[1]; d1[j+3] = s3[1]; d2[j] = s0[2]; d2[j+1] = s1[2]; d2[j+2] = s2[2]; d2[j+3] = s3[2]; d3[j] = s0[3]; d3[j+1] = s1[3]; d3[j+2] = s2[3]; d3[j+3] = s3[3]; } - + for( ; j < n; j++ ) { const T* s0 = (const T*)(src + i*sizeof(T) + j*sstep); @@ -1795,14 +1797,14 @@ transpose_( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size sz ) { T* d0 = (T*)(dst + dstep*i); j = 0; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for(; j <= n - 4; j += 4 ) { const T* s0 = (const T*)(src + i*sizeof(T) + sstep*j); const T* s1 = (const T*)(src + i*sizeof(T) + sstep*(j+1)); const T* s2 = (const T*)(src + i*sizeof(T) + sstep*(j+2)); const T* s3 = (const T*)(src + i*sizeof(T) + sstep*(j+3)); - + d0[j] = s0[0]; d0[j+1] = s1[0]; d0[j+2] = s2[0]; d0[j+3] = s3[0]; } #endif @@ -1826,10 +1828,10 @@ transposeI_( uchar* data, size_t step, int n ) std::swap( row[j], *(T*)(data1 + step*j) ); } } - + typedef void (*TransposeFunc)( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size sz ); typedef void (*TransposeInplaceFunc)( uchar* data, size_t step, int n ); - + #define DEF_TRANSPOSE_FUNC(suffix, type) \ static void transpose_##suffix( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size sz ) \ { transpose_(src, sstep, dst, dstep, sz); } \ @@ -1863,7 +1865,7 @@ static TransposeInplaceFunc transposeInplaceTab[] = }; } - + void cv::transpose( InputArray _src, OutputArray _dst ) { Mat src = _src.getMat(); @@ -1872,7 +1874,7 @@ void cv::transpose( InputArray _src, OutputArray _dst ) _dst.create(src.cols, src.rows, src.type()); Mat dst = _dst.getMat(); - + if( dst.data == src.data ) { TransposeInplaceFunc func = transposeInplaceTab[esz]; @@ -1892,7 +1894,7 @@ void cv::completeSymm( InputOutputArray _m, bool LtoR ) { Mat m = _m.getMat(); CV_Assert( m.dims <= 2 ); - + int i, j, nrows = m.rows, type = m.type(); int j0 = 0, j1 = nrows; CV_Assert( m.rows == m.cols ); @@ -1923,7 +1925,7 @@ void cv::completeSymm( InputOutputArray _m, bool LtoR ) CV_Error( CV_StsUnsupportedFormat, "" ); } - + cv::Mat cv::Mat::cross(InputArray _m) const { Mat m = _m.getMat(); @@ -1985,7 +1987,7 @@ reduceR_( const Mat& srcmat, Mat& dstmat ) { src += srcstep; i = 0; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for(; i <= size.width - 4; i += 4 ) { WT s0, s1; @@ -2044,7 +2046,7 @@ reduceC_( const Mat& srcmat, Mat& dstmat ) dst[k] = (ST)a0; } } - } + } } typedef void (*ReduceFunc)( const Mat& src, Mat& dst ); @@ -2110,7 +2112,7 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) _dst.create(dim == 0 ? 1 : src.rows, dim == 0 ? src.cols : 1, CV_MAKETYPE(dtype >= 0 ? dtype : stype, cn)); Mat dst = _dst.getMat(), temp = dst; - + CV_Assert( op == CV_REDUCE_SUM || op == CV_REDUCE_MAX || op == CV_REDUCE_MIN || op == CV_REDUCE_AVG ); CV_Assert( src.channels() == dst.channels() ); @@ -2240,8 +2242,8 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) if( op0 == CV_REDUCE_AVG ) temp.convertTo(dst, dst.type(), 1./(dim == 0 ? src.rows : src.cols)); } - - + + //////////////////////////////////////// sort /////////////////////////////////////////// namespace cv @@ -2255,7 +2257,7 @@ template static void sort_( const Mat& src, Mat& dst, int flags ) bool sortRows = (flags & 1) == CV_SORT_EVERY_ROW; bool inplace = src.data == dst.data; bool sortDescending = (flags & CV_SORT_DESCENDING) != 0; - + if( sortRows ) n = src.rows, len = src.cols; else @@ -2306,7 +2308,7 @@ template static void sortIdx_( const Mat& src, Mat& dst, int flags ) bool sortDescending = (flags & CV_SORT_DESCENDING) != 0; CV_Assert( src.data != dst.data ); - + if( sortRows ) n = src.rows, len = src.cols; else @@ -2348,7 +2350,7 @@ template static void sortIdx_( const Mat& src, Mat& dst, int flags ) typedef void (*SortFunc)(const Mat& src, Mat& dst, int flags); } - + void cv::sort( InputArray _src, OutputArray _dst, int flags ) { static SortFunc tab[] = @@ -2374,7 +2376,7 @@ void cv::sortIdx( InputArray _src, OutputArray _dst, int flags ) Mat src = _src.getMat(); SortFunc func = tab[src.depth()]; CV_Assert( src.dims <= 2 && src.channels() == 1 && func != 0 ); - + Mat dst = _dst.getMat(); if( dst.data == src.data ) _dst.release(); @@ -2382,8 +2384,8 @@ void cv::sortIdx( InputArray _src, OutputArray _dst, int flags ) dst = _dst.getMat(); func( src, dst, flags ); } - - + + ////////////////////////////////////////// kmeans //////////////////////////////////////////// namespace cv @@ -2421,7 +2423,7 @@ static void generateCentersPP(const Mat& _data, Mat& _out_centers, dist[i] = normL2Sqr_(data + step*i, data + step*centers[0], dims); sum0 += dist[i]; } - + for( k = 1; k < K; k++ ) { double bestSum = DBL_MAX; @@ -2439,7 +2441,7 @@ static void generateCentersPP(const Mat& _data, Mat& _out_centers, tdist2[i] = std::min(normL2Sqr_(data + step*i, data + step*ci, dims), dist[i]); s += tdist2[i]; } - + if( s < bestSum ) { bestSum = s; @@ -2462,7 +2464,7 @@ static void generateCentersPP(const Mat& _data, Mat& _out_centers, } } - + double cv::kmeans( InputArray _data, int K, InputOutputArray _bestLabels, TermCriteria criteria, int attempts, @@ -2480,7 +2482,7 @@ double cv::kmeans( InputArray _data, int K, CV_Assert( N >= K ); _bestLabels.create(N, 1, CV_32S, -1, true); - + Mat _labels, best_labels = _bestLabels.getMat(); if( flags & CV_KMEANS_USE_INITIAL_LABELS ) { @@ -2566,7 +2568,7 @@ double cv::kmeans( InputArray _data, int K, for( i = 0; i < N; i++ ) CV_Assert( (unsigned)labels[i] < (unsigned)K ); } - + // compute centers centers = Scalar(0); for( k = 0; k < K; k++ ) @@ -2577,8 +2579,8 @@ double cv::kmeans( InputArray _data, int K, sample = data.ptr(i); k = labels[i]; float* center = centers.ptr(k); - j=0; - #if CV_ENABLE_UNROLLED + j=0; + #if CV_ENABLE_UNROLLED for(; j <= dims - 4; j += 4 ) { float t0 = center[j] + sample[j]; @@ -2601,7 +2603,7 @@ double cv::kmeans( InputArray _data, int K, if( iter > 0 ) max_center_shift = 0; - + for( k = 0; k < K; k++ ) { if( counters[k] != 0 ) @@ -2617,8 +2619,8 @@ double cv::kmeans( InputArray _data, int K, if( counters[max_k] < counters[k1] ) max_k = k1; } - - double max_dist = 0; + + double max_dist = 0; int farthest_i = -1; float* new_center = centers.ptr(k); float* old_center = centers.ptr(max_k); @@ -2626,26 +2628,26 @@ double cv::kmeans( InputArray _data, int K, float scale = 1.f/counters[max_k]; for( j = 0; j < dims; j++ ) _old_center[j] = old_center[j]*scale; - + for( i = 0; i < N; i++ ) { if( labels[i] != max_k ) continue; sample = data.ptr(i); double dist = normL2Sqr_(sample, _old_center, dims); - + if( max_dist <= dist ) { max_dist = dist; farthest_i = i; } } - + counters[max_k]--; counters[k]++; labels[farthest_i] = k; sample = data.ptr(farthest_i); - + for( j = 0; j < dims; j++ ) { old_center[j] -= sample[j]; @@ -2661,7 +2663,7 @@ double cv::kmeans( InputArray _data, int K, float scale = 1.f/counters[k]; for( j = 0; j < dims; j++ ) center[j] *= scale; - + if( iter > 0 ) { double dist = 0; @@ -2675,7 +2677,7 @@ double cv::kmeans( InputArray _data, int K, } } } - + if( ++iter == MAX(criteria.maxCount, 2) || max_center_shift <= criteria.epsilon ) break; @@ -2759,7 +2761,7 @@ CV_IMPL void cvReduce( const CvArr* srcarr, CvArr* dstarr, int dim, int op ) { cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr); - + if( dim < 0 ) dim = src.rows > dst.rows ? 0 : src.cols > dst.cols ? 1 : dst.cols == 1; @@ -2769,7 +2771,7 @@ cvReduce( const CvArr* srcarr, CvArr* dstarr, int dim, int op ) if( (dim == 0 && (dst.cols != src.cols || dst.rows != 1)) || (dim == 1 && (dst.rows != src.rows || dst.cols != 1)) ) CV_Error( CV_StsBadSize, "The output array size is incorrect" ); - + if( src.channels() != dst.channels() ) CV_Error( CV_StsUnmatchedFormats, "Input and output arrays must have the same number of channels" ); @@ -2781,14 +2783,14 @@ CV_IMPL CvArr* cvRange( CvArr* arr, double start, double end ) { int ok = 0; - + CvMat stub, *mat = (CvMat*)arr; double delta; int type, step; double val = start; int i, j; int rows, cols; - + if( !CV_IS_MAT(mat) ) mat = cvGetMat( mat, &stub); @@ -2844,7 +2846,7 @@ CV_IMPL void cvSort( const CvArr* _src, CvArr* _dst, CvArr* _idx, int flags ) { cv::Mat src = cv::cvarrToMat(_src), dst, idx; - + if( _idx ) { cv::Mat idx0 = cv::cvarrToMat(_idx), idx = idx0; @@ -2884,7 +2886,7 @@ cvKMeans2( const CvArr* _samples, int cluster_count, CvArr* _labels, CV_Assert( labels.isContinuous() && labels.type() == CV_32S && (labels.cols == 1 || labels.rows == 1) && labels.cols + labels.rows - 1 == data.rows ); - + double compactness = cv::kmeans(data, cluster_count, labels, termcrit, attempts, flags, _centers ? cv::_OutputArray(centers) : cv::_OutputArray() ); if( _compactness ) @@ -2932,26 +2934,26 @@ NAryMatIterator::NAryMatIterator(const Mat** _arrays, Mat* _planes, int _narrays : arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0) { init(_arrays, _planes, 0, _narrays); -} - +} + NAryMatIterator::NAryMatIterator(const Mat** _arrays, uchar** _ptrs, int _narrays) : arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0) { init(_arrays, 0, _ptrs, _narrays); } - + void NAryMatIterator::init(const Mat** _arrays, Mat* _planes, uchar** _ptrs, int _narrays) { CV_Assert( _arrays && (_ptrs || _planes) ); int i, j, d1=0, i0 = -1, d = -1; - + arrays = _arrays; ptrs = _ptrs; planes = _planes; narrays = _narrays; nplanes = 0; size = 0; - + if( narrays < 0 ) { for( i = 0; _arrays[i] != 0; i++ ) @@ -2968,15 +2970,15 @@ void NAryMatIterator::init(const Mat** _arrays, Mat* _planes, uchar** _ptrs, int const Mat& A = *arrays[i]; if( ptrs ) ptrs[i] = A.data; - + if( !A.data ) continue; - + if( i0 < 0 ) { i0 = i; d = A.dims; - + // find the first dimensionality which is different from 1; // in any of the arrays the first "d1" step do not affect the continuity for( d1 = 0; d1 < d; d1++ ) @@ -3010,16 +3012,16 @@ void NAryMatIterator::init(const Mat** _arrays, Mat* _planes, uchar** _ptrs, int iterdepth = j; if( iterdepth == d1 ) iterdepth = 0; - + nplanes = 1; for( j = iterdepth-1; j >= 0; j-- ) nplanes *= arrays[i0]->size[j]; } else iterdepth = 0; - + idx = 0; - + if( !planes ) return; @@ -3027,14 +3029,14 @@ void NAryMatIterator::init(const Mat** _arrays, Mat* _planes, uchar** _ptrs, int { CV_Assert(arrays[i] != 0); const Mat& A = *arrays[i]; - + if( !A.data ) { planes[i] = Mat(); continue; } - - planes[i] = Mat(1, (int)size, A.type(), A.data); + + planes[i] = Mat(1, (int)size, A.type(), A.data); } } @@ -3044,7 +3046,7 @@ NAryMatIterator& NAryMatIterator::operator ++() if( idx >= nplanes-1 ) return *this; ++idx; - + if( iterdepth == 1 ) { if( ptrs ) @@ -3087,7 +3089,7 @@ NAryMatIterator& NAryMatIterator::operator ++() planes[i].data = data; } } - + return *this; } @@ -3107,7 +3109,7 @@ Point MatConstIterator::pos() const if( !m ) return Point(); CV_DbgAssert(m->dims <= 2); - + ptrdiff_t ofs = ptr - m->data; int y = (int)(ofs/m->step[0]); return Point((int)((ofs - y*m->step[0])/elemSize), y); @@ -3147,7 +3149,7 @@ ptrdiff_t MatConstIterator::lpos() const } return result; } - + void MatConstIterator::seek(ptrdiff_t ofs, bool relative) { if( m->isContinuous() ) @@ -3159,7 +3161,7 @@ void MatConstIterator::seek(ptrdiff_t ofs, bool relative) ptr = sliceEnd; return; } - + int d = m->dims; if( d == 2 ) { @@ -3178,20 +3180,20 @@ void MatConstIterator::seek(ptrdiff_t ofs, bool relative) sliceStart + (ofs - y*m->cols)*elemSize; return; } - + if( relative ) ofs += lpos(); - + if( ofs < 0 ) ofs = 0; - + int szi = m->size[d-1]; ptrdiff_t t = ofs/szi; int v = (int)(ofs - t*szi); ofs = t; ptr = m->data + v*elemSize; sliceStart = m->data; - + for( int i = d-2; i >= 0; i-- ) { szi = m->size[i]; @@ -3200,14 +3202,14 @@ void MatConstIterator::seek(ptrdiff_t ofs, bool relative) ofs = t; sliceStart += v*m->step[i]; } - + sliceEnd = sliceStart + m->size[d-1]*elemSize; if( ofs > 0 ) ptr = sliceEnd; else ptr = sliceStart + (ptr - m->data); } - + void MatConstIterator::seek(const int* _idx, bool relative) { int i, d = m->dims; @@ -3232,8 +3234,8 @@ ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a) return (b.ptr - a.ptr)/b.elemSize; return b.lpos() - a.lpos(); -} - +} + //////////////////////////////// SparseMat //////////////////////////////// template void @@ -3260,7 +3262,7 @@ convertScaleData_(const void* _from, void* _to, int cn, double alpha, double bet to[i] = saturate_cast(from[i]*alpha + beta); } -ConvertData getConvertData(int fromType, int toType) +static ConvertData getConvertData(int fromType, int toType) { static ConvertData tab[][8] = {{ convertData_, convertData_, @@ -3305,7 +3307,7 @@ ConvertData getConvertData(int fromType, int toType) return func; } -ConvertScaleData getConvertScaleData(int fromType, int toType) +static ConvertScaleData getConvertScaleData(int fromType, int toType) { static ConvertScaleData tab[][8] = {{ convertScaleData_, convertScaleData_, @@ -3382,7 +3384,7 @@ SparseMat::Hdr::Hdr( int _dims, const int* _sizes, int _type ) sizeof(int)*std::max(dims - CV_MAX_DIM, 0), CV_ELEM_SIZE1(_type)); nodeSize = alignSize(valueOffset + CV_ELEM_SIZE(_type), (int)sizeof(size_t)); - + int i; for( i = 0; i < dims; i++ ) size[i] = _sizes[i]; @@ -3420,7 +3422,7 @@ SparseMat::SparseMat(const Mat& m) uchar* to = newNode(idx, hash(idx)); copyElem( ptr, to, esz ); } - + for( i = d - 2; i >= 0; i-- ) { ptr += m.step[i] - m.size[i+1]*m.step[i+1]; @@ -3432,7 +3434,7 @@ SparseMat::SparseMat(const Mat& m) break; } } - + SparseMat::SparseMat(const CvSparseMat* m) : flags(MAGIC_VAL), hdr(0) { @@ -3525,11 +3527,11 @@ void SparseMat::convertTo( SparseMat& m, int rtype, double alpha ) const m = temp; return; } - + CV_Assert(hdr != 0); if( hdr != m.hdr ) m.create( hdr->dims, hdr->size, rtype ); - + SparseMatConstIterator from = begin(); size_t i, N = nzcount(); @@ -3540,7 +3542,7 @@ void SparseMat::convertTo( SparseMat& m, int rtype, double alpha ) const { const Node* n = from.node(); uchar* to = hdr == m.hdr ? from.ptr : m.newNode(n->idx, n->hashval); - cvtfunc( from.ptr, to, cn ); + cvtfunc( from.ptr, to, cn ); } } else @@ -3550,7 +3552,7 @@ void SparseMat::convertTo( SparseMat& m, int rtype, double alpha ) const { const Node* n = from.node(); uchar* to = hdr == m.hdr ? from.ptr : m.newNode(n->idx, n->hashval); - cvtfunc( from.ptr, to, cn, alpha, 0 ); + cvtfunc( from.ptr, to, cn, alpha, 0 ); } } } @@ -3562,7 +3564,7 @@ void SparseMat::convertTo( Mat& m, int rtype, double alpha, double beta ) const if( rtype < 0 ) rtype = type(); rtype = CV_MAKETYPE(rtype, cn); - + CV_Assert( hdr ); m.create( dims(), hdr->size, rtype ); m = Scalar(beta); @@ -3629,7 +3631,7 @@ uchar* SparseMat::ptr(int i0, bool createMissing, size_t* hashval) return &value(elem); nidx = elem->next; } - + if( createMissing ) { int idx[] = { i0 }; @@ -3637,7 +3639,7 @@ uchar* SparseMat::ptr(int i0, bool createMissing, size_t* hashval) } return 0; } - + uchar* SparseMat::ptr(int i0, int i1, bool createMissing, size_t* hashval) { CV_Assert( hdr && hdr->dims == 2 ); @@ -3810,7 +3812,7 @@ uchar* SparseMat::newNode(const int* idx, size_t hashval) resizeHashTab(std::max(hsize*2, (size_t)8)); hsize = hdr->hashtab.size(); } - + if( !hdr->freeList ) { size_t i, nsz = hdr->nodeSize, psize = hdr->pool.size(), @@ -3841,7 +3843,7 @@ uchar* SparseMat::newNode(const int* idx, size_t hashval) *((double*)p) = 0.; else memset(p, 0, esz); - + return p; } @@ -3913,14 +3915,14 @@ SparseMatConstIterator& SparseMatConstIterator::operator ++() double norm( const SparseMat& src, int normType ) { SparseMatConstIterator it = src.begin(); - + size_t i, N = src.nzcount(); normType &= NORM_TYPE_MASK; int type = src.type(); double result = 0; - + CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 ); - + if( type == CV_32F ) { if( normType == NORM_INF ) @@ -3932,7 +3934,7 @@ double norm( const SparseMat& src, int normType ) else for( i = 0; i < N; i++, ++it ) { - double v = *(const float*)it.ptr; + double v = *(const float*)it.ptr; result += v*v; } } @@ -3947,25 +3949,25 @@ double norm( const SparseMat& src, int normType ) else for( i = 0; i < N; i++, ++it ) { - double v = *(const double*)it.ptr; + double v = *(const double*)it.ptr; result += v*v; } } else CV_Error( CV_StsUnsupportedFormat, "Only 32f and 64f are supported" ); - + if( normType == NORM_L2 ) result = std::sqrt(result); return result; } - + void minMaxLoc( const SparseMat& src, double* _minval, double* _maxval, int* _minidx, int* _maxidx ) { SparseMatConstIterator it = src.begin(); size_t i, N = src.nzcount(), d = src.hdr ? src.hdr->dims : 0; int type = src.type(); const int *minidx = 0, *maxidx = 0; - + if( type == CV_32F ) { float minval = FLT_MAX, maxval = -FLT_MAX; @@ -4012,7 +4014,7 @@ void minMaxLoc( const SparseMat& src, double* _minval, double* _maxval, int* _mi } else CV_Error( CV_StsUnsupportedFormat, "Only 32f and 64f are supported" ); - + if( _minidx ) for( i = 0; i < d; i++ ) _minidx[i] = minidx[i]; @@ -4021,7 +4023,7 @@ void minMaxLoc( const SparseMat& src, double* _minval, double* _maxval, int* _mi _maxidx[i] = maxidx[i]; } - + void normalize( const SparseMat& src, SparseMat& dst, double a, int norm_type ) { double scale = 1; @@ -4032,18 +4034,18 @@ void normalize( const SparseMat& src, SparseMat& dst, double a, int norm_type ) } else CV_Error( CV_StsBadArg, "Unknown/unsupported norm type" ); - + src.convertTo( dst, -1, scale ); } ////////////////////// RotatedRect ////////////////////// - + void RotatedRect::points(Point2f pt[]) const { double _angle = angle*CV_PI/180.; float b = (float)cos(_angle)*0.5f; float a = (float)sin(_angle)*0.5f; - + pt[0].x = center.x - a*size.height - b*size.width; pt[0].y = center.y + b*size.height - a*size.width; pt[1].x = center.x + a*size.height - b*size.width; @@ -4065,8 +4067,8 @@ Rect RotatedRect::boundingRect() const r.width -= r.x - 1; r.height -= r.y - 1; return r; -} - } - + +} + /* End of file. */ diff --git a/modules/core/src/out.cpp b/modules/core/src/out.cpp index 366f5cf..6817fca 100644 --- a/modules/core/src/out.cpp +++ b/modules/core/src/out.cpp @@ -116,13 +116,13 @@ static void writeMat(std::ostream& out, const Mat& m, char rowsep, char elembrac { CV_Assert(m.dims <= 2); int type = m.type(); - + char crowbrace = getCloseBrace(rowsep); char orowbrace = crowbrace ? rowsep : '\0'; - + if( orowbrace || isspace(rowsep) ) rowsep = '\0'; - + for( int i = 0; i < m.rows; i++ ) { if(orowbrace) @@ -151,7 +151,7 @@ public: writeMat(out, m, ';', ' ', m.cols == 1); out << "]"; } - + void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const { writeElems(out, data, nelems, type, ' '); @@ -168,7 +168,7 @@ public: writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.cols*m.channels() == 1); out << "]"; } - + void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const { writeElems(out, data, nelems, type, '['); @@ -190,7 +190,7 @@ public: writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.cols*m.channels() == 1); out << "], type='" << numpyTypes[m.depth()] << "')"; } - + void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const { writeElems(out, data, nelems, type, '['); @@ -208,7 +208,7 @@ public: if(m.rows > 1) out << "\n"; } - + void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const { writeElems(out, data, nelems, type, ' '); @@ -226,7 +226,7 @@ public: writeMat(out, m, ',', ' ', m.cols==1); out << "}"; } - + void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const { writeElems(out, data, nelems, type, ' '); @@ -243,7 +243,7 @@ static CFormatter cFormatter; static const Formatter* g_defaultFormatter0 = &matlabFormatter; static const Formatter* g_defaultFormatter = &matlabFormatter; -bool my_streq(const char* a, const char* b) +static bool my_streq(const char* a, const char* b) { size_t i, alen = strlen(a), blen = strlen(b); if( alen != blen ) @@ -280,7 +280,7 @@ const Formatter* Formatter::setDefault(const Formatter* fmt) g_defaultFormatter = fmt; return prevFmt; } - + Formatted::Formatted(const Mat& _m, const Formatter* _fmt, const vector& _params) { @@ -288,12 +288,12 @@ Formatted::Formatted(const Mat& _m, const Formatter* _fmt, fmt = _fmt ? _fmt : Formatter::get(); std::copy(_params.begin(), _params.end(), back_inserter(params)); } - + Formatted::Formatted(const Mat& _m, const Formatter* _fmt, const int* _params) { mtx = _m; fmt = _fmt ? _fmt : Formatter::get(); - + if( _params ) { int i, maxParams = 100; diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index 499c44c..b5b08fb 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -54,7 +54,7 @@ template static inline Scalar rawToScalar(const T& v) for( i = 0; i < n; i++ ) s.val[i] = ((T1*)&v)[i]; return s; -} +} /****************************************************************************************\ * sum * @@ -72,7 +72,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn ) { ST s0 = dst[0]; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for(; i <= len - 4; i += 4, src += cn*4 ) s0 += src[0] + src[cn] + src[cn*2] + src[cn*3]; #endif @@ -104,7 +104,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn ) dst[1] = s1; dst[2] = s2; } - + for( ; k < cn; k += 4 ) { src = src0 + k; @@ -121,7 +121,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn ) } return len; } - + int i, nzm = 0; if( cn == 1 ) { @@ -155,7 +155,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn ) if( mask[i] ) { int k = 0; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for( ; k <= cn - 4; k += 4 ) { ST s0, s1; @@ -212,7 +212,7 @@ template static int countNonZero_(const T* src, int len ) { int i=0, nz = 0; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for(; i <= len - 4; i += 4 ) nz += (src[i] != 0) + (src[i+1] != 0) + (src[i+2] != 0) + (src[i+3] != 0); #endif @@ -251,12 +251,12 @@ template static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int len, int cn ) { const T* src = src0; - + if( !mask ) { int i; int k = cn % 4; - + if( k == 1 ) { ST s0 = sum[0]; @@ -296,7 +296,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le sum[0] = s0; sum[1] = s1; sum[2] = s2; sqsum[0] = sq0; sqsum[1] = sq1; sqsum[2] = sq2; } - + for( ; k < cn; k += 4 ) { src = src0 + k; @@ -319,7 +319,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le } return len; } - + int i, nzm = 0; if( cn == 1 ) @@ -368,7 +368,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le } } return nzm; -} +} static int sqsum8u( const uchar* src, const uchar* mask, int* sum, int* sqsum, int len, int cn ) @@ -407,9 +407,9 @@ cv::Scalar cv::sum( InputArray _src ) Mat src = _src.getMat(); int k, cn = src.channels(), depth = src.depth(); SumFunc func = sumTab[depth]; - + CV_Assert( cn <= 4 && func != 0 ); - + const Mat* arrays[] = {&src, 0}; uchar* ptrs[1]; NAryMatIterator it(arrays, ptrs); @@ -420,7 +420,7 @@ cv::Scalar cv::sum( InputArray _src ) int* buf = (int*)&s[0]; size_t esz = 0; bool blockSum = depth < CV_32S; - + if( blockSum ) { intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15); @@ -459,30 +459,30 @@ int cv::countNonZero( InputArray _src ) { Mat src = _src.getMat(); CountNonZeroFunc func = countNonZeroTab[src.depth()]; - + CV_Assert( src.channels() == 1 && func != 0 ); - + const Mat* arrays[] = {&src, 0}; uchar* ptrs[1]; NAryMatIterator it(arrays, ptrs); int total = (int)it.size, nz = 0; - + for( size_t i = 0; i < it.nplanes; i++, ++it ) nz += func( ptrs[0], total ); - + return nz; -} +} cv::Scalar cv::mean( InputArray _src, InputArray _mask ) { Mat src = _src.getMat(), mask = _mask.getMat(); CV_Assert( mask.empty() || mask.type() == CV_8U ); - + int k, cn = src.channels(), depth = src.depth(); SumFunc func = sumTab[depth]; - + CV_Assert( cn <= 4 && func != 0 ); - + const Mat* arrays[] = {&src, &mask, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); @@ -493,19 +493,19 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask ) int* buf = (int*)&s[0]; bool blockSum = depth <= CV_16S; size_t esz = 0, nz0 = 0; - + if( blockSum ) { intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15); blockSize = std::min(blockSize, intSumBlockSize); _buf.allocate(cn); buf = _buf; - + for( k = 0; k < cn; k++ ) buf[k] = 0; esz = src.elemSize(); } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -529,19 +529,19 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask ) } } return s*(nz0 ? 1./nz0 : 0); -} +} void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray _mask ) { Mat src = _src.getMat(), mask = _mask.getMat(); CV_Assert( mask.empty() || mask.type() == CV_8U ); - + int k, cn = src.channels(), depth = src.depth(); SumSqrFunc func = sumSqrTab[depth]; - + CV_Assert( func != 0 ); - + const Mat* arrays[] = {&src, &mask, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); @@ -552,10 +552,10 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input int *sbuf = (int*)s, *sqbuf = (int*)sq; bool blockSum = depth <= CV_16S, blockSqSum = depth <= CV_8S; size_t esz = 0; - + for( k = 0; k < cn; k++ ) s[k] = sq[k] = 0; - + if( blockSum ) { intSumBlockSize = 1 << 15; @@ -567,7 +567,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input sbuf[k] = sqbuf[k] = 0; esz = src.elemSize(); } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -598,14 +598,14 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input ptrs[1] += bsz; } } - + double scale = nz0 ? 1./nz0 : 0.; for( k = 0; k < cn; k++ ) { s[k] *= scale; sq[k] = std::sqrt(std::max(sq[k]*scale - s[k]*s[k], 0.)); } - + for( j = 0; j < 2; j++ ) { const double* sptr = j == 0 ? s : sq; @@ -640,7 +640,7 @@ minMaxIdx_( const T* src, const uchar* mask, WT* _minVal, WT* _maxVal, { WT minVal = *_minVal, maxVal = *_maxVal; size_t minIdx = *_minIdx, maxIdx = *_maxIdx; - + if( !mask ) { for( int i = 0; i < len; i++ ) @@ -708,7 +708,7 @@ static void minMaxIdx_32f(const float* src, const uchar* mask, float* minval, fl static void minMaxIdx_64f(const double* src, const uchar* mask, double* minval, double* maxval, size_t* minidx, size_t* maxidx, int len, size_t startidx ) -{ minMaxIdx_(src, mask, minval, maxval, minidx, maxidx, len, startidx ); } +{ minMaxIdx_(src, mask, minval, maxval, minidx, maxidx, len, startidx ); } typedef void (*MinMaxIdxFunc)(const uchar*, const uchar*, int*, int*, size_t*, size_t*, int, size_t); @@ -749,16 +749,16 @@ void cv::minMaxIdx(InputArray _src, double* minVal, { Mat src = _src.getMat(), mask = _mask.getMat(); int depth = src.depth(), cn = src.channels(); - + CV_Assert( (cn == 1 && (mask.empty() || mask.type() == CV_8U)) || (cn >= 1 && mask.empty() && !minIdx && !maxIdx) ); MinMaxIdxFunc func = minmaxTab[depth]; CV_Assert( func != 0 ); - + const Mat* arrays[] = {&src, &mask, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); - + size_t minidx = 0, maxidx = 0; int iminval = INT_MAX, imaxval = INT_MIN; float fminval = FLT_MAX, fmaxval = -FLT_MAX; @@ -766,39 +766,39 @@ void cv::minMaxIdx(InputArray _src, double* minVal, size_t startidx = 1; int *minval = &iminval, *maxval = &imaxval; int planeSize = (int)it.size*cn; - + if( depth == CV_32F ) minval = (int*)&fminval, maxval = (int*)&fmaxval; else if( depth == CV_64F ) minval = (int*)&dminval, maxval = (int*)&dmaxval; - + for( size_t i = 0; i < it.nplanes; i++, ++it, startidx += planeSize ) func( ptrs[0], ptrs[1], minval, maxval, &minidx, &maxidx, planeSize, startidx ); - + if( minidx == 0 ) dminval = dmaxval = 0; else if( depth == CV_32F ) dminval = fminval, dmaxval = fmaxval; else if( depth <= CV_32S ) dminval = iminval, dmaxval = imaxval; - + if( minVal ) *minVal = dminval; if( maxVal ) *maxVal = dmaxval; - + if( minIdx ) ofs2idx(src, minidx, minIdx); if( maxIdx ) ofs2idx(src, maxidx, maxIdx); -} +} void cv::minMaxLoc( InputArray _img, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, InputArray mask ) { Mat img = _img.getMat(); CV_Assert(img.dims <= 2); - + minMaxIdx(_img, minVal, maxVal, (int*)minLoc, (int*)maxLoc, mask); if( minLoc ) std::swap(minLoc->x, minLoc->y); @@ -821,7 +821,7 @@ float normL2Sqr_(const float* a, const float* b, int n) { float CV_DECL_ALIGNED(16) buf[4]; __m128 d0 = _mm_setzero_ps(), d1 = _mm_setzero_ps(); - + for( ; j <= n - 8; j += 8 ) { __m128 t0 = _mm_sub_ps(_mm_loadu_ps(a + j), _mm_loadu_ps(b + j)); @@ -834,14 +834,14 @@ float normL2Sqr_(const float* a, const float* b, int n) } else #endif - { + { for( ; j <= n - 4; j += 4 ) { float t0 = a[j] - b[j], t1 = a[j+1] - b[j+1], t2 = a[j+2] - b[j+2], t3 = a[j+3] - b[j+3]; d += t0*t0 + t1*t1 + t2*t2 + t3*t3; } } - + for( ; j < n; j++ ) { float t = a[j] - b[j]; @@ -861,7 +861,7 @@ float normL1_(const float* a, const float* b, int n) static const int CV_DECL_ALIGNED(16) absbuf[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; __m128 d0 = _mm_setzero_ps(), d1 = _mm_setzero_ps(); __m128 absmask = _mm_load_ps((const float*)absbuf); - + for( ; j <= n - 8; j += 8 ) { __m128 t0 = _mm_sub_ps(_mm_loadu_ps(a + j), _mm_loadu_ps(b + j)); @@ -894,12 +894,12 @@ int normL1_(const uchar* a, const uchar* b, int n) if( USE_SSE2 ) { __m128i d0 = _mm_setzero_si128(); - + for( ; j <= n - 16; j += 16 ) { __m128i t0 = _mm_loadu_si128((const __m128i*)(a + j)); __m128i t1 = _mm_loadu_si128((const __m128i*)(b + j)); - + d0 = _mm_add_epi32(d0, _mm_sad_epu8(t0, t1)); } @@ -907,7 +907,7 @@ int normL1_(const uchar* a, const uchar* b, int n) { __m128i t0 = _mm_cvtsi32_si128(*(const int*)(a + j)); __m128i t1 = _mm_cvtsi32_si128(*(const int*)(b + j)); - + d0 = _mm_add_epi32(d0, _mm_sad_epu8(t0, t1)); } d = _mm_cvtsi128_si32(_mm_add_epi32(d0, _mm_unpackhi_epi64(d0, d0))); @@ -926,7 +926,7 @@ int normL1_(const uchar* a, const uchar* b, int n) return d; } -static const uchar popCountTable[] = +static const uchar popCountTable[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, @@ -962,7 +962,7 @@ static const uchar popCountTable4[] = 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; -int normHamming(const uchar* a, int n) +static int normHamming(const uchar* a, int n) { int i = 0, result = 0; #if CV_NEON @@ -989,7 +989,7 @@ int normHamming(const uchar* a, int n) result += popCountTable[a[i]]; return result; } - + int normHamming(const uchar* a, const uchar* b, int n) { int i = 0, result = 0; @@ -1020,7 +1020,7 @@ int normHamming(const uchar* a, const uchar* b, int n) return result; } -int normHamming(const uchar* a, int n, int cellSize) +static int normHamming(const uchar* a, int n, int cellSize) { if( cellSize == 1 ) return normHamming(a, n); @@ -1039,8 +1039,8 @@ int normHamming(const uchar* a, int n, int cellSize) for( ; i < n; i++ ) result += tab[a[i]]; return result; -} - +} + int normHamming(const uchar* a, const uchar* b, int n, int cellSize) { if( cellSize == 1 ) @@ -1053,7 +1053,7 @@ int normHamming(const uchar* a, const uchar* b, int n, int cellSize) else CV_Error( CV_StsBadSize, "bad cell size (not 1, 2 or 4) in normHamming" ); int i = 0, result = 0; - #if CV_ENABLE_UNROLLED + #if CV_ENABLE_UNROLLED for( ; i <= n - 4; i += 4 ) result += tab[a[i] ^ b[i]] + tab[a[i+1] ^ b[i+1]] + tab[a[i+2] ^ b[i+2]] + tab[a[i+3] ^ b[i+3]]; @@ -1128,7 +1128,7 @@ normL2_(const T* src, const uchar* mask, ST* _result, int len, int cn) } *_result = result; return 0; -} +} template int normDiffInf_(const T* src1, const T* src2, const uchar* mask, ST* _result, int len, int cn) @@ -1194,7 +1194,7 @@ normDiffL2_(const T* src1, const T* src2, const uchar* mask, ST* _result, int le } *_result = result; return 0; -} +} #define CV_DEF_NORM_FUNC(L, suffix, type, ntype) \ @@ -1219,7 +1219,7 @@ CV_DEF_NORM_ALL(64f, double, double, double, double) typedef int (*NormFunc)(const uchar*, const uchar*, uchar*, int, int); -typedef int (*NormDiffFunc)(const uchar*, const uchar*, const uchar*, uchar*, int, int); +typedef int (*NormDiffFunc)(const uchar*, const uchar*, const uchar*, uchar*, int, int); static NormFunc normTab[3][8] = { @@ -1265,11 +1265,11 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) { Mat src = _src.getMat(), mask = _mask.getMat(); int depth = src.depth(), cn = src.channels(); - + normType &= 7; CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src.type() == CV_8U) ); - + if( src.isContinuous() && mask.empty() ) { size_t len = src.total()*cn; @@ -1278,7 +1278,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) if( depth == CV_32F ) { const float* data = src.ptr(); - + if( normType == NORM_L2 ) { double result = 0; @@ -1307,18 +1307,18 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) if( depth == CV_8U ) { const uchar* data = src.ptr(); - + if( normType == NORM_HAMMING ) return normHamming(data, (int)len); - + if( normType == NORM_HAMMING2 ) return normHamming(data, (int)len, 2); } } } - + CV_Assert( mask.empty() || mask.type() == CV_8U ); - + if( normType == NORM_HAMMING || normType == NORM_HAMMING2 ) { if( !mask.empty() ) @@ -1328,22 +1328,22 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) return norm(temp, normType); } int cellSize = normType == NORM_HAMMING ? 1 : 2; - + const Mat* arrays[] = {&src, 0}; uchar* ptrs[1]; NAryMatIterator it(arrays, ptrs); int total = (int)it.size; int result = 0; - + for( size_t i = 0; i < it.nplanes; i++, ++it ) result += normHamming(ptrs[0], total, cellSize); - + return result; } - + NormFunc func = normTab[normType >> 1][depth]; CV_Assert( func != 0 ); - + const Mat* arrays[] = {&src, &mask, 0}; uchar* ptrs[2]; union @@ -1361,7 +1361,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) int isum = 0; int *ibuf = &result.i; size_t esz = 0; - + if( blockSum ) { intSumBlockSize = (normType == NORM_L1 && depth <= CV_8S ? (1 << 23) : (1 << 15))/cn; @@ -1369,7 +1369,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) ibuf = &isum; esz = src.elemSize(); } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -1388,7 +1388,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) ptrs[1] += bsz; } } - + if( normType == NORM_INF ) { if( depth == CV_64F ) @@ -1400,7 +1400,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) } else if( normType == NORM_L2 ) result.d = std::sqrt(result.d); - + return result.d; } @@ -1409,16 +1409,16 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m { if( normType & CV_RELATIVE ) return norm(_src1, _src2, normType & ~CV_RELATIVE, _mask)/(norm(_src2, normType, _mask) + DBL_EPSILON); - + Mat src1 = _src1.getMat(), src2 = _src2.getMat(), mask = _mask.getMat(); int depth = src1.depth(), cn = src1.channels(); - + CV_Assert( src1.size == src2.size && src1.type() == src2.type() ); - + normType &= 7; CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U) ); - + if( src1.isContinuous() && src2.isContinuous() && mask.empty() ) { size_t len = src1.total()*src1.channels(); @@ -1428,7 +1428,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m { const float* data1 = src1.ptr(); const float* data2 = src2.ptr(); - + if( normType == NORM_L2 ) { double result = 0; @@ -1456,9 +1456,9 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m } } } - + CV_Assert( mask.empty() || mask.type() == CV_8U ); - + if( normType == NORM_HAMMING || normType == NORM_HAMMING2 ) { if( !mask.empty() ) @@ -1469,22 +1469,22 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m return norm(temp, normType); } int cellSize = normType == NORM_HAMMING ? 1 : 2; - + const Mat* arrays[] = {&src1, &src2, 0}; uchar* ptrs[2]; NAryMatIterator it(arrays, ptrs); int total = (int)it.size; int result = 0; - + for( size_t i = 0; i < it.nplanes; i++, ++it ) result += normHamming(ptrs[0], ptrs[1], total, cellSize); - + return result; } - + NormDiffFunc func = normDiffTab[normType >> 1][depth]; CV_Assert( func != 0 ); - + const Mat* arrays[] = {&src1, &src2, &mask, 0}; uchar* ptrs[3]; union @@ -1503,7 +1503,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m unsigned isum = 0; unsigned *ibuf = &result.u; size_t esz = 0; - + if( blockSum ) { intSumBlockSize = normType == NORM_L1 && depth <= CV_8S ? (1 << 23) : (1 << 15); @@ -1511,7 +1511,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m ibuf = &isum; esz = src1.elemSize(); } - + for( size_t i = 0; i < it.nplanes; i++, ++it ) { for( j = 0; j < total; j += blockSize ) @@ -1531,7 +1531,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m ptrs[2] += bsz; } } - + if( normType == NORM_INF ) { if( depth == CV_64F ) @@ -1543,7 +1543,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m } else if( normType == NORM_L2 ) result.d = std::sqrt(result.d); - + return result.d; } @@ -1692,7 +1692,7 @@ static void batchDistL2_32f(const float* src1, const float* src2, size_t step2, typedef void (*BatchDistFunc)(const uchar* src1, const uchar* src2, size_t step2, int nvecs, int len, uchar* dist, const uchar* mask); - + struct BatchDistInvoker { BatchDistInvoker( const Mat& _src1, const Mat& _src2, @@ -1709,26 +1709,26 @@ struct BatchDistInvoker update = _update; func = _func; } - + void operator()(const BlockedRange& range) const { AutoBuffer buf(src2->rows); int* bufptr = buf; - + for( int i = range.begin(); i < range.end(); i++ ) { func(src1->ptr(i), src2->ptr(), src2->step, src2->rows, src2->cols, K > 0 ? (uchar*)bufptr : dist->ptr(i), mask->data ? mask->ptr(i) : 0); - + if( K > 0 ) { int* nidxptr = nidx->ptr(i); // since positive float's can be compared just like int's, // we handle both CV_32S and CV_32F cases with a single branch int* distptr = (int*)dist->ptr(i); - + int j, k; - + for( j = 0; j < src2->rows; j++ ) { int d = bufptr[j]; @@ -1746,7 +1746,7 @@ struct BatchDistInvoker } } } - + const Mat *src1; const Mat *src2; Mat *dist; @@ -1756,9 +1756,9 @@ struct BatchDistInvoker int update; BatchDistFunc func; }; - + } - + void cv::batchDistance( InputArray _src1, InputArray _src2, OutputArray _dist, int dtype, OutputArray _nidx, int normType, int K, InputArray _mask, @@ -1769,7 +1769,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2, CV_Assert( type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)); CV_Assert( _nidx.needed() == (K > 0) ); - + if( dtype == -1 ) { dtype = normType == NORM_HAMMING || normType == NORM_HAMMING2 ? CV_32S : CV_32F; @@ -1777,7 +1777,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2, CV_Assert( (type == CV_8U && dtype == CV_32S) || dtype == CV_32F); K = std::min(K, src2.rows); - + _dist.create(src1.rows, (K > 0 ? K : src2.rows), dtype); Mat dist = _dist.getMat(), nidx; if( _nidx.needed() ) @@ -1785,19 +1785,19 @@ void cv::batchDistance( InputArray _src1, InputArray _src2, _nidx.create(dist.size(), CV_32S); nidx = _nidx.getMat(); } - + if( update == 0 && K > 0 ) { dist = Scalar::all(dtype == CV_32S ? (double)INT_MAX : (double)FLT_MAX); nidx = Scalar::all(-1); } - + if( crosscheck ) { CV_Assert( K == 1 && update == 0 && mask.empty() ); Mat tdist, tidx; batchDistance(src2, src1, tdist, dtype, tidx, normType, K, mask, 0, false); - + // if an idx-th element from src1 appeared to be the nearest to i-th element of src2, // we update the minimum mutual distance between idx-th element of src1 and the whole src2 set. // As a result, if nidx[idx] = i*, it means that idx-th element of src1 is the nearest @@ -1832,7 +1832,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2, } return; } - + BatchDistFunc func = 0; if( type == CV_8U ) { @@ -1860,12 +1860,12 @@ void cv::batchDistance( InputArray _src1, InputArray _src2, else if( normType == NORM_L2 ) func = (BatchDistFunc)batchDistL2_32f; } - + if( func == 0 ) CV_Error_(CV_StsUnsupportedFormat, ("The combination of type=%d, dtype=%d and normType=%d is not supported", type, dtype, normType)); - + parallel_for(BlockedRange(0, src1.rows), BatchDistInvoker(src1, src2, dist, nidx, K, mask, update, func)); } diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index b8c46fa..b48467c 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -88,7 +88,7 @@ #if defined __linux__ || defined __APPLE__ #include #include -#include +#include #if defined ANDROID #include #else @@ -111,7 +111,7 @@ Exception::~Exception() throw() {} /*! \return the error description and the context as a text string. - */ + */ const char* Exception::what() const throw() { return msg.c_str(); } void Exception::formatMessage() @@ -121,7 +121,7 @@ void Exception::formatMessage() else msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str()); } - + struct HWFeatures { enum { MAX_FEATURE = CV_HARDWARE_MAX_FEATURE }; @@ -374,7 +374,7 @@ int getThreadNum(void) #endif } -#if ANDROID +#ifdef ANDROID static inline int getNumberOfCPUsImpl() { FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r"); @@ -408,7 +408,7 @@ static inline int getNumberOfCPUsImpl() sscanf(pos, "%d-%d", &rstart, &rend); cpusAvailable += rend - rstart + 1; } - + } return cpusAvailable ? cpusAvailable : 1; } @@ -419,9 +419,9 @@ int getNumberOfCPUs(void) #if defined WIN32 || defined _WIN32 SYSTEM_INFO sysinfo; GetSystemInfo( &sysinfo ); - + return (int)sysinfo.dwNumberOfProcessors; -#elif ANDROID +#elif defined ANDROID static int ncpus = getNumberOfCPUsImpl(); printf("CPUS= %d\n", ncpus); return ncpus; @@ -430,24 +430,24 @@ int getNumberOfCPUs(void) #elif defined __APPLE__ int numCPU=0; int mib[4]; - size_t len = sizeof(numCPU); - + size_t len = sizeof(numCPU); + /* set the mib for hw.ncpu */ mib[0] = CTL_HW; mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU; - + /* get the number of CPUs from the system */ sysctl(mib, 2, &numCPU, &len, NULL, 0); - - if( numCPU < 1 ) + + if( numCPU < 1 ) { mib[1] = HW_NCPU; sysctl( mib, 2, &numCPU, &len, NULL, 0 ); - + if( numCPU < 1 ) numCPU = 1; } - + return (int)numCPU; #else return 1; @@ -475,7 +475,7 @@ string tempfile( const char* suffix ) { char buf[L_tmpnam]; char* name = 0; -#if ANDROID +#ifdef ANDROID strcpy(buf, "/sdcard/__opencv_temp_XXXXXX"); name = mktemp(buf); #else diff --git a/modules/core/test/test_ds.cpp b/modules/core/test/test_ds.cpp index bd12fd5..91c9727 100644 --- a/modules/core/test/test_ds.cpp +++ b/modules/core/test/test_ds.cpp @@ -45,11 +45,11 @@ static void cvTsClearSimpleSeq( CvTsSimpleSeq* seq ) static void cvTsSimpleSeqShiftAndCopy( CvTsSimpleSeq* seq, int from_idx, int to_idx, void* elem=0 ) { int elem_size = seq->elem_size; - + if( from_idx == to_idx ) return; assert( (from_idx > to_idx && !elem) || (from_idx < to_idx && elem) ); - + if( from_idx < seq->count ) { memmove( seq->array + to_idx*elem_size, seq->array + from_idx*elem_size, @@ -64,7 +64,7 @@ static void cvTsSimpleSeqInvert( CvTsSimpleSeq* seq ) { int i, k, len = seq->count, elem_size = seq->elem_size; schar *data = seq->array, t; - + for( i = 0; i < len/2; i++ ) { schar* a = data + i*elem_size; @@ -92,7 +92,7 @@ static void cvTsClearSimpleSet( CvTsSimpleSet* set_header ) { int i; int elem_size = set_header->elem_size; - + for( i = 0; i < set_header->max_count; i++ ) { set_header->array[i*elem_size] = 0; @@ -111,7 +111,7 @@ static CvTsSimpleSet* cvTsCreateSimpleSet( int max_count, int elem_size ) set_header->max_count = max_count; set_header->free_stack = (int*)(set_header + 1); set_header->array = (schar*)(set_header->free_stack + max_count); - + cvTsClearSimpleSet( set_header ); return set_header; } @@ -135,7 +135,7 @@ static int cvTsSimpleSetAdd( CvTsSimpleSet* set_header, void* elem ) { int idx, idx2; assert( set_header->free_count > 0 ); - + idx = set_header->free_stack[--set_header->free_count]; idx2 = idx * set_header->elem_size; assert( set_header->array[idx2] == 0 ); @@ -143,7 +143,7 @@ static int cvTsSimpleSetAdd( CvTsSimpleSet* set_header, void* elem ) if( set_header->elem_size > 1 ) memcpy( set_header->array + idx2 + 1, elem, set_header->elem_size - 1 ); set_header->count = MAX( set_header->count, idx + 1 ); - + return idx; } @@ -153,7 +153,7 @@ static void cvTsSimpleSetRemove( CvTsSimpleSet* set_header, int index ) assert( set_header->free_count < set_header->max_count && 0 <= index && index < set_header->max_count ); assert( set_header->array[index * set_header->elem_size] == 1 ); - + set_header->free_stack[set_header->free_count++] = index; set_header->array[index * set_header->elem_size] = 0; } @@ -184,7 +184,7 @@ static CvTsSimpleGraph* cvTsCreateSimpleGraph( int max_vtx_count, int vtx_size, int edge_size, int oriented ) { CvTsSimpleGraph* graph; - + assert( max_vtx_count > 1 && vtx_size >= 0 && edge_size >= 0 ); graph = (CvTsSimpleGraph*)cvAlloc( sizeof(*graph) + max_vtx_count * max_vtx_count * (edge_size + 1)); @@ -192,7 +192,7 @@ static CvTsSimpleGraph* cvTsCreateSimpleGraph( int max_vtx_count, int vtx_size, graph->edge_size = edge_size + 1; graph->matrix = (char*)(graph + 1); graph->oriented = oriented; - + cvTsClearSimpleGraph( graph ); return graph; } @@ -219,7 +219,7 @@ static void cvTsSimpleGraphRemoveVertex( CvTsSimpleGraph* graph, int index ) int i, max_vtx_count = graph->vtx->max_count; int edge_size = graph->edge_size; cvTsSimpleSetRemove( graph->vtx, index ); - + /* remove all the corresponding edges */ for( i = 0; i < max_vtx_count; i++ ) { @@ -232,10 +232,10 @@ static void cvTsSimpleGraphRemoveVertex( CvTsSimpleGraph* graph, int index ) static void cvTsSimpleGraphAddEdge( CvTsSimpleGraph* graph, int idx1, int idx2, void* edge ) { int i, t, n = graph->oriented ? 1 : 2; - + assert( cvTsSimpleSetFind( graph->vtx, idx1 ) && cvTsSimpleSetFind( graph->vtx, idx2 )); - + for( i = 0; i < n; i++ ) { int ofs = (idx1*graph->vtx->max_count + idx2)*graph->edge_size; @@ -243,7 +243,7 @@ static void cvTsSimpleGraphAddEdge( CvTsSimpleGraph* graph, int idx1, int idx2, graph->matrix[ofs] = 1; if( graph->edge_size > 1 ) memcpy( graph->matrix + ofs + 1, edge, graph->edge_size - 1 ); - + CV_SWAP( idx1, idx2, t ); } } @@ -252,10 +252,10 @@ static void cvTsSimpleGraphAddEdge( CvTsSimpleGraph* graph, int idx1, int idx2, static void cvTsSimpleGraphRemoveEdge( CvTsSimpleGraph* graph, int idx1, int idx2 ) { int i, t, n = graph->oriented ? 1 : 2; - + assert( cvTsSimpleSetFind( graph->vtx, idx1 ) && cvTsSimpleSetFind( graph->vtx, idx2 )); - + for( i = 0; i < n; i++ ) { int ofs = (idx1*graph->vtx->max_count + idx2)*graph->edge_size; @@ -290,13 +290,13 @@ static int cvTsSimpleGraphVertexDegree( CvTsSimpleGraph* graph, int index ) int edge_size = graph->edge_size; int max_vtx_count = graph->vtx->max_count; assert( cvTsSimpleGraphFindVertex( graph, index ) != 0 ); - + for( i = 0; i < max_vtx_count; i++ ) { count += graph->matrix[(i*max_vtx_count + index)*edge_size] + graph->matrix[(index*max_vtx_count + i)*edge_size]; } - + if( !graph->oriented ) { assert( count % 2 == 0 ); @@ -323,7 +323,7 @@ public: virtual ~Core_DynStructBaseTest(); bool can_do_fast_forward(); void clear(); - + protected: int read_params( CvFileStorage* fs ); void run_func(void); @@ -332,7 +332,7 @@ protected: const char* file, int line ); int test_seq_block_consistence( int _struct_idx, CvSeq* seq, int total ); void update_progressbar(); - + int struct_count, max_struct_size, iterations, generations; int min_log_storage_block_size, max_log_storage_block_size; int min_log_elem_size, max_log_elem_size; @@ -358,7 +358,7 @@ Core_DynStructBaseTest::Core_DynStructBaseTest() iterations = max_struct_size*2; gen = struct_idx = iter = -1; test_progress = -1; - + storage = 0; } @@ -391,33 +391,33 @@ int Core_DynStructBaseTest::read_params( CvFileStorage* fs ) double sqrt_scale = sqrt(ts->get_test_case_count_scale()); if( code < 0 ) return code; - + struct_count = cvReadInt( find_param( fs, "struct_count" ), struct_count ); max_struct_size = cvReadInt( find_param( fs, "max_struct_size" ), max_struct_size ); generations = cvReadInt( find_param( fs, "generations" ), generations ); iterations = cvReadInt( find_param( fs, "iterations" ), iterations ); generations = cvRound(generations*sqrt_scale); iterations = cvRound(iterations*sqrt_scale); - + min_log_storage_block_size = cvReadInt( find_param( fs, "min_log_storage_block_size" ), min_log_storage_block_size ); max_log_storage_block_size = cvReadInt( find_param( fs, "max_log_storage_block_size" ), max_log_storage_block_size ); min_log_elem_size = cvReadInt( find_param( fs, "min_log_elem_size" ), min_log_elem_size ); max_log_elem_size = cvReadInt( find_param( fs, "max_log_elem_size" ), max_log_elem_size ); - + struct_count = cvtest::clipInt( struct_count, 1, 100 ); max_struct_size = cvtest::clipInt( max_struct_size, 1, 1<<20 ); generations = cvtest::clipInt( generations, 1, 100 ); iterations = cvtest::clipInt( iterations, 100, 1<<20 ); - + min_log_storage_block_size = cvtest::clipInt( min_log_storage_block_size, 7, 20 ); max_log_storage_block_size = cvtest::clipInt( max_log_storage_block_size, min_log_storage_block_size, 20 ); - + min_log_elem_size = cvtest::clipInt( min_log_elem_size, 0, 8 ); max_log_elem_size = cvtest::clipInt( max_log_elem_size, min_log_elem_size, 10 ); - + return 0; } @@ -425,14 +425,14 @@ int Core_DynStructBaseTest::read_params( CvFileStorage* fs ) void Core_DynStructBaseTest::update_progressbar() { int64 t; - + if( test_progress < 0 ) { test_progress = 0; cpu_freq = cv::getTickFrequency(); start_time = cv::getTickCount(); } - + t = cv::getTickCount(); test_progress = update_progress( test_progress, 0, 0, (double)(t - start_time)/cpu_freq ); } @@ -453,16 +453,16 @@ int Core_DynStructBaseTest::test_seq_block_consistence( int _struct_idx, CvSeq* { int sum = 0; struct_idx = _struct_idx; - + CV_TS_SEQ_CHECK_CONDITION( seq != 0, "Null sequence pointer" ); - + if( seq->first ) { CvSeqBlock* block = seq->first; CvSeqBlock* prev_block = block->prev; - + int delta_idx = seq->first->start_index; - + for( ;; ) { CV_TS_SEQ_CHECK_CONDITION( sum == block->start_index - delta_idx && @@ -474,15 +474,15 @@ int Core_DynStructBaseTest::test_seq_block_consistence( int _struct_idx, CvSeq* block = block->next; if( block == seq->first ) break; } - + CV_TS_SEQ_CHECK_CONDITION( block->prev->count * seq->elem_size + block->prev->data <= seq->block_max, "block->data or block_max pointer are incorrect" ); } - + CV_TS_SEQ_CHECK_CONDITION( seq->total == sum && sum == total, "total number of elements is incorrect" ); - + return 0; } @@ -495,7 +495,7 @@ public: Core_SeqBaseTest(); void clear(); void run( int ); - + protected: int test_multi_create(); int test_get_seq_elem( int _struct_idx, int iters ); @@ -524,20 +524,20 @@ int Core_SeqBaseTest::test_multi_create() vector index(struct_count); int cur_count, elem_size; RNG& rng = ts->get_rng(); - + for( int i = 0; i < struct_count; i++ ) { double t; CvTsSimpleSeq* sseq; - + pos[i] = -1; index[i] = i; - + t = cvtest::randReal(rng)*(max_log_elem_size - min_log_elem_size) + min_log_elem_size; elem_size = cvRound( exp(t * CV_LOG2) ); elem_size = MIN( elem_size, (int)(storage->block_size - sizeof(void*) - sizeof(CvSeqBlock) - sizeof(CvMemBlock)) ); - + cvTsReleaseSimpleSeq( (CvTsSimpleSeq**)&simple_struct[i] ); simple_struct[i] = sseq = cvTsCreateSimpleSeq( max_struct_size, elem_size ); cxcore_struct[i] = 0; @@ -545,7 +545,7 @@ int Core_SeqBaseTest::test_multi_create() Mat m( 1, MAX(sseq->count,1)*elem_size, CV_8UC1, sseq->array ); cvtest::randUni( rng, m, Scalar::all(0), Scalar::all(256) ); } - + for( cur_count = struct_count; cur_count > 0; cur_count-- ) { for(;;) @@ -553,13 +553,13 @@ int Core_SeqBaseTest::test_multi_create() int k = cvtest::randInt( rng ) % cur_count; struct_idx = index[k]; CvTsSimpleSeq* sseq = (CvTsSimpleSeq*)simple_struct[struct_idx]; - + if( pos[struct_idx] < 0 ) { int hdr_size = (cvtest::randInt(rng) % 10)*4 + sizeof(CvSeq); hdr_size = MIN( hdr_size, (int)(storage->block_size - sizeof(CvMemBlock)) ); elem_size = sseq->elem_size; - + if( cvtest::randInt(rng) % 2 ) { cvStartWriteSeq( 0, hdr_size, elem_size, storage, &writer[struct_idx] ); @@ -570,11 +570,11 @@ int Core_SeqBaseTest::test_multi_create() s = cvCreateSeq( 0, hdr_size, elem_size, storage ); cvStartAppendToSeq( s, &writer[struct_idx] ); } - + cvSetSeqBlockSize( writer[struct_idx].seq, cvtest::randInt( rng ) % 10000 ); pos[struct_idx] = 0; } - + update_progressbar(); if( pos[struct_idx] == sseq->count ) { @@ -584,7 +584,7 @@ int Core_SeqBaseTest::test_multi_create() index[k] = index[k+1]; break; } - + { schar* el = cvTsSimpleSeqElem( sseq, pos[struct_idx] ); CV_WRITE_SEQ_ELEM_VAR( el, writer[struct_idx] ); @@ -592,7 +592,7 @@ int Core_SeqBaseTest::test_multi_create() pos[struct_idx]++; } } - + return 0; } @@ -600,16 +600,16 @@ int Core_SeqBaseTest::test_multi_create() int Core_SeqBaseTest::test_get_seq_elem( int _struct_idx, int iters ) { RNG& rng = ts->get_rng(); - + CvSeq* seq = (CvSeq*)cxcore_struct[_struct_idx]; CvTsSimpleSeq* sseq = (CvTsSimpleSeq*)simple_struct[_struct_idx]; struct_idx = _struct_idx; - + assert( seq->total == sseq->count ); - + if( sseq->count == 0 ) return 0; - + for( int i = 0; i < iters; i++ ) { int idx = cvtest::randInt(rng) % (sseq->count*3) - sseq->count*3/2; @@ -618,7 +618,7 @@ int Core_SeqBaseTest::test_get_seq_elem( int _struct_idx, int iters ) int bad_range = (unsigned)idx0 >= (unsigned)(sseq->count); schar* elem; elem = cvGetSeqElem( seq, idx ); - + if( bad_range ) { CV_TS_SEQ_CHECK_CONDITION( elem == 0, @@ -630,13 +630,13 @@ int Core_SeqBaseTest::test_get_seq_elem( int _struct_idx, int iters ) CV_TS_SEQ_CHECK_CONDITION( elem != 0 && !memcmp( elem, cvTsSimpleSeqElem(sseq, idx0), sseq->elem_size ), "cvGetSeqElem returns wrong element" ); - + idx = cvSeqElemIdx(seq, elem ); CV_TS_SEQ_CHECK_CONDITION( idx >= 0 && idx == idx0, "cvSeqElemIdx is incorrect" ); } } - + return 0; } @@ -651,43 +651,43 @@ int Core_SeqBaseTest::test_get_seq_reading( int _struct_idx, int iters ) CvSeqReader reader; vector _elem(sseq->elem_size); schar* elem = &_elem[0]; - + assert( total == sseq->count ); this->struct_idx = _struct_idx; - + int pos = cvtest::randInt(rng) % 2; cvStartReadSeq( seq, &reader, pos ); - + if( total == 0 ) { CV_TS_SEQ_CHECK_CONDITION( reader.ptr == 0, "Empty sequence reader pointer is not NULL" ); return 0; } - + pos = pos ? seq->total - 1 : 0; - + CV_TS_SEQ_CHECK_CONDITION( pos == cvGetSeqReaderPos(&reader), "initial reader position is wrong" ); - + for( iter = 0; iter < iters; iter++ ) { int op = cvtest::randInt(rng) % max_val; - + if( op >= max_val - 2 ) { int new_pos, new_pos0; int bad_range; int is_relative = op == max_val - 1; - + new_pos = cvtest::randInt(rng) % (total*2) - total; new_pos0 = new_pos + (is_relative ? pos : 0 ); - + if( new_pos0 < 0 ) new_pos0 += total; if( new_pos0 >= total ) new_pos0 -= total; - + bad_range = (unsigned)new_pos0 >= (unsigned)total; cvSetSeqReaderPos( &reader, new_pos, is_relative ); - + if( !bad_range ) { CV_TS_SEQ_CHECK_CONDITION( new_pos0 == cvGetSeqReaderPos( &reader ), @@ -704,7 +704,7 @@ int Core_SeqBaseTest::test_get_seq_reading( int _struct_idx, int iters ) { int direction = (op % 3) - 1; memcpy( elem, reader.ptr, sseq->elem_size ); - + if( direction > 0 ) { CV_NEXT_SEQ_ELEM( sseq->elem_size, reader ); @@ -713,18 +713,18 @@ int Core_SeqBaseTest::test_get_seq_reading( int _struct_idx, int iters ) { CV_PREV_SEQ_ELEM( sseq->elem_size, reader ); } - + CV_TS_SEQ_CHECK_CONDITION( memcmp(elem, cvTsSimpleSeqElem(sseq, pos), sseq->elem_size) == 0, "reading is incorrect" ); pos += direction; if( -pos > 0 ) pos += total; if( pos >= total ) pos -= total; - + CV_TS_SEQ_CHECK_CONDITION( pos == cvGetSeqReaderPos( &reader ), "reader doesn't move correctly after reading" ); } } - + return 0; } @@ -735,14 +735,14 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) int max_elem_size = 0; schar* elem2 = 0; RNG& rng = ts->get_rng(); - + for( int i = 0; i < struct_count; i++ ) max_elem_size = MAX( max_elem_size, ((CvSeq*)cxcore_struct[i])->elem_size ); - + vector elem_buf(max_struct_size*max_elem_size); schar* elem = (schar*)&elem_buf[0]; Mat elem_mat; - + for( iter = 0; iter < iters; iter++ ) { struct_idx = cvtest::randInt(rng) % struct_count; @@ -751,7 +751,7 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) CvTsSimpleSeq* sseq = (CvTsSimpleSeq*)simple_struct[struct_idx]; int elem_size = sseq->elem_size; int whence = 0, pos = 0, count = 0; - + switch( op ) { case 0: @@ -759,10 +759,10 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) case 2: // push/pushfront/insert if( sseq->count == sseq->max_count ) break; - + elem_mat = Mat(1, elem_size, CV_8U, elem); cvtest::randUni( rng, elem_mat, cvScalarAll(0), cvScalarAll(255) ); - + whence = op - 1; if( whence < 0 ) { @@ -779,7 +779,7 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) pos = cvtest::randInt(rng) % (sseq->count + 1); cvSeqInsert( seq, pos, elem ); } - + cvTsSimpleSeqShiftAndCopy( sseq, pos, pos + 1, elem ); elem2 = cvGetSeqElem( seq, pos ); CV_TS_SEQ_CHECK_CONDITION( elem2 != 0, "The inserted element could not be retrieved" ); @@ -787,13 +787,13 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) memcmp(elem2, cvTsSimpleSeqElem(sseq,pos), elem_size) == 0, "The inserted sequence element is wrong" ); break; - + case 3: case 4: case 5: // pop/popfront/remove if( sseq->count == 0 ) break; - + whence = op - 4; if( whence < 0 ) { @@ -810,19 +810,19 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) pos = cvtest::randInt(rng) % sseq->count; cvSeqRemove( seq, pos ); } - + if( whence != 0 ) CV_TS_SEQ_CHECK_CONDITION( seq->total == sseq->count - 1 && memcmp( elem, cvTsSimpleSeqElem(sseq,pos), elem_size) == 0, "The popped sequence element isn't correct" ); - + cvTsSimpleSeqShiftAndCopy( sseq, pos + 1, pos ); - + if( sseq->count > 0 ) { elem2 = cvGetSeqElem( seq, pos < sseq->count ? pos : -1 ); CV_TS_SEQ_CHECK_CONDITION( elem2 != 0, "GetSeqElem fails after removing the element" ); - + CV_TS_SEQ_CHECK_CONDITION( memcmp( elem2, cvTsSimpleSeqElem(sseq, pos - (pos == sseq->count)), elem_size) == 0, "The first shifted element is not correct after removing another element" ); @@ -833,17 +833,17 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) "The sequence doesn't become empty after the final remove" ); } break; - + case 6: case 7: case 8: // push [front] multi/insert slice if( sseq->count == sseq->max_count ) break; - + count = cvtest::randInt( rng ) % (sseq->max_count - sseq->count + 1); elem_mat = Mat(1, MAX(count,1) * elem_size, CV_8U, elem); cvtest::randUni( rng, elem_mat, cvScalarAll(0), cvScalarAll(255) ); - + whence = op - 7; pos = whence < 0 ? 0 : whence > 0 ? sseq->count : cvtest::randInt(rng) % (sseq->count+1); if( whence != 0 ) @@ -858,11 +858,11 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) sseq->elem_size, elem, count, &header, &block ); - + cvSeqInsertSlice( seq, pos, &header ); } cvTsSimpleSeqShiftAndCopy( sseq, pos, pos + count, elem ); - + if( sseq->count > 0 ) { // choose the random element among the added @@ -879,22 +879,22 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) "Adding no elements to empty sequence fails" ); } break; - + case 9: case 10: case 11: // pop [front] multi if( sseq->count == 0 ) break; - + count = cvtest::randInt(rng) % (sseq->count+1); whence = op - 10; pos = whence < 0 ? 0 : whence > 0 ? sseq->count - count : cvtest::randInt(rng) % (sseq->count - count + 1); - + if( whence != 0 ) { cvSeqPopMulti( seq, elem, count, whence < 0 ); - + if( count > 0 ) { CV_TS_SEQ_CHECK_CONDITION( memcmp(elem, @@ -906,10 +906,10 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) { cvSeqRemoveSlice( seq, cvSlice(pos, pos + count) ); } - + CV_TS_SEQ_CHECK_CONDITION( seq->total == sseq->count - count, "The popmulti left a wrong number of elements in the sequence" ); - + cvTsSimpleSeqShiftAndCopy( sseq, pos + count, pos, 0 ); if( sseq->count > 0 ) { @@ -929,15 +929,15 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) { CvMemStoragePos storage_pos; cvSaveMemStoragePos( storage, &storage_pos ); - + int copy_data = cvtest::randInt(rng) % 2; count = cvtest::randInt(rng) % (seq->total + 1); pos = cvtest::randInt(rng) % (seq->total - count + 1); CvSeq* seq_slice = cvSeqSlice( seq, cvSlice(pos, pos + count), storage, copy_data ); - + CV_TS_SEQ_CHECK_CONDITION( seq_slice && seq_slice->total == count, "cvSeqSlice returned incorrect slice" ); - + if( count > 0 ) { int test_idx = cvtest::randInt(rng) % count; @@ -949,7 +949,7 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) CV_TS_SEQ_CHECK_CONDITION( (elem2 == elem3) ^ copy_data, "copy_data flag is handled incorrectly" ); } - + cvRestoreMemStoragePos( storage, &storage_pos ); } break; @@ -963,16 +963,16 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) assert(0); return -1; } - + if( test_seq_block_consistence(struct_idx, seq, sseq->count) < 0 ) return -1; - + if( test_get_seq_elem(struct_idx, 7) < 0 ) return -1; - + update_progressbar(); } - + return 0; } @@ -984,44 +984,44 @@ void Core_SeqBaseTest::run( int ) RNG& rng = ts->get_rng(); int i; double t; - + clear(); test_progress = -1; - + simple_struct.resize(struct_count, 0); cxcore_struct.resize(struct_count, 0); - + for( gen = 0; gen < generations; gen++ ) { struct_idx = iter = -1; - + if( !storage ) { t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size) + min_log_storage_block_size; storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ); } - + iter = struct_idx = -1; test_multi_create(); - + for( i = 0; i < struct_count; i++ ) { if( test_seq_block_consistence(i, (CvSeq*)cxcore_struct[i], ((CvTsSimpleSeq*)simple_struct[i])->count) < 0 ) return; - + if( test_get_seq_elem( i, MAX(iterations/3,7) ) < 0 ) return; - + if( test_get_seq_reading( i, MAX(iterations/3,7) ) < 0 ) return; update_progressbar(); } - + if( test_seq_ops( iterations ) < 0 ) return; - + if( cvtest::randInt(rng) % 2 ) storage.release(); else @@ -1041,7 +1041,7 @@ class Core_SeqSortInvTest : public Core_SeqBaseTest public: Core_SeqSortInvTest(); void run( int ); - + protected: }; @@ -1072,73 +1072,73 @@ void Core_SeqSortInvTest::run( int ) double t; schar *elem0, *elem, *elem2; vector buffer; - + clear(); test_progress = -1; - + simple_struct.resize(struct_count, 0); cxcore_struct.resize(struct_count, 0); - + for( gen = 0; gen < generations; gen++ ) { struct_idx = iter = -1; - + if( storage.empty() ) { t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size) + min_log_storage_block_size; storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ); } - + for( iter = 0; iter < iterations/10; iter++ ) { int max_size = 0; test_multi_create(); - + for( i = 0; i < struct_count; i++ ) { CvTsSimpleSeq* sseq = (CvTsSimpleSeq*)simple_struct[i]; max_size = MAX( max_size, sseq->count*sseq->elem_size ); } - + buffer.resize(max_size); - + for( i = 0; i < struct_count; i++ ) { CvSeq* seq = (CvSeq*)cxcore_struct[i]; CvTsSimpleSeq* sseq = (CvTsSimpleSeq*)simple_struct[i]; CvSlice slice = CV_WHOLE_SEQ; - + //printf("%d. %d. %d-th size = %d\n", gen, iter, i, sseq->count ); - + cvSeqInvert( seq ); cvTsSimpleSeqInvert( sseq ); - + if( test_seq_block_consistence( i, seq, sseq->count ) < 0 ) return; - + if( sseq->count > 0 && cvtest::randInt(rng) % 2 == 0 ) { slice.end_index = cvtest::randInt(rng) % sseq->count + 1; slice.start_index = cvtest::randInt(rng) % (sseq->count - slice.end_index + 1); slice.end_index += slice.start_index; } - + cvCvtSeqToArray( seq, &buffer[0], slice ); - + slice.end_index = MIN( slice.end_index, sseq->count ); CV_TS_SEQ_CHECK_CONDITION( sseq->count == 0 || memcmp( &buffer[0], sseq->array + slice.start_index*sseq->elem_size, (slice.end_index - slice.start_index)*sseq->elem_size ) == 0, "cvSeqInvert returned wrong result" ); - + for( k = 0; k < (sseq->count > 0 ? 10 : 0); k++ ) { int idx0 = cvtest::randInt(rng) % sseq->count, idx = 0; elem0 = cvTsSimpleSeqElem( sseq, idx0 ); elem = cvGetSeqElem( seq, idx0 ); elem2 = cvSeqSearch( seq, elem0, k % 2 ? icvCmpSeqElems : 0, 0, &idx, seq ); - + CV_TS_SEQ_CHECK_CONDITION( elem != 0 && memcmp( elem0, elem, seq->elem_size ) == 0, "cvSeqInvert gives incorrect result" ); @@ -1147,18 +1147,18 @@ void Core_SeqSortInvTest::run( int ) elem2 == cvGetSeqElem( seq, idx ), "cvSeqSearch failed (linear search)" ); } - + cvSeqSort( seq, icvCmpSeqElems, seq ); - + if( test_seq_block_consistence( i, seq, sseq->count ) < 0 ) return; - + if( sseq->count > 0 ) { // !!! This is not thread-safe !!! icvCmpSeqElems2_elem_size = sseq->elem_size; qsort( sseq->array, sseq->count, sseq->elem_size, icvCmpSeqElems2 ); - + if( cvtest::randInt(rng) % 2 == 0 ) { slice.end_index = cvtest::randInt(rng) % sseq->count + 1; @@ -1166,20 +1166,20 @@ void Core_SeqSortInvTest::run( int ) slice.end_index += slice.start_index; } } - + cvCvtSeqToArray( seq, &buffer[0], slice ); CV_TS_SEQ_CHECK_CONDITION( sseq->count == 0 || memcmp( &buffer[0], sseq->array + slice.start_index*sseq->elem_size, (slice.end_index - slice.start_index)*sseq->elem_size ) == 0, "cvSeqSort returned wrong result" ); - + for( k = 0; k < (sseq->count > 0 ? 10 : 0); k++ ) { int idx0 = cvtest::randInt(rng) % sseq->count, idx = 0; elem0 = cvTsSimpleSeqElem( sseq, idx0 ); elem = cvGetSeqElem( seq, idx0 ); elem2 = cvSeqSearch( seq, elem0, icvCmpSeqElems, 1, &idx, seq ); - + CV_TS_SEQ_CHECK_CONDITION( elem != 0 && memcmp( elem0, elem, seq->elem_size ) == 0, "cvSeqSort gives incorrect result" ); @@ -1189,10 +1189,10 @@ void Core_SeqSortInvTest::run( int ) "cvSeqSearch failed (binary search)" ); } } - + cvClearMemStorage( storage ); } - + storage.release(); } } @@ -1210,7 +1210,7 @@ public: Core_SetTest(); void clear(); void run( int ); - + protected: //int test_seq_block_consistence( int struct_idx ); int test_set_ops( int iters ); @@ -1239,17 +1239,17 @@ int Core_SetTest::test_set_ops( int iters ) schar* elem_data = 0; RNG& rng = ts->get_rng(); //int max_active_count = 0, mean_active_count = 0; - + for( int i = 0; i < struct_count; i++ ) max_elem_size = MAX( max_elem_size, ((CvSeq*)cxcore_struct[i])->elem_size ); - + vector elem_buf(max_elem_size); Mat elem_mat; - + for( iter = 0; iter < iters; iter++ ) { struct_idx = cvtest::randInt(rng) % struct_count; - + CvSet* cvset = (CvSet*)cxcore_struct[struct_idx]; CvTsSimpleSet* sset = (CvTsSimpleSet*)simple_struct[struct_idx]; int pure_elem_size = sset->elem_size - 1; @@ -1259,13 +1259,13 @@ int Core_SetTest::test_set_ops( int iters ) CvSetElem* first_free = cvset->free_elems; CvSetElem* next_free = first_free ? first_free->next_free : 0; int pass_data = 0; - + if( iter > iters/10 && cvtest::randInt(rng)%200 == 0 ) // clear set { int prev_count = cvset->total; cvClearSet( cvset ); cvTsClearSimpleSet( sset ); - + CV_TS_SEQ_CHECK_CONDITION( cvset->active_count == 0 && cvset->total == 0 && cvset->first == 0 && cvset->free_elems == 0 && (cvset->free_blocks != 0 || prev_count == 0), @@ -1276,11 +1276,11 @@ int Core_SetTest::test_set_ops( int iters ) { if( sset->free_count == 0 ) continue; - + elem_mat = Mat(1, cvset->elem_size, CV_8U, &elem_buf[0]); cvtest::randUni( rng, elem_mat, cvScalarAll(0), cvScalarAll(255) ); elem = (CvSetElem*)&elem_buf[0]; - + if( by_ptr ) { elem2 = cvSetNew( cvset ); @@ -1293,21 +1293,21 @@ int Core_SetTest::test_set_ops( int iters ) CV_TS_SEQ_CHECK_CONDITION( elem2 != 0 && elem2->flags == idx, "cvSetAdd returned NULL pointer or a wrong index" ); } - + elem_data = (schar*)elem + sizeof(int); - + if( !pass_data ) memcpy( (schar*)elem2 + sizeof(int), elem_data, pure_elem_size ); - + idx = elem2->flags; idx0 = cvTsSimpleSetAdd( sset, elem_data ); elem3 = cvGetSetElem( cvset, idx ); - + CV_TS_SEQ_CHECK_CONDITION( CV_IS_SET_ELEM(elem3) && idx == idx0 && elem3 == elem2 && (!pass_data || memcmp( (char*)elem3 + sizeof(int), elem_data, pure_elem_size) == 0), "The added element is not correct" ); - + CV_TS_SEQ_CHECK_CONDITION( (!first_free || elem3 == first_free) && (!next_free || cvset->free_elems == next_free) && cvset->active_count == prev_count + 1, @@ -1316,19 +1316,19 @@ int Core_SetTest::test_set_ops( int iters ) else if( op == 2 || op == 3 ) // remove element { idx = cvtest::randInt(rng) % sset->max_count; - + if( sset->free_count == sset->max_count || idx >= sset->count ) continue; - + elem_data = cvTsSimpleSetFind(sset, idx); if( elem_data == 0 ) continue; - + elem = cvGetSetElem( cvset, idx ); CV_TS_SEQ_CHECK_CONDITION( CV_IS_SET_ELEM(elem) && elem->flags == idx && memcmp((char*)elem + sizeof(int), elem_data, pure_elem_size) == 0, "cvGetSetElem returned wrong element" ); - + if( by_ptr ) { cvSetRemoveByPtr( cvset, elem ); @@ -1337,32 +1337,32 @@ int Core_SetTest::test_set_ops( int iters ) { cvSetRemove( cvset, idx ); } - + cvTsSimpleSetRemove( sset, idx ); - + CV_TS_SEQ_CHECK_CONDITION( !CV_IS_SET_ELEM(elem) && !cvGetSetElem(cvset, idx) && (elem->flags & CV_SET_ELEM_IDX_MASK) == idx, "cvSetRemove[ByPtr] didn't release the element properly" ); - + CV_TS_SEQ_CHECK_CONDITION( elem->next_free == first_free && cvset->free_elems == elem && cvset->active_count == prev_count - 1, "The free node list has not been updated properly" ); } - + //max_active_count = MAX( max_active_count, cvset->active_count ); //mean_active_count += cvset->active_count; CV_TS_SEQ_CHECK_CONDITION( cvset->active_count == sset->max_count - sset->free_count && cvset->total >= cvset->active_count && (cvset->total == 0 || cvset->total >= prev_total), "The total number of cvset elements is not correct" ); - + // CvSet and simple set do not neccessary have the same "total" (active & free) number, // so pass "set->total" to skip that check test_seq_block_consistence( struct_idx, (CvSeq*)cvset, cvset->total ); update_progressbar(); } - + return 0; } @@ -1373,19 +1373,19 @@ void Core_SetTest::run( int ) { RNG& rng = ts->get_rng(); double t; - + clear(); test_progress = -1; - + simple_struct.resize(struct_count, 0); cxcore_struct.resize(struct_count, 0); - + for( gen = 0; gen < generations; gen++ ) { struct_idx = iter = -1; t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size) + min_log_storage_block_size; storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ); - + for( int i = 0; i < struct_count; i++ ) { t = cvtest::randReal(rng)*(max_log_elem_size - min_log_elem_size) + min_log_elem_size; @@ -1395,15 +1395,15 @@ void Core_SetTest::run( int ) elem_size = MAX( elem_size, (int)sizeof(CvSetElem) ); elem_size = MIN( elem_size, (int)(storage->block_size - sizeof(void*) - sizeof(CvMemBlock) - sizeof(CvSeqBlock)) ); pure_elem_size = MIN( pure_elem_size, elem_size-(int)sizeof(CvSetElem) ); - + cvTsReleaseSimpleSet( (CvTsSimpleSet**)&simple_struct[i] ); simple_struct[i] = cvTsCreateSimpleSet( max_struct_size, pure_elem_size ); cxcore_struct[i] = cvCreateSet( 0, sizeof(CvSet), elem_size, storage ); } - + if( test_set_ops( iterations*100 ) < 0 ) return; - + storage.release(); } } @@ -1421,7 +1421,7 @@ public: Core_GraphTest(); void clear(); void run( int ); - + protected: //int test_seq_block_consistence( int struct_idx ); int test_graph_ops( int iters ); @@ -1451,17 +1451,17 @@ int Core_GraphTest::test_graph_ops( int iters ) CvGraphEdge* edge = 0, *edge2 = 0; RNG& rng = ts->get_rng(); //int max_active_count = 0, mean_active_count = 0; - + for( i = 0; i < struct_count; i++ ) { CvGraph* graph = (CvGraph*)cxcore_struct[i]; max_elem_size = MAX( max_elem_size, graph->elem_size ); max_elem_size = MAX( max_elem_size, graph->edges->elem_size ); } - + vector elem_buf(max_elem_size); Mat elem_mat; - + for( iter = 0; iter < iters; iter++ ) { struct_idx = cvtest::randInt(rng) % struct_count; @@ -1479,19 +1479,19 @@ int Core_GraphTest::test_graph_ops( int iters ) int op = cvtest::randInt(rng) % max_op; int pass_data = 0, vtx_degree0 = 0, vtx_degree = 0; CvSetElem *first_free, *next_free; - + if( cvtest::randInt(rng) % 200 == 0 ) // clear graph { int prev_vtx_count = graph->total, prev_edge_count = graph->edges->total; - + cvClearGraph( graph ); cvTsClearSimpleGraph( sgraph ); - + CV_TS_SEQ_CHECK_CONDITION( graph->active_count == 0 && graph->total == 0 && graph->first == 0 && graph->free_elems == 0 && (graph->free_blocks != 0 || prev_vtx_count == 0), "The graph is not empty after clearing" ); - + CV_TS_SEQ_CHECK_CONDITION( edges->active_count == 0 && edges->total == 0 && edges->first == 0 && edges->free_elems == 0 && (edges->free_blocks != 0 || prev_edge_count == 0), @@ -1501,33 +1501,33 @@ int Core_GraphTest::test_graph_ops( int iters ) { if( sgraph->vtx->free_count == 0 ) continue; - + first_free = graph->free_elems; next_free = first_free ? first_free->next_free : 0; - + if( pure_vtx_size ) { elem_mat = Mat(1, graph->elem_size, CV_8U, &elem_buf[0]); cvtest::randUni( rng, elem_mat, cvScalarAll(0), cvScalarAll(255) ); } - + vtx = (CvGraphVtx*)&elem_buf[0]; idx0 = cvTsSimpleGraphAddVertex( sgraph, vtx + 1 ); - + pass_data = cvtest::randInt(rng) % 2; idx = cvGraphAddVtx( graph, pass_data ? vtx : 0, &vtx2 ); - + if( !pass_data && pure_vtx_size > 0 ) memcpy( vtx2 + 1, vtx + 1, pure_vtx_size ); - + vtx3 = cvGetGraphVtx( graph, idx ); - + CV_TS_SEQ_CHECK_CONDITION( (CV_IS_SET_ELEM(vtx3) && vtx3->flags == idx && vtx3->first == 0) || (idx == idx0 && vtx3 == vtx2 && (!pass_data || pure_vtx_size == 0 || memcmp(vtx3 + 1, vtx + 1, pure_vtx_size) == 0)), "The added element is not correct" ); - + CV_TS_SEQ_CHECK_CONDITION( (!first_free || first_free == (CvSetElem*)vtx3) && (!next_free || graph->free_elems == next_free) && graph->active_count == prev_vtx_count + 1, @@ -1538,19 +1538,19 @@ int Core_GraphTest::test_graph_ops( int iters ) idx = cvtest::randInt(rng) % sgraph->vtx->max_count; if( sgraph->vtx->free_count == sgraph->vtx->max_count || idx >= sgraph->vtx->count ) continue; - + vtx_data = cvTsSimpleGraphFindVertex(sgraph, idx); if( vtx_data == 0 ) continue; - + vtx_degree0 = cvTsSimpleGraphVertexDegree( sgraph, idx ); first_free = graph->free_elems; - + vtx = cvGetGraphVtx( graph, idx ); CV_TS_SEQ_CHECK_CONDITION( CV_IS_SET_ELEM(vtx) && vtx->flags == idx && (pure_vtx_size == 0 || memcmp( vtx + 1, vtx_data, pure_vtx_size) == 0), "cvGetGraphVtx returned wrong element" ); - + if( cvtest::randInt(rng) % 2 ) { vtx_degree = cvGraphVtxDegreeByPtr( graph, vtx ); @@ -1561,20 +1561,20 @@ int Core_GraphTest::test_graph_ops( int iters ) vtx_degree = cvGraphVtxDegree( graph, idx ); cvGraphRemoveVtx( graph, idx ); } - + cvTsSimpleGraphRemoveVertex( sgraph, idx ); - + CV_TS_SEQ_CHECK_CONDITION( vtx_degree == vtx_degree0, "Number of incident edges is different in two graph representations" ); - + CV_TS_SEQ_CHECK_CONDITION( !CV_IS_SET_ELEM(vtx) && !cvGetGraphVtx(graph, idx) && (vtx->flags & CV_SET_ELEM_IDX_MASK) == idx, "cvGraphRemoveVtx[ByPtr] didn't release the vertex properly" ); - + CV_TS_SEQ_CHECK_CONDITION( graph->edges->active_count == prev_edge_count - vtx_degree, "cvGraphRemoveVtx[ByPtr] didn't remove all the incident edges " "(or removed some extra)" ); - + CV_TS_SEQ_CHECK_CONDITION( ((CvSetElem*)vtx)->next_free == first_free && graph->free_elems == (CvSetElem*)vtx && graph->active_count == prev_vtx_count - 1, @@ -1584,10 +1584,10 @@ int Core_GraphTest::test_graph_ops( int iters ) { int v_idx[2] = {0,0}, res = 0; int v_prev_degree[2] = {0,0}, v_degree[2] = {0,0}; - + if( sgraph->vtx->free_count >= sgraph->vtx->max_count-1 ) continue; - + for( i = 0, k = 0; i < 10; i++ ) { int j = cvtest::randInt(rng) % sgraph->vtx->count; @@ -1605,34 +1605,34 @@ int Core_GraphTest::test_graph_ops( int iters ) } } } - + if( k < 2 ) continue; - + first_free = graph->edges->free_elems; next_free = first_free ? first_free->next_free : 0; - + edge = cvFindGraphEdge( graph, v_idx[0], v_idx[1] ); CV_TS_SEQ_CHECK_CONDITION( edge == 0, "Extra edge appeared in the graph" ); - + if( pure_edge_size > 0 ) { elem_mat = Mat(1, graph->edges->elem_size, CV_8U, &elem_buf[0]); cvtest::randUni( rng, elem_mat, cvScalarAll(0), cvScalarAll(255) ); } edge = (CvGraphEdge*)&elem_buf[0]; - + // assign some default weight that is easy to check for // consistensy, 'cause an edge weight is not stored // in the simple graph edge->weight = (float)(v_idx[0] + v_idx[1]); pass_data = cvtest::randInt(rng) % 2; - + vtx = cvGetGraphVtx( graph, v_idx[0] ); vtx2 = cvGetGraphVtx( graph, v_idx[1] ); CV_TS_SEQ_CHECK_CONDITION( vtx != 0 && vtx2 != 0 && vtx->flags == v_idx[0] && vtx2->flags == v_idx[1], "Some of the vertices are missing" ); - + if( cvtest::randInt(rng) % 2 ) { v_prev_degree[0] = cvGraphVtxDegreeByPtr( graph, vtx ); @@ -1649,27 +1649,27 @@ int Core_GraphTest::test_graph_ops( int iters ) v_degree[0] = cvGraphVtxDegree( graph, v_idx[0] ); v_degree[1] = cvGraphVtxDegree( graph, v_idx[1] ); } - + //edge3 = (CvGraphEdge*)cvGetSetElem( graph->edges, idx ); CV_TS_SEQ_CHECK_CONDITION( res == 1 && edge2 != 0 && CV_IS_SET_ELEM(edge2) && ((edge2->vtx[0] == vtx && edge2->vtx[1] == vtx2) || (!CV_IS_GRAPH_ORIENTED(graph) && edge2->vtx[0] == vtx2 && edge2->vtx[1] == vtx)) && (!pass_data || pure_edge_size == 0 || memcmp( edge2 + 1, edge + 1, pure_edge_size ) == 0), "The edge has been added incorrectly" ); - + if( !pass_data ) { if( pure_edge_size > 0 ) memcpy( edge2 + 1, edge + 1, pure_edge_size ); edge2->weight = edge->weight; } - + CV_TS_SEQ_CHECK_CONDITION( v_degree[0] == v_prev_degree[0] + 1 && v_degree[1] == v_prev_degree[1] + 1, "The vertices lists have not been updated properly" ); - + cvTsSimpleGraphAddEdge( sgraph, v_idx[0], v_idx[1], edge + 1 ); - + CV_TS_SEQ_CHECK_CONDITION( (!first_free || first_free == (CvSetElem*)edge2) && (!next_free || graph->edges->free_elems == next_free) && graph->edges->active_count == prev_edge_count + 1, @@ -1679,10 +1679,10 @@ int Core_GraphTest::test_graph_ops( int iters ) { int v_idx[2] = {0,0}, by_ptr; int v_prev_degree[2] = {0,0}, v_degree[2] = {0,0}; - + if( sgraph->vtx->free_count >= sgraph->vtx->max_count-1 ) continue; - + edge_data = 0; for( i = 0, k = 0; i < 10; i++ ) { @@ -1704,18 +1704,18 @@ int Core_GraphTest::test_graph_ops( int iters ) } } } - + if( k < 2 ) continue; - + by_ptr = cvtest::randInt(rng) % 2; first_free = graph->edges->free_elems; - + vtx = cvGetGraphVtx( graph, v_idx[0] ); vtx2 = cvGetGraphVtx( graph, v_idx[1] ); CV_TS_SEQ_CHECK_CONDITION( vtx != 0 && vtx2 != 0 && vtx->flags == v_idx[0] && vtx2->flags == v_idx[1], "Some of the vertices are missing" ); - + if( by_ptr ) { edge = cvFindGraphEdgeByPtr( graph, vtx, vtx2 ); @@ -1728,15 +1728,15 @@ int Core_GraphTest::test_graph_ops( int iters ) v_prev_degree[0] = cvGraphVtxDegree( graph, v_idx[0] ); v_prev_degree[1] = cvGraphVtxDegree( graph, v_idx[1] ); } - + idx = edge->flags; - + CV_TS_SEQ_CHECK_CONDITION( edge != 0 && edge->weight == v_idx[0] + v_idx[1] && ((edge->vtx[0] == vtx && edge->vtx[1] == vtx2) || (!CV_IS_GRAPH_ORIENTED(graph) && edge->vtx[1] == vtx && edge->vtx[0] == vtx2)) && (pure_edge_size == 0 || memcmp(edge + 1, edge_data, pure_edge_size) == 0), "An edge is missing or incorrect" ); - + if( by_ptr ) { cvGraphRemoveEdgeByPtr( graph, vtx, vtx2 ); @@ -1751,41 +1751,41 @@ int Core_GraphTest::test_graph_ops( int iters ) v_degree[0] = cvGraphVtxDegree( graph, v_idx[0] ); v_degree[1] = cvGraphVtxDegree( graph, v_idx[1] ); } - + CV_TS_SEQ_CHECK_CONDITION( !edge2 && !CV_IS_SET_ELEM(edge), "The edge has not been removed from the edge set" ); - + CV_TS_SEQ_CHECK_CONDITION( v_degree[0] == v_prev_degree[0] - 1 && v_degree[1] == v_prev_degree[1] - 1, "The vertices lists have not been updated properly" ); - + cvTsSimpleGraphRemoveEdge( sgraph, v_idx[0], v_idx[1] ); - + CV_TS_SEQ_CHECK_CONDITION( graph->edges->free_elems == (CvSetElem*)edge && graph->edges->free_elems->next_free == first_free && graph->edges->active_count == prev_edge_count - 1, "The free edge list has not been modified properly" ); } - + //max_active_count = MAX( max_active_count, graph->active_count ); //mean_active_count += graph->active_count; - + CV_TS_SEQ_CHECK_CONDITION( graph->active_count == sgraph->vtx->max_count - sgraph->vtx->free_count && graph->total >= graph->active_count && (graph->total == 0 || graph->total >= prev_vtx_total), "The total number of graph vertices is not correct" ); - + CV_TS_SEQ_CHECK_CONDITION( graph->edges->total >= graph->edges->active_count && (graph->edges->total == 0 || graph->edges->total >= prev_edge_total), "The total number of graph vertices is not correct" ); - + // CvGraph and simple graph do not neccessary have the same "total" (active & free) number, // so pass "graph->total" (or "graph->edges->total") to skip that check test_seq_block_consistence( struct_idx, (CvSeq*)graph, graph->total ); test_seq_block_consistence( struct_idx, (CvSeq*)graph->edges, graph->edges->total ); update_progressbar(); } - + return 0; } @@ -1797,22 +1797,22 @@ void Core_GraphTest::run( int ) RNG& rng = ts->get_rng(); int i, k; double t; - + clear(); test_progress = -1; - + simple_struct.resize(struct_count, 0); cxcore_struct.resize(struct_count, 0); - + for( gen = 0; gen < generations; gen++ ) { struct_idx = iter = -1; t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size) + min_log_storage_block_size; int block_size = cvRound( exp(t * CV_LOG2) ); block_size = MAX(block_size, (int)(sizeof(CvGraph) + sizeof(CvMemBlock) + sizeof(CvSeqBlock))); - + storage = cvCreateMemStorage(block_size); - + for( i = 0; i < struct_count; i++ ) { int pure_elem_size[2], elem_size[2]; @@ -1830,7 +1830,7 @@ void Core_GraphTest::run( int ) pure_elem_size[k] = pe; elem_size[k] = e; } - + cvTsReleaseSimpleGraph( (CvTsSimpleGraph**)&simple_struct[i] ); simple_struct[i] = cvTsCreateSimpleGraph( max_struct_size/4, pure_elem_size[0], pure_elem_size[1], is_oriented ); @@ -1838,10 +1838,10 @@ void Core_GraphTest::run( int ) sizeof(CvGraph), elem_size[0], elem_size[1], storage ); } - + if( test_graph_ops( iterations*10 ) < 0 ) return; - + storage.release(); } } @@ -1858,7 +1858,7 @@ class Core_GraphScanTest : public Core_DynStructBaseTest public: Core_GraphScanTest(); void run( int ); - + protected: //int test_seq_block_consistence( int struct_idx ); int create_random_graph( int ); @@ -1879,29 +1879,29 @@ int Core_GraphScanTest::create_random_graph( int _struct_idx ) int i, vtx_count = cvtest::randInt(rng) % max_struct_size; int edge_count = cvtest::randInt(rng) % MAX(vtx_count*20, 1); CvGraph* graph; - + struct_idx = _struct_idx; cxcore_struct[_struct_idx] = graph = cvCreateGraph(is_oriented ? CV_ORIENTED_GRAPH : CV_GRAPH, sizeof(CvGraph), sizeof(CvGraphVtx), sizeof(CvGraphEdge), storage ); - + for( i = 0; i < vtx_count; i++ ) cvGraphAddVtx( graph ); - + assert( graph->active_count == vtx_count ); - + for( i = 0; i < edge_count; i++ ) { int j = cvtest::randInt(rng) % vtx_count; int k = cvtest::randInt(rng) % vtx_count; - + if( j != k ) cvGraphAddEdge( graph, j, k ); } - + assert( graph->active_count == vtx_count && graph->edges->active_count <= edge_count ); - + return 0; } @@ -1915,12 +1915,12 @@ void Core_GraphScanTest::run( int ) vector vtx_mask, edge_mask; double t; int i; - + clear(); test_progress = -1; - + cxcore_struct.resize(struct_count, 0); - + for( gen = 0; gen < generations; gen++ ) { struct_idx = iter = -1; @@ -1930,49 +1930,49 @@ void Core_GraphScanTest::run( int ) storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraphEdge) + sizeof(CvMemBlock) + sizeof(CvSeqBlock))); storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraphVtx) + sizeof(CvMemBlock) + sizeof(CvSeqBlock))); storage = cvCreateMemStorage(storage_blocksize); - + if( gen == 0 ) { // special regression test for one sample graph. // !!! ATTENTION !!! The test relies on the particular order of the inserted edges // (LIFO: the edge inserted last goes first in the list of incident edges). // if it is changed, the test will have to be modified. - + int vtx_count = -1, edge_count = 0, edges[][3] = { {0,4,'f'}, {0,1,'t'}, {1,4,'t'}, {1,2,'t'}, {2,3,'t'}, {4,3,'c'}, {3,1,'b'}, {5,7,'t'}, {7,5,'b'}, {5,6,'t'}, {6,0,'c'}, {7,6,'c'}, {6,4,'c'}, {-1,-1,0} }; - + CvGraph* graph = cvCreateGraph( CV_ORIENTED_GRAPH, sizeof(CvGraph), sizeof(CvGraphVtx), sizeof(CvGraphEdge), storage ); - + for( i = 0; edges[i][0] >= 0; i++ ) { vtx_count = MAX( vtx_count, edges[i][0] ); vtx_count = MAX( vtx_count, edges[i][1] ); } vtx_count++; - + for( i = 0; i < vtx_count; i++ ) cvGraphAddVtx( graph ); - + for( i = 0; edges[i][0] >= 0; i++ ) { CvGraphEdge* edge; cvGraphAddEdge( graph, edges[i][0], edges[i][1], 0, &edge ); edge->weight = (float)edges[i][2]; } - + edge_count = i; scanner = cvCreateGraphScanner( graph, 0, CV_GRAPH_ALL_ITEMS ); - + for(;;) { int code, a = -1, b = -1; const char* event = ""; code = cvNextGraphItem( scanner ); - + switch( code ) { case CV_GRAPH_VERTEX: @@ -2023,16 +2023,16 @@ void Core_GraphScanTest::run( int ) event = "End of procedure"; break; default: -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( push ) - #pragma warning( disable : 4127 ) + #pragma warning( disable : 4127 ) #endif CV_TS_SEQ_CHECK_CONDITION( 0, "Invalid code appeared during graph scan" ); -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( pop ) #endif } - + ts->printf( cvtest::TS::LOG, "%s", event ); if( a >= 0 ) { @@ -2041,48 +2041,48 @@ void Core_GraphScanTest::run( int ) else ts->printf( cvtest::TS::LOG, ": %d", a ); } - + ts->printf( cvtest::TS::LOG, "\n" ); - + if( code < 0 ) break; } - + CV_TS_SEQ_CHECK_CONDITION( vtx_count == 0 && edge_count == 0, "Not every vertex/edge has been visited" ); update_progressbar(); } - + // for a random graph the test just checks that every graph vertex and // every edge is vitisted during the scan for( iter = 0; iter < iterations; iter++ ) { create_random_graph(0); CvGraph* graph = (CvGraph*)cxcore_struct[0]; - + // iterate twice to check that scanner doesn't damage the graph for( i = 0; i < 2; i++ ) { CvGraphVtx* start_vtx = cvtest::randInt(rng) % 2 || graph->active_count == 0 ? 0 : cvGetGraphVtx( graph, cvtest::randInt(rng) % graph->active_count ); - + scanner = cvCreateGraphScanner( graph, start_vtx, CV_GRAPH_ALL_ITEMS ); - + vtx_mask.resize(0); vtx_mask.resize(graph->active_count, 0); edge_mask.resize(0); edge_mask.resize(graph->edges->active_count, 0); - + for(;;) { int code = cvNextGraphItem( scanner ); - + if( code == CV_GRAPH_OVER ) break; else if( code & CV_GRAPH_ANY_EDGE ) { int edge_idx = scanner->edge->flags & CV_SET_ELEM_IDX_MASK; - + CV_TS_SEQ_CHECK_CONDITION( edge_idx < graph->edges->active_count && edge_mask[edge_idx] == 0, "The edge is not found or visited for the second time" ); @@ -2091,16 +2091,16 @@ void Core_GraphScanTest::run( int ) else if( code & CV_GRAPH_VERTEX ) { int vtx_idx = scanner->vtx->flags & CV_SET_ELEM_IDX_MASK; - + CV_TS_SEQ_CHECK_CONDITION( vtx_idx < graph->active_count && vtx_mask[vtx_idx] == 0, "The vtx is not found or visited for the second time" ); vtx_mask[vtx_idx] = 1; } } - + cvReleaseGraphScanner( &scanner ); - + CV_TS_SEQ_CHECK_CONDITION( cvtest::norm(Mat(vtx_mask),CV_L1) == graph->active_count && cvtest::norm(Mat(edge_mask),CV_L1) == graph->edges->active_count, "Some vertices or edges have not been visited" ); @@ -2108,14 +2108,14 @@ void Core_GraphScanTest::run( int ) } cvClearMemStorage( storage ); } - + storage.release(); } } catch(int) { } - + cvReleaseGraphScanner( &scanner ); } diff --git a/modules/features2d/perf/perf_precomp.hpp b/modules/features2d/perf/perf_precomp.hpp index c986237..eaf9d77 100644 --- a/modules/features2d/perf/perf_precomp.hpp +++ b/modules/features2d/perf/perf_precomp.hpp @@ -5,7 +5,7 @@ #include "opencv2/highgui/highgui.hpp" #include "opencv2/features2d/features2d.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/features2d/src/brief.cpp b/modules/features2d/src/brief.cpp index 7247b92..98759be 100644 --- a/modules/features2d/src/brief.cpp +++ b/modules/features2d/src/brief.cpp @@ -61,7 +61,7 @@ inline int smoothedSum(const Mat& sum, const KeyPoint& pt, int y, int x) + sum.at(img_y - HALF_KERNEL, img_x - HALF_KERNEL); } -void pixelTests16(const Mat& sum, const std::vector& keypoints, Mat& descriptors) +static void pixelTests16(const Mat& sum, const std::vector& keypoints, Mat& descriptors) { for (int i = 0; i < (int)keypoints.size(); ++i) { @@ -71,7 +71,7 @@ void pixelTests16(const Mat& sum, const std::vector& keypoints, Mat& d } } -void pixelTests32(const Mat& sum, const std::vector& keypoints, Mat& descriptors) +static void pixelTests32(const Mat& sum, const std::vector& keypoints, Mat& descriptors) { for (int i = 0; i < (int)keypoints.size(); ++i) { @@ -82,7 +82,7 @@ void pixelTests32(const Mat& sum, const std::vector& keypoints, Mat& d } } -void pixelTests64(const Mat& sum, const std::vector& keypoints, Mat& descriptors) +static void pixelTests64(const Mat& sum, const std::vector& keypoints, Mat& descriptors) { for (int i = 0; i < (int)keypoints.size(); ++i) { diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index 7d8d9fc..e90bf9d 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -56,7 +56,7 @@ DescriptorExtractor::~DescriptorExtractor() {} void DescriptorExtractor::compute( const Mat& image, vector& keypoints, Mat& descriptors ) const -{ +{ if( image.empty() || keypoints.empty() ) { descriptors.release(); @@ -102,7 +102,7 @@ Ptr DescriptorExtractor::create(const string& descriptorExt string type = descriptorExtractorType.substr(pos); return new OpponentColorDescriptorExtractor(DescriptorExtractor::create(type)); } - + return Algorithm::create("Feature2D." + descriptorExtractorType); } @@ -117,7 +117,7 @@ OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor( const Ptr& opponentChannels ) +static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, vector& opponentChannels ) { if( bgrImage.type() != CV_8UC3 ) CV_Error( CV_StsBadArg, "input image must be an BGR image of type CV_8UC3" ); @@ -227,7 +227,7 @@ void OpponentColorDescriptorExtractor::computeImpl( const Mat& bgrImage, vector< Mat mergedDescriptors( maxKeypointsCount, 3*descriptorSize, descriptorExtractor->descriptorType() ); int mergedCount = 0; // cp - current channel position - size_t cp[] = {0, 0, 0}; + size_t cp[] = {0, 0, 0}; while( cp[0] < channelKeypoints[0].size() && cp[1] < channelKeypoints[1].size() && cp[2] < channelKeypoints[2].size() ) diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index 8b23242..70e795a 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -45,7 +45,7 @@ using namespace std; namespace cv { - + /* * FeatureDetector */ @@ -95,19 +95,19 @@ Ptr FeatureDetector::create( const string& detectorType ) return new GridAdaptedFeatureDetector(FeatureDetector::create( detectorType.substr(strlen("Grid")))); } - + if( detectorType.find("Pyramid") == 0 ) { return new PyramidAdaptedFeatureDetector(FeatureDetector::create( detectorType.substr(strlen("Pyramid")))); } - + if( detectorType.find("Dynamic") == 0 ) { return new DynamicAdaptedFeatureDetector(AdjusterAdapter::create( detectorType.substr(strlen("Dynamic")))); } - + if( detectorType.compare( "HARRIS" ) == 0 ) { Ptr fd = FeatureDetector::create("GFTT"); @@ -149,13 +149,13 @@ void GFTTDetector::detectImpl( const Mat& image, vector& keypoints, co /* * DenseFeatureDetector */ -DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels, - float _featureScaleMul, int _initXyStep, - int _initImgBound, bool _varyXyStepWithScale, - bool _varyImgBoundWithScale ) : - initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels), - featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound), - varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale) +DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels, + float _featureScaleMul, int _initXyStep, + int _initImgBound, bool _varyXyStepWithScale, + bool _varyImgBoundWithScale ) : + initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels), + featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound), + varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale) {} @@ -203,7 +203,7 @@ struct ResponseComparator } }; -void keepStrongest( int N, vector& keypoints ) +static void keepStrongest( int N, vector& keypoints ) { if( (int)keypoints.size() > N ) { diff --git a/modules/features2d/src/features2d_init.cpp b/modules/features2d/src/features2d_init.cpp index 6f9e07c..508e034 100644 --- a/modules/features2d/src/features2d_init.cpp +++ b/modules/features2d/src/features2d_init.cpp @@ -42,8 +42,7 @@ #include "precomp.hpp" -namespace cv -{ +using namespace cv; /////////////////////// AlgorithmInfo for various detector & descriptors //////////////////////////// @@ -54,7 +53,7 @@ namespace cv CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF", obj.info()->addParam(obj, "bytes", obj.bytes_)); - + /////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST", @@ -69,7 +68,7 @@ CV_INIT_ALGORITHM(StarDetector, "Feature2D.STAR", obj.info()->addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected); obj.info()->addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized); obj.info()->addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize)); - + /////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(MSER, "Feature2D.MSER", @@ -81,8 +80,8 @@ CV_INIT_ALGORITHM(MSER, "Feature2D.MSER", obj.info()->addParam(obj, "maxEvolution", obj.maxEvolution); obj.info()->addParam(obj, "areaThreshold", obj.areaThreshold); obj.info()->addParam(obj, "minMargin", obj.minMargin); - obj.info()->addParam(obj, "edgeBlurSize", obj.edgeBlurSize)); - + obj.info()->addParam(obj, "edgeBlurSize", obj.edgeBlurSize)); + /////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(ORB, "Feature2D.ORB", @@ -96,7 +95,7 @@ CV_INIT_ALGORITHM(ORB, "Feature2D.ORB", obj.info()->addParam(obj, "scoreType", obj.scoreType)); /////////////////////////////////////////////////////////////////////////////////////////////////////////// - + CV_INIT_ALGORITHM(GFTTDetector, "Feature2D.GFTT", obj.info()->addParam(obj, "nfeatures", obj.nfeatures); obj.info()->addParam(obj, "qualityLevel", obj.qualityLevel); @@ -105,7 +104,7 @@ CV_INIT_ALGORITHM(GFTTDetector, "Feature2D.GFTT", obj.info()->addParam(obj, "k", obj.k)); /////////////////////////////////////////////////////////////////////////////////////////////////////////// - + class CV_EXPORTS HarrisDetector : public GFTTDetector { public: @@ -113,7 +112,7 @@ public: int blockSize=3, bool useHarrisDetector=true, double k=0.04 ) : GFTTDetector( maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, k ) {} AlgorithmInfo* info() const; -}; +}; CV_INIT_ALGORITHM(HarrisDetector, "Feature2D.HARRIS", obj.info()->addParam(obj, "nfeatures", obj.nfeatures); @@ -122,7 +121,7 @@ CV_INIT_ALGORITHM(HarrisDetector, "Feature2D.HARRIS", obj.info()->addParam(obj, "useHarrisDetector", obj.useHarrisDetector); obj.info()->addParam(obj, "k", obj.k)); -//////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(DenseFeatureDetector, "Feature2D.Dense", obj.info()->addParam(obj, "initFeatureScale", obj.initFeatureScale); @@ -134,22 +133,23 @@ CV_INIT_ALGORITHM(DenseFeatureDetector, "Feature2D.Dense", obj.info()->addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale)); CV_INIT_ALGORITHM(GridAdaptedFeatureDetector, "Feature2D.Grid", - obj.info()->addParam(obj, "detector", (Ptr&)obj.detector); + //obj.info()->addParam(obj, "detector", (Ptr&)obj.detector); obj.info()->addParam(obj, "maxTotalKeypoints", obj.maxTotalKeypoints); obj.info()->addParam(obj, "gridRows", obj.gridRows); obj.info()->addParam(obj, "gridCols", obj.gridCols)); -bool initModule_features2d(void) +bool cv::initModule_features2d(void) { - Ptr brief = createBriefDescriptorExtractor(), orb = createORB(), - star = createStarDetector(), fastd = createFastFeatureDetector(), mser = createMSER(), - dense = createDenseFeatureDetector(), gftt = createGFTTDetector(), - harris = createHarrisDetector(), grid = createGridAdaptedFeatureDetector(); - - return brief->info() != 0 && orb->info() != 0 && star->info() != 0 && - fastd->info() != 0 && mser->info() != 0 && dense->info() != 0 && - gftt->info() != 0 && harris->info() != 0 && grid->info() != 0; -} - + bool all = true; + all &= !BriefDescriptorExtractor_info_auto.name().empty(); + all &= !FastFeatureDetector_info_auto.name().empty(); + all &= !StarDetector_info_auto.name().empty(); + all &= !MSER_info_auto.name().empty(); + all &= !ORB_info_auto.name().empty(); + all &= !GFTTDetector_info_auto.name().empty(); + all &= !HarrisDetector_info_auto.name().empty(); + all &= !DenseFeatureDetector_info_auto.name().empty(); + all &= !GridAdaptedFeatureDetector_info_auto.name().empty(); + + return all; } - diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 61a6ced..74ab4b8 100755 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -174,7 +174,7 @@ int DescriptorMatcher::DescriptorCollection::size() const /* * DescriptorMatcher */ -void convertMatches( const vector >& knnMatches, vector& matches ) +static void convertMatches( const vector >& knnMatches, vector& matches ) { matches.clear(); matches.reserve( knnMatches.size() ); diff --git a/modules/features2d/src/precomp.hpp b/modules/features2d/src/precomp.hpp index 1678c69..4bf511c 100644 --- a/modules/features2d/src/precomp.hpp +++ b/modules/features2d/src/precomp.hpp @@ -43,7 +43,7 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4512 4710 4711 4514 4996 ) #endif diff --git a/modules/features2d/test/test_features2d.cpp b/modules/features2d/test/test_features2d.cpp index 272acca..958d891 100644 --- a/modules/features2d/test/test_features2d.cpp +++ b/modules/features2d/test/test_features2d.cpp @@ -493,23 +493,6 @@ private: CV_DescriptorExtractorTest& operator=(const CV_DescriptorExtractorTest&) { return *this; } }; -/*template -class CV_CalonderDescriptorExtractorTest : public CV_DescriptorExtractorTest -{ -public: - CV_CalonderDescriptorExtractorTest( const char* testName, float _normDif, float _prevTime ) : - CV_DescriptorExtractorTest( testName, _normDif, Ptr(), _prevTime ) - {} - -protected: - virtual void createDescriptorExtractor() - { - CV_DescriptorExtractorTest::dextractor = - new CalonderDescriptorExtractor( string(CV_DescriptorExtractorTest::ts->get_data_path()) + - FEATURES2D_DIR + "/calonder_classifier.rtc"); - } -};*/ - /****************************************************************************************\ * Algorithmic tests for descriptor matchers * \****************************************************************************************/ @@ -1059,24 +1042,6 @@ TEST( Features2d_DescriptorExtractor_BRIEF, regression ) test.safe_run(); } -#if CV_SSE2 -TEST( Features2d_DescriptorExtractor_Calonder_uchar, regression ) -{ - CV_CalonderDescriptorExtractorTest > test( "descriptor-calonder-uchar", - std::numeric_limits::epsilon() + 1, - 0.0132175f ); - test.safe_run(); -} - -TEST( Features2d_DescriptorExtractor_Calonder_float, regression ) -{ - CV_CalonderDescriptorExtractorTest > test( "descriptor-calonder-float", - std::numeric_limits::epsilon(), - 0.0221308f ); - test.safe_run(); -} -#endif // CV_SSE2 - /* * Matchers */ diff --git a/modules/flann/include/opencv2/flann/any.h b/modules/flann/include/opencv2/flann/any.h index 34a7120..e1c78b6 100644 --- a/modules/flann/include/opencv2/flann/any.h +++ b/modules/flann/include/opencv2/flann/any.h @@ -46,6 +46,7 @@ struct base_any_policy virtual ::size_t get_size() = 0; virtual const std::type_info& type() = 0; virtual void print(std::ostream& out, void* const* src) = 0; + virtual ~base_any_policy() {} }; template diff --git a/modules/flann/include/opencv2/flann/dynamic_bitset.h b/modules/flann/include/opencv2/flann/dynamic_bitset.h index 064ec39..b94a089 100644 --- a/modules/flann/include/opencv2/flann/dynamic_bitset.h +++ b/modules/flann/include/opencv2/flann/dynamic_bitset.h @@ -35,6 +35,9 @@ #ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_ #define OPENCV_FLANN_DYNAMIC_BITSET_H_ +#ifndef FLANN_USE_BOOST +# define FLANN_USE_BOOST 0 +#endif //#define FLANN_USE_BOOST 1 #if FLANN_USE_BOOST #include diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h index 4948d05..cb9e05f 100644 --- a/modules/flann/include/opencv2/flann/lsh_table.h +++ b/modules/flann/include/opencv2/flann/lsh_table.h @@ -40,6 +40,11 @@ #include #include // TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +# define USE_UNORDERED_MAP 1 +#else +# define USE_UNORDERED_MAP 0 +#endif #if USE_UNORDERED_MAP #include #else diff --git a/modules/gpu/perf/perf_precomp.hpp b/modules/gpu/perf/perf_precomp.hpp index 21532ab..472f750 100644 --- a/modules/gpu/perf/perf_precomp.hpp +++ b/modules/gpu/perf/perf_precomp.hpp @@ -16,7 +16,7 @@ #include "perf_utility.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/gpu/perf_cpu/perf_cpu_precomp.hpp b/modules/gpu/perf_cpu/perf_cpu_precomp.hpp index 6c3fbd1..f57b08c 100644 --- a/modules/gpu/perf_cpu/perf_cpu_precomp.hpp +++ b/modules/gpu/perf_cpu/perf_cpu_precomp.hpp @@ -20,7 +20,7 @@ #include "perf_utility.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/gpu/src/precomp.hpp b/modules/gpu/src/precomp.hpp index 287d6bc..1cf467c 100644 --- a/modules/gpu/src/precomp.hpp +++ b/modules/gpu/src/precomp.hpp @@ -43,7 +43,7 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4710 4711 4514 4996 ) #endif diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index ecd0276..ecce478 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -81,6 +81,10 @@ if(HAVE_QT) list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY}) list(APPEND highgui_srcs src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES} ) + + if(CMAKE_COMPILER_IS_GNUCXX) + set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS "-Wno-missing-declarations") + endif() elseif(WIN32) list(APPEND highgui_srcs src/window_w32.cpp) elseif(HAVE_GTK) @@ -131,6 +135,10 @@ if(HAVE_OPENNI) list(APPEND highgui_srcs src/cap_openni.cpp) ocv_include_directories(${OPENNI_INCLUDE_DIR}) list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY}) + + if(CMAKE_COMPILER_IS_GNUCXX) + set_source_files_properties(src/cap_openni.cpp PROPERTIES COMPILE_FLAGS "-Wno-unknown-pragmas -Wno-uninitialized -Wno-reorder -Wno-strict-aliasing") + endif() endif(HAVE_OPENNI) if(HAVE_opencv_androidcamera) diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index 7937df4..ddd3003 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -79,7 +79,7 @@ CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms C CVAPI(void) cvSaveWindowParameters(const char* name); CVAPI(void) cvLoadWindowParameters(const char* name); CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); -CVAPI(void) cvStopLoop(); +CVAPI(void) cvStopLoop( void ); typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata); enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1, CV_RADIOBOX = 2}; @@ -90,7 +90,7 @@ CVAPI(int) cvCreateButton( const char* button_name CV_DEFAULT(NULL),CvButtonCall /* this function is used to set some external parameters in case of X Window */ CVAPI(int) cvInitSystem( int argc, char** argv ); -CVAPI(int) cvStartWindowThread(); +CVAPI(int) cvStartWindowThread( void ); // --------- YV --------- enum @@ -100,16 +100,16 @@ enum CV_WND_PROP_AUTOSIZE = 1, //to change/get window's autosize property CV_WND_PROP_ASPECTRATIO= 2, //to change/get window's aspectratio property CV_WND_PROP_OPENGL = 3, //to change/get window's opengl support - + //These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty CV_WINDOW_NORMAL = 0x00000000, //the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size CV_WINDOW_AUTOSIZE = 0x00000001, //the user cannot resize the window, the size is constrainted by the image displayed CV_WINDOW_OPENGL = 0x00001000, //window with opengl support - + //Those flags are only for Qt CV_GUI_EXPANDED = 0x00000000, //status bar and tool bar CV_GUI_NORMAL = 0x00000010, //old fashious way - + //These 3 flags are used by cvNamedWindow and cvSet/GetWindowProperty CV_WINDOW_FULLSCREEN = 1,//change the window to fullscreen CV_WINDOW_FREERATIO = 0x00000100,//the image expends as much as it can (no ratio constraint) @@ -303,10 +303,10 @@ enum CV_CAP_OPENNI_ASUS =910, // OpenNI (for Asus Xtion) CV_CAP_ANDROID =1000, // Android - + CV_CAP_XIAPI =1100, // XIMEA Camera API - - CV_CAP_AVFOUNDATION = 1200 // AVFoundation framework for iOS (OS X Lion will have the same API) + + CV_CAP_AVFOUNDATION = 1200 // AVFoundation framework for iOS (OS X Lion will have the same API) }; /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */ @@ -367,15 +367,15 @@ enum CV_CAP_PROP_TRIGGER_DELAY =25, CV_CAP_PROP_WHITE_BALANCE_RED_V =26, CV_CAP_PROP_ZOOM =27, - CV_CAP_PROP_FOCUS =28, - CV_CAP_PROP_GUID =29, - CV_CAP_PROP_ISO_SPEED =30, + CV_CAP_PROP_FOCUS =28, + CV_CAP_PROP_GUID =29, + CV_CAP_PROP_ISO_SPEED =30, CV_CAP_PROP_MAX_DC1394 =31, - CV_CAP_PROP_BACKLIGHT =32, - CV_CAP_PROP_PAN =33, - CV_CAP_PROP_TILT =34, - CV_CAP_PROP_ROLL =35, - CV_CAP_PROP_IRIS =36, + CV_CAP_PROP_BACKLIGHT =32, + CV_CAP_PROP_PAN =33, + CV_CAP_PROP_TILT =34, + CV_CAP_PROP_ROLL =35, + CV_CAP_PROP_IRIS =36, CV_CAP_PROP_SETTINGS =37, CV_CAP_PROP_AUTOGRAB =1024, // property for highgui class CvCapture_Android only @@ -409,24 +409,24 @@ enum CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH, CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_REGISTRATION, CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, - + // Properties of cameras available through GStreamer interface CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1 CV_CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast - + // Properties of cameras available through XIMEA SDK interface - CV_CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping. + CV_CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping. CV_CAP_PROP_XI_DATA_FORMAT = 401, // Output data format. CV_CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels). CV_CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels). CV_CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger. CV_CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE. - CV_CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input + CV_CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input CV_CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode CV_CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level - CV_CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output + CV_CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output CV_CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode - CV_CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED + CV_CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED CV_CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality CV_CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition) CV_CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance @@ -436,7 +436,7 @@ enum CV_CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure CV_CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %) CV_CAP_PROP_XI_TIMEOUT = 420, // Image capture timeout in milliseconds - + // Properties for Android cameras CV_CAP_PROP_ANDROID_FLASH_MODE = 8001, CV_CAP_PROP_ANDROID_FOCUS_MODE = 8002, @@ -532,7 +532,7 @@ CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id ); CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value ); // Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY -CVAPI(int) cvGetCaptureDomain( CvCapture* capture); +CVAPI(int) cvGetCaptureDomain( CvCapture* capture); /* "black box" video file writer structure */ typedef struct CvVideoWriter CvVideoWriter; diff --git a/modules/highgui/perf/perf_precomp.hpp b/modules/highgui/perf/perf_precomp.hpp index 2ffa9ee..17a338e 100644 --- a/modules/highgui/perf/perf_precomp.hpp +++ b/modules/highgui/perf/perf_precomp.hpp @@ -4,7 +4,7 @@ #include "opencv2/ts/ts.hpp" #include "opencv2/highgui/highgui.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index 8dc25f3..15ac626 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -41,7 +41,7 @@ #include "precomp.hpp" -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4711 ) #endif @@ -282,7 +282,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) return capture; break; #endif - + #ifdef HAVE_PVAPI case CV_CAP_PVAPI: capture = cvCreateCameraCapture_PvAPI (index); @@ -306,7 +306,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) return capture; break; #endif - + #ifdef HAVE_XIMEA case CV_CAP_XIAPI: capture = cvCreateCameraCapture_XIMEA (index); @@ -354,7 +354,7 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename) if (! result) result = cvCreateFileCapture_QT (filename); #endif - + #ifdef HAVE_AVFOUNDATION if (! result) result = cvCreateFileCapture_AVFoundation (filename); @@ -364,7 +364,7 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename) if (! result) result = cvCreateFileCapture_OpenNI (filename); #endif - + if (! result) result = cvCreateFileCapture_Images (filename); @@ -378,29 +378,29 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename) CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc, double fps, CvSize frameSize, int is_color ) { - //CV_FUNCNAME( "cvCreateVideoWriter" ); + //CV_FUNCNAME( "cvCreateVideoWriter" ); - CvVideoWriter *result = 0; + CvVideoWriter *result = 0; - if(!fourcc || !fps) - result = cvCreateVideoWriter_Images(filename); + if(!fourcc || !fps) + result = cvCreateVideoWriter_Images(filename); - if(!result) - result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color); + if(!result) + result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color); -/* #ifdef HAVE_XINE - if(!result) - result = cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color); - #endif +/* #ifdef HAVE_XINE + if(!result) + result = cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color); + #endif */ -#ifdef HAVE_AVFOUNDATION +#ifdef HAVE_AVFOUNDATION if (! result) result = cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color); #endif #ifdef HAVE_QUICKTIME - if(!result) - result = cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color); + if(!result) + result = cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color); #endif #ifdef HAVE_GSTREAMER @@ -408,10 +408,10 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc, result = cvCreateVideoWriter_GStreamer(filename, fourcc, fps, frameSize, is_color); #endif - if(!result) - result = cvCreateVideoWriter_Images(filename); + if(!result) + result = cvCreateVideoWriter_Images(filename); - return result; + return result; } CV_IMPL int cvWriteFrame( CvVideoWriter* writer, const IplImage* image ) @@ -434,12 +434,12 @@ namespace cv VideoCapture::VideoCapture() {} - + VideoCapture::VideoCapture(const string& filename) { open(filename); } - + VideoCapture::VideoCapture(int device) { open(device); @@ -449,21 +449,21 @@ VideoCapture::~VideoCapture() { cap.release(); } - + bool VideoCapture::open(const string& filename) { cap = cvCreateFileCapture(filename.c_str()); return isOpened(); } - + bool VideoCapture::open(int device) { cap = cvCreateCameraCapture(device); return isOpened(); } - + bool VideoCapture::isOpened() const { return !cap.empty(); } - + void VideoCapture::release() { cap.release(); @@ -473,7 +473,7 @@ bool VideoCapture::grab() { return cvGrabFrame(cap) != 0; } - + bool VideoCapture::retrieve(Mat& image, int channel) { IplImage* _img = cvRetrieveFrame(cap, channel); @@ -500,18 +500,18 @@ bool VideoCapture::read(Mat& image) image.release(); return !image.empty(); } - + VideoCapture& VideoCapture::operator >> (Mat& image) { read(image); return *this; } - + bool VideoCapture::set(int propId, double value) { return cvSetCaptureProperty(cap, propId, value) != 0; } - + double VideoCapture::get(int propId) { return cvGetCaptureProperty(cap, propId); @@ -519,7 +519,7 @@ double VideoCapture::get(int propId) VideoWriter::VideoWriter() {} - + VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size frameSize, bool isColor) { open(filename, fourcc, fps, frameSize, isColor); @@ -528,13 +528,13 @@ VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size fr void VideoWriter::release() { writer.release(); -} - +} + VideoWriter::~VideoWriter() { release(); } - + bool VideoWriter::open(const string& filename, int fourcc, double fps, Size frameSize, bool isColor) { writer = cvCreateVideoWriter(filename.c_str(), fourcc, fps, frameSize, isColor); @@ -544,18 +544,18 @@ bool VideoWriter::open(const string& filename, int fourcc, double fps, Size fram bool VideoWriter::isOpened() const { return !writer.empty(); -} +} void VideoWriter::write(const Mat& image) { IplImage _img = image; cvWriteFrame(writer, &_img); } - + VideoWriter& VideoWriter::operator << (const Mat& image) { write(image); - return *this; + return *this; } } diff --git a/modules/highgui/src/cap_ffmpeg.cpp b/modules/highgui/src/cap_ffmpeg.cpp index be89b9c..0cc60e3 100644 --- a/modules/highgui/src/cap_ffmpeg.cpp +++ b/modules/highgui/src/cap_ffmpeg.cpp @@ -123,7 +123,7 @@ icvInitFFMPEG(void) icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG; icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG; #endif - + ffmpegInitialized = 1; } } @@ -151,7 +151,7 @@ public: { unsigned char* data = 0; int step=0, width=0, height=0, cn=0; - + if(!ffmpegCapture || !icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) return 0; @@ -193,7 +193,7 @@ CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename) return cvCreateFileCapture_VFW(filename); #else return 0; -#endif +#endif } @@ -247,5 +247,5 @@ CvVideoWriter* cvCreateVideoWriter_FFMPEG_proxy( const char* filename, int fourc return cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, isColor); #else return 0; -#endif +#endif } diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index 025cb89..fc9ace5 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -66,7 +66,7 @@ extern "C" { #ifndef HAVE_FFMPEG_SWSCALE #error "libswscale is necessary to build the newer OpenCV ffmpeg wrapper" #endif - + // if the header path is not specified explicitly, let's deduce it #if !defined HAVE_FFMPEG_AVCODEC_H && !defined HAVE_LIBAVCODEC_AVCODEC_H @@ -140,7 +140,7 @@ extern "C" { #define AV_NOPTS_VALUE_ ((int64_t)AV_NOPTS_VALUE) #endif -int get_number_of_cpus(void) +static int get_number_of_cpus(void) { #if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(52, 111, 0) return 1; @@ -210,7 +210,7 @@ struct CvCapture_FFMPEG void seek(int64_t frame_number); void seek(double sec); - bool slowSeek( int framenumber ); + bool slowSeek( int framenumber ); int64_t get_total_frames(); double get_duration_sec(); @@ -225,8 +225,8 @@ struct CvCapture_FFMPEG AVCodec * avcodec; int video_stream; AVStream * video_st; - AVFrame * picture; - AVFrame rgb_picture; + AVFrame * picture; + AVFrame rgb_picture; int64_t picture_pts; AVPacket packet; @@ -274,7 +274,7 @@ void CvCapture_FFMPEG::close() sws_freeContext(img_convert_ctx); img_convert_ctx = 0; } - + if( picture ) av_free(picture); @@ -293,9 +293,9 @@ void CvCapture_FFMPEG::close() if( ic ) { #if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2) - av_close_input_file(ic); + av_close_input_file(ic); #else - avformat_close_input(&ic); + avformat_close_input(&ic); #endif ic = NULL; @@ -337,7 +337,7 @@ static void icvInitFFMPEG_internal() av_register_all(); av_log_set_level(AV_LOG_ERROR); - + initialized = true; } } @@ -345,18 +345,18 @@ static void icvInitFFMPEG_internal() bool CvCapture_FFMPEG::open( const char* _filename ) { icvInitFFMPEG_internal(); - + unsigned i; bool valid = false; close(); - + #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0) int err = avformat_open_input(&ic, _filename, NULL, NULL); #else int err = av_open_input_file(&ic, _filename, NULL, 0, NULL); -#endif - +#endif + if (err < 0) { CV_WARN("Error opening file"); goto exit_func; @@ -438,13 +438,13 @@ bool CvCapture_FFMPEG::grabFrame() const int max_number_of_attempts = 1 << 16; if( !ic || !video_st ) return false; - + if( ic->streams[video_stream]->nb_frames > 0 && frame_number > ic->streams[video_stream]->nb_frames ) return false; av_free_packet (&packet); - + picture_pts = AV_NOPTS_VALUE_; // get the next frame @@ -463,7 +463,7 @@ bool CvCapture_FFMPEG::grabFrame() break; continue; } - + // Decode video frame #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0) avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet); @@ -498,7 +498,7 @@ bool CvCapture_FFMPEG::grabFrame() if( valid && first_frame_number < 0 ) first_frame_number = dts_to_frame_number(picture_pts); - + // return if we have a new picture or not return valid; } @@ -518,7 +518,7 @@ bool CvCapture_FFMPEG::retrieveFrame(int, unsigned char** data, int* step, int* { if( img_convert_ctx ) sws_freeContext(img_convert_ctx); - + frame.width = video_st->codec->width; frame.height = video_st->codec->height; @@ -629,7 +629,7 @@ double CvCapture_FFMPEG::get_fps() { fps = r2d(ic->streams[video_stream]->avg_frame_rate); } -#endif +#endif if (fps < eps_zero) { @@ -666,12 +666,12 @@ void CvCapture_FFMPEG::seek(int64_t _frame_number) { _frame_number = std::min(_frame_number, get_total_frames()); int delta = 16; - + // if we have not grabbed a single frame before first seek, let's read the first frame // and get some valuable information during the process if( first_frame_number < 0 && get_total_frames() > 1 ) grabFrame(); - + for(;;) { int64_t _frame_number_temp = std::max(_frame_number-delta, (int64_t)0); @@ -684,13 +684,13 @@ void CvCapture_FFMPEG::seek(int64_t _frame_number) if( _frame_number > 0 ) { grabFrame(); - + if( _frame_number > 1 ) { frame_number = dts_to_frame_number(picture_pts) - first_frame_number; //printf("_frame_number = %d, frame_number = %d, delta = %d\n", // (int)_frame_number, (int)frame_number, delta); - + if( frame_number < 0 || frame_number > _frame_number-1 ) { if( _frame_number_temp == 0 || delta >= INT_MAX/4 ) @@ -771,7 +771,7 @@ struct CvVideoWriter_FFMPEG void init(); - AVOutputFormat * fmt; + AVOutputFormat * fmt; AVFormatContext * oc; uint8_t * outbuf; uint32_t outbuf_size; @@ -1010,7 +1010,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, static const int OPENCV_NO_FRAMES_WRITTEN_CODE = 1000; -int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture ) +static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture ) { #if LIBAVFORMAT_BUILD > 4628 AVCodecContext * c = video_st->codec; @@ -1046,7 +1046,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_ #if LIBAVFORMAT_BUILD > 4752 if(c->coded_frame->pts != (int64_t)AV_NOPTS_VALUE) - pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base); + pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base); #else pkt.pts = c->coded_frame->pts; #endif @@ -1069,7 +1069,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int width, int height, int cn, int origin ) { bool ret = false; - + if( (width & -2) != frame_width || (height & -2) != frame_height || !data ) return false; width = frame_width; @@ -1180,7 +1180,7 @@ void CvVideoWriter_FFMPEG::close() // nothing to do if already released if ( !picture ) return; - + /* no more frame to compress. The codec has a latency of a few frames if using B frames, so we get the last frames by passing the same picture again */ @@ -1200,7 +1200,7 @@ void CvVideoWriter_FFMPEG::close() } av_write_trailer(oc); } - + if( img_convert_ctx ) { sws_freeContext(img_convert_ctx); @@ -1272,7 +1272,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, double fps, int width, int height, bool is_color ) { icvInitFFMPEG_internal(); - + CodecID codec_id = CODEC_ID_NONE; int err, codec_pix_fmt; double bitrate_scale = 1; @@ -1284,7 +1284,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, return false; if(fps <= 0) return false; - + // we allow frames of odd width or height, but in this case we truncate // the rightmost column/the bottom row. Probably, this should be handled more elegantly, // but some internal functions inside FFMPEG swscale require even width/height. @@ -1363,7 +1363,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, codec_pix_fmt = PIX_FMT_YUV420P; break; } - + double bitrate = MIN(bitrate_scale*fps*width*height, (double)INT_MAX/2); // TODO -- safe to ignore output audio stream? @@ -1480,8 +1480,8 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, err=avformat_write_header(oc, NULL); #else err=av_write_header( oc ); -#endif - +#endif + if(err < 0) { close(); @@ -1579,7 +1579,7 @@ struct OutputMediaStream_FFMPEG { bool open(const char* fileName, int width, int height, double fps); void close(); - + void write(unsigned char* data, int size, int keyFrame); // add a video output stream to the container @@ -1692,7 +1692,7 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CodecID { AVRational error = av_sub_q(req, *p); - if (error.num < 0) + if (error.num < 0) error.num *= -1; if (av_cmp_q(error, best_error) < 0) @@ -1825,7 +1825,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height, void OutputMediaStream_FFMPEG::write(unsigned char* data, int size, int keyFrame) { // if zero size, it means the image was buffered - if (size > 0) + if (size > 0) { AVPacket pkt; av_init_packet(&pkt); @@ -1851,7 +1851,7 @@ struct OutputMediaStream_FFMPEG* create_OutputMediaStream_FFMPEG(const char* fil stream->close(); free(stream); - + return 0; } diff --git a/modules/highgui/src/cap_openni.cpp b/modules/highgui/src/cap_openni.cpp index 739adf8..7ec7cf8 100644 --- a/modules/highgui/src/cap_openni.cpp +++ b/modules/highgui/src/cap_openni.cpp @@ -50,6 +50,20 @@ #include #include + +#ifndef i386 +# define i386 0 +#endif +#ifndef __arm__ +# define __arm__ 0 +#endif +#ifndef _ARC +# define _ARC 0 +#endif +#ifndef __APPLE__ +# define __APPLE__ 0 +#endif + #include "XnCppWrapper.h" const std::string XMLConfig = @@ -169,6 +183,8 @@ private: approxSyncGrabber(approxSyncGrabber), isDepthFilled(false), isImageFilled(false) {} + virtual ~ApproximateSynchronizerBase() {} + virtual bool isSpinContinue() const = 0; virtual void pushDepthMetaData( xn::DepthMetaData& depthMetaData ) = 0; virtual void pushImageMetaData( xn::ImageMetaData& imageMetaData ) = 0; @@ -410,7 +426,7 @@ class CvCapture_OpenNI : public CvCapture { public: enum { DEVICE_DEFAULT=0, DEVICE_MS_KINECT=0, DEVICE_ASUS_XTION=1, DEVICE_MAX=1 }; - + static const int INVALID_PIXEL_VAL = 0; static const int INVALID_COORDINATE_VAL = 0; @@ -508,26 +524,26 @@ bool CvCapture_OpenNI::isOpened() const return isContextOpened; } -XnMapOutputMode defaultMapOutputMode() -{ - XnMapOutputMode mode; - mode.nXRes = XN_VGA_X_RES; - mode.nYRes = XN_VGA_Y_RES; - mode.nFPS = 30; - return mode; -} +// static XnMapOutputMode defaultMapOutputMode() +// { +// XnMapOutputMode mode; +// mode.nXRes = XN_VGA_X_RES; +// mode.nYRes = XN_VGA_Y_RES; +// mode.nFPS = 30; +// return mode; +// } CvCapture_OpenNI::CvCapture_OpenNI( int index ) { int deviceType = DEVICE_DEFAULT; XnStatus status; - + isContextOpened = false; maxBufferSize = DEFAULT_MAX_BUFFER_SIZE; isCircleBuffer = DEFAULT_IS_CIRCLE_BUFFER; maxTimeDuration = DEFAULT_MAX_TIME_DURATION; - + if( index >= 10 ) { deviceType = index / 10; @@ -1201,7 +1217,7 @@ IplImage* CvCapture_OpenNI::retrievePointCloudMap() return outputMaps[CV_CAP_OPENNI_POINT_CLOUD_MAP].getIplImagePtr(); } -void computeDisparity_32F( const xn::DepthMetaData& depthMetaData, cv::Mat& disp, XnDouble baseline, XnUInt64 F, +static void computeDisparity_32F( const xn::DepthMetaData& depthMetaData, cv::Mat& disp, XnDouble baseline, XnUInt64 F, XnUInt64 noSampleValue, XnUInt64 shadowValue ) { cv::Mat depth; diff --git a/modules/highgui/src/grfmt_jpeg.cpp b/modules/highgui/src/grfmt_jpeg.cpp index 183a38e..ec45c84 100644 --- a/modules/highgui/src/grfmt_jpeg.cpp +++ b/modules/highgui/src/grfmt_jpeg.cpp @@ -126,8 +126,7 @@ skip_input_data(j_decompress_ptr cinfo, long num_bytes) } -GLOBAL(void) -jpeg_buffer_src(j_decompress_ptr cinfo, JpegSource* source) +static void jpeg_buffer_src(j_decompress_ptr cinfo, JpegSource* source) { cinfo->src = &source->pub; @@ -498,8 +497,7 @@ empty_output_buffer (j_compress_ptr cinfo) return TRUE; } -GLOBAL(void) -jpeg_buffer_dest(j_compress_ptr cinfo, JpegDestination* destination) +static void jpeg_buffer_dest(j_compress_ptr cinfo, JpegDestination* destination) { cinfo->dest = &destination->pub; diff --git a/modules/highgui/src/loadsave.cpp b/modules/highgui/src/loadsave.cpp index b903b03..9250fff 100644 --- a/modules/highgui/src/loadsave.cpp +++ b/modules/highgui/src/loadsave.cpp @@ -57,7 +57,7 @@ namespace cv static vector decoders; static vector encoders; -ImageDecoder findDecoder( const string& filename ) +static ImageDecoder findDecoder( const string& filename ) { size_t i, maxlen = 0; for( i = 0; i < decoders.size(); i++ ) @@ -83,7 +83,7 @@ ImageDecoder findDecoder( const string& filename ) return ImageDecoder(); } -ImageDecoder findDecoder( const Mat& buf ) +static ImageDecoder findDecoder( const Mat& buf ) { size_t i, maxlen = 0; @@ -110,7 +110,7 @@ ImageDecoder findDecoder( const Mat& buf ) return ImageDecoder(); } -ImageEncoder findEncoder( const string& _ext ) +static ImageEncoder findEncoder( const string& _ext ) { if( _ext.size() <= 1 ) return ImageEncoder(); @@ -395,7 +395,7 @@ Mat imdecode( InputArray _buf, int flags ) imdecode_( buf, flags, LOAD_MAT, &img ); return img; } - + bool imencode( const string& ext, InputArray _image, vector& buf, const vector& params ) { diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 415f5e8..5664dd7 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -42,7 +42,7 @@ #ifndef __HIGHGUI_H_ #define __HIGHGUI_H_ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 ) #endif diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index 30bf973..0924277 100755 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -1,4 +1,4 @@ -//IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +//IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, @@ -78,181 +78,181 @@ static CvWinProperties* global_control_panel = NULL; CV_IMPL CvFont cvFontQt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing) { - /* - //nameFont <- only Qt - //CvScalar color <- only Qt (blue_component, green_component, red\_component[, alpha_component]) - int font_face;//<- style in Qt - const int* ascii; - const int* greek; - const int* cyrillic; - float hscale, vscale; - float shear; - int thickness;//<- weight in Qt - float dx;//spacing letter in Qt (0 default) in pixel - int line_type;//<- pointSize in Qt - */ - CvFont f = {nameFont,color,style,NULL,NULL,NULL,0,0,0,weight,spacing,pointSize}; - return f; + /* + //nameFont <- only Qt + //CvScalar color <- only Qt (blue_component, green_component, red\_component[, alpha_component]) + int font_face;//<- style in Qt + const int* ascii; + const int* greek; + const int* cyrillic; + float hscale, vscale; + float shear; + int thickness;//<- weight in Qt + float dx;//spacing letter in Qt (0 default) in pixel + int line_type;//<- pointSize in Qt + */ + CvFont f = {nameFont,color,style,NULL,NULL,NULL,0,0,0,weight,spacing,pointSize}; + return f; } CV_IMPL void cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont* font) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "putText", - Qt::AutoConnection, - Q_ARG(void*, (void*) img), - Q_ARG(QString,QString(text)), - Q_ARG(QPoint, QPoint(org.x,org.y)), - Q_ARG(void*,(void*) font)); + QMetaObject::invokeMethod(guiMainThread, + "putText", + Qt::AutoConnection, + Q_ARG(void*, (void*) img), + Q_ARG(QString,QString(text)), + Q_ARG(QPoint, QPoint(org.x,org.y)), + Q_ARG(void*,(void*) font)); } double cvGetRatioWindow_QT(const char* name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - double result = -1; - QMetaObject::invokeMethod(guiMainThread, - "getRatioWindow", - //Qt::DirectConnection, - Qt::AutoConnection, - Q_RETURN_ARG(double, result), - Q_ARG(QString, QString(name))); + double result = -1; + QMetaObject::invokeMethod(guiMainThread, + "getRatioWindow", + //Qt::DirectConnection, + Qt::AutoConnection, + Q_RETURN_ARG(double, result), + Q_ARG(QString, QString(name))); - return result; + return result; } void cvSetRatioWindow_QT(const char* name,double prop_value) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "setRatioWindow", - Qt::AutoConnection, - Q_ARG(QString, QString(name)), - Q_ARG(double, prop_value)); + QMetaObject::invokeMethod(guiMainThread, + "setRatioWindow", + Qt::AutoConnection, + Q_ARG(QString, QString(name)), + Q_ARG(double, prop_value)); } double cvGetPropWindow_QT(const char* name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - double result = -1; - QMetaObject::invokeMethod(guiMainThread, - "getPropWindow", - //Qt::DirectConnection, - Qt::AutoConnection, - Q_RETURN_ARG(double, result), - Q_ARG(QString, QString(name))); + double result = -1; + QMetaObject::invokeMethod(guiMainThread, + "getPropWindow", + //Qt::DirectConnection, + Qt::AutoConnection, + Q_RETURN_ARG(double, result), + Q_ARG(QString, QString(name))); - return result; + return result; } void cvSetPropWindow_QT(const char* name,double prop_value) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "setPropWindow", - Qt::AutoConnection, - Q_ARG(QString, QString(name)), - Q_ARG(double, prop_value)); + QMetaObject::invokeMethod(guiMainThread, + "setPropWindow", + Qt::AutoConnection, + Q_ARG(QString, QString(name)), + Q_ARG(double, prop_value)); } void cvSetModeWindow_QT(const char* name, double prop_value) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "toggleFullScreen", - Qt::AutoConnection, - Q_ARG(QString, QString(name)), - Q_ARG(double, prop_value)); + QMetaObject::invokeMethod(guiMainThread, + "toggleFullScreen", + Qt::AutoConnection, + Q_ARG(QString, QString(name)), + Q_ARG(double, prop_value)); } double cvGetModeWindow_QT(const char* name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - double result = -1; + double result = -1; - QMetaObject::invokeMethod(guiMainThread, - "isFullScreen", - Qt::AutoConnection, - Q_RETURN_ARG(double, result), - Q_ARG(QString, QString(name))); + QMetaObject::invokeMethod(guiMainThread, + "isFullScreen", + Qt::AutoConnection, + Q_RETURN_ARG(double, result), + Q_ARG(QString, QString(name))); - return result; + return result; } CV_IMPL void cvDisplayOverlay(const char* name, const char* text, int delayms) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "displayInfo", - Qt::AutoConnection, - //Qt::DirectConnection, - Q_ARG(QString, QString(name)), - Q_ARG(QString, QString(text)), - Q_ARG(int, delayms)); + QMetaObject::invokeMethod(guiMainThread, + "displayInfo", + Qt::AutoConnection, + //Qt::DirectConnection, + Q_ARG(QString, QString(name)), + Q_ARG(QString, QString(text)), + Q_ARG(int, delayms)); } CV_IMPL void cvSaveWindowParameters(const char* name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "saveWindowParameters", - Qt::AutoConnection, - Q_ARG(QString, QString(name))); + QMetaObject::invokeMethod(guiMainThread, + "saveWindowParameters", + Qt::AutoConnection, + Q_ARG(QString, QString(name))); } CV_IMPL void cvLoadWindowParameters(const char* name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "loadWindowParameters", - Qt::AutoConnection, - Q_ARG(QString, QString(name))); + QMetaObject::invokeMethod(guiMainThread, + "loadWindowParameters", + Qt::AutoConnection, + Q_ARG(QString, QString(name))); } CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "displayStatusBar", - Qt::AutoConnection, - //Qt::DirectConnection, - Q_ARG(QString, QString(name)), - Q_ARG(QString, QString(text)), - Q_ARG(int, delayms)); + QMetaObject::invokeMethod(guiMainThread, + "displayStatusBar", + Qt::AutoConnection, + //Qt::DirectConnection, + Q_ARG(QString, QString(name)), + Q_ARG(QString, QString(text)), + Q_ARG(int, delayms)); } @@ -337,19 +337,19 @@ CV_IMPL int cvWaitKey(int delay) //We recommend not using this function for now CV_IMPL int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]) { - multiThreads = true; - QFuture future = QtConcurrent::run(pt2Func, argc, argv); - return guiMainThread->start(); + multiThreads = true; + QFuture future = QtConcurrent::run(pt2Func, argc, argv); + return guiMainThread->start(); } CV_IMPL void cvStopLoop() { - qApp->exit(); + qApp->exit(); } -CvWindow* icvFindWindowByName(QString name) +static CvWindow* icvFindWindowByName(QString name) { CvWindow* window = 0; @@ -357,100 +357,100 @@ CvWindow* icvFindWindowByName(QString name) //that can be grabbed here and crash the code at 'w->param_name==name'. foreach (QWidget* widget, QApplication::topLevelWidgets()) { - if (widget->isWindow() && !widget->parentWidget())//is a window without parent - { - CvWinModel* temp = (CvWinModel*) widget; + if (widget->isWindow() && !widget->parentWidget())//is a window without parent + { + CvWinModel* temp = (CvWinModel*) widget; - if (temp->type == type_CvWindow) - { - CvWindow* w = (CvWindow*) temp; + if (temp->type == type_CvWindow) + { + CvWindow* w = (CvWindow*) temp; if (w->windowTitle() == name) - { - window = w; - break; - } - } - } - } + { + window = w; + break; + } + } + } + } return window; } -CvBar* icvFindBarByName(QBoxLayout* layout, QString name_bar, typeBar type) +static CvBar* icvFindBarByName(QBoxLayout* layout, QString name_bar, typeBar type) { if (!layout) - return NULL; + return NULL; int stop_index = layout->layout()->count(); for (int i = 0; i < stop_index; ++i) { - CvBar* t = (CvBar*) layout->layout()->itemAt(i); + CvBar* t = (CvBar*) layout->layout()->itemAt(i); - if (t->type == type && t->name_bar == name_bar) - return t; + if (t->type == type && t->name_bar == name_bar) + return t; } return NULL; } -CvTrackbar* icvFindTrackBarByName(const char* name_trackbar, const char* name_window, QBoxLayout* layout = NULL) +static CvTrackbar* icvFindTrackBarByName(const char* name_trackbar, const char* name_window, QBoxLayout* layout = NULL) { QString nameQt(name_trackbar); if (!name_window && global_control_panel) //window name is null and we have a control panel - layout = global_control_panel->myLayout; + layout = global_control_panel->myLayout; if (!layout) { - QPointer w = icvFindWindowByName(QLatin1String(name_window)); + QPointer w = icvFindWindowByName(QLatin1String(name_window)); - if (!w) - CV_Error(CV_StsNullPtr, "NULL window handler"); + if (!w) + CV_Error(CV_StsNullPtr, "NULL window handler"); - if (w->param_gui_mode == CV_GUI_NORMAL) - return (CvTrackbar*) icvFindBarByName(w->myBarLayout, nameQt, type_CvTrackbar); + if (w->param_gui_mode == CV_GUI_NORMAL) + return (CvTrackbar*) icvFindBarByName(w->myBarLayout, nameQt, type_CvTrackbar); - if (w->param_gui_mode == CV_GUI_EXPANDED) - { - CvBar* result = icvFindBarByName(w->myBarLayout, nameQt, type_CvTrackbar); + if (w->param_gui_mode == CV_GUI_EXPANDED) + { + CvBar* result = icvFindBarByName(w->myBarLayout, nameQt, type_CvTrackbar); - if (result) - return (CvTrackbar*) result; + if (result) + return (CvTrackbar*) result; - return (CvTrackbar*) icvFindBarByName(global_control_panel->myLayout, nameQt, type_CvTrackbar); - } + return (CvTrackbar*) icvFindBarByName(global_control_panel->myLayout, nameQt, type_CvTrackbar); + } - return NULL; + return NULL; } else { - //layout was specified - return (CvTrackbar*) icvFindBarByName(layout, nameQt, type_CvTrackbar); + //layout was specified + return (CvTrackbar*) icvFindBarByName(layout, nameQt, type_CvTrackbar); } } - -CvButtonbar* icvFindButtonBarByName(const char* button_name, QBoxLayout* layout) +/* +static CvButtonbar* icvFindButtonBarByName(const char* button_name, QBoxLayout* layout) { QString nameQt(button_name); return (CvButtonbar*) icvFindBarByName(layout, nameQt, type_CvButtonbar); } +*/ - -int icvInitSystem(int* c, char** v) +static int icvInitSystem(int* c, char** v) { //"For any GUI application using Qt, there is precisely one QApplication object" if (!QApplication::instance()) { - new QApplication(*c, v); + new QApplication(*c, v); - qDebug() << "init done"; + qDebug() << "init done"; #ifdef HAVE_QT_OPENGL - qDebug() << "opengl support available"; + qDebug() << "opengl support available"; #endif } @@ -460,212 +460,212 @@ int icvInitSystem(int* c, char** v) CV_IMPL int cvInitSystem(int, char**) { - icvInitSystem(¶meterSystemC, parameterSystemV); - return 0; + icvInitSystem(¶meterSystemC, parameterSystemV); + return 0; } CV_IMPL int cvNamedWindow(const char* name, int flags) { - if (!guiMainThread) - guiMainThread = new GuiReceiver; + if (!guiMainThread) + guiMainThread = new GuiReceiver; - if (multiThreads) - QMetaObject::invokeMethod(guiMainThread, - "createWindow", - Qt::BlockingQueuedConnection, - Q_ARG(QString, QString(name)), - Q_ARG(int, flags)); - else - guiMainThread->createWindow(QString(name), flags); + if (multiThreads) + QMetaObject::invokeMethod(guiMainThread, + "createWindow", + Qt::BlockingQueuedConnection, + Q_ARG(QString, QString(name)), + Q_ARG(int, flags)); + else + guiMainThread->createWindow(QString(name), flags); - return 1; //Dummy value + return 1; //Dummy value } CV_IMPL void cvDestroyWindow(const char* name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "destroyWindow", - //Qt::BlockingQueuedConnection, - Qt::AutoConnection, - Q_ARG(QString, QString(name))); + QMetaObject::invokeMethod(guiMainThread, + "destroyWindow", + //Qt::BlockingQueuedConnection, + Qt::AutoConnection, + Q_ARG(QString, QString(name))); } CV_IMPL void cvDestroyAllWindows() { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "destroyAllWindow", - //Qt::BlockingQueuedConnection, - Qt::AutoConnection); + QMetaObject::invokeMethod(guiMainThread, + "destroyAllWindow", + //Qt::BlockingQueuedConnection, + Qt::AutoConnection); } CV_IMPL void* cvGetWindowHandle(const char* name) { - if (!name) - CV_Error( CV_StsNullPtr, "NULL name string" ); + if (!name) + CV_Error( CV_StsNullPtr, "NULL name string" ); - return (void*) icvFindWindowByName(QLatin1String(name)); + return (void*) icvFindWindowByName(QLatin1String(name)); } CV_IMPL const char* cvGetWindowName(void* window_handle) { - if( !window_handle ) - CV_Error( CV_StsNullPtr, "NULL window handler" ); + if( !window_handle ) + CV_Error( CV_StsNullPtr, "NULL window handler" ); - return ((CvWindow*)window_handle)->windowTitle().toLatin1().data(); + return ((CvWindow*)window_handle)->windowTitle().toLatin1().data(); } CV_IMPL void cvMoveWindow(const char* name, int x, int y) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "moveWindow", - //Qt::BlockingQueuedConnection, - Qt::AutoConnection, - Q_ARG(QString, QString(name)), - Q_ARG(int, x), - Q_ARG(int, y)); + QMetaObject::invokeMethod(guiMainThread, + "moveWindow", + //Qt::BlockingQueuedConnection, + Qt::AutoConnection, + Q_ARG(QString, QString(name)), + Q_ARG(int, x), + Q_ARG(int, y)); } CV_IMPL void cvResizeWindow(const char* name, int width, int height) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "resizeWindow", - //Qt::BlockingQueuedConnection, - Qt::AutoConnection, - Q_ARG(QString, QString(name)), - Q_ARG(int, width), - Q_ARG(int, height)); + QMetaObject::invokeMethod(guiMainThread, + "resizeWindow", + //Qt::BlockingQueuedConnection, + Qt::AutoConnection, + Q_ARG(QString, QString(name)), + Q_ARG(int, width), + Q_ARG(int, height)); } CV_IMPL int cvCreateTrackbar2(const char* name_bar, const char* window_name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "addSlider2", - Qt::AutoConnection, - Q_ARG(QString, QString(name_bar)), - Q_ARG(QString, QString(window_name)), - Q_ARG(void*, (void*)val), - Q_ARG(int, count), - Q_ARG(void*, (void*)on_notify), - Q_ARG(void*, (void*)userdata)); + QMetaObject::invokeMethod(guiMainThread, + "addSlider2", + Qt::AutoConnection, + Q_ARG(QString, QString(name_bar)), + Q_ARG(QString, QString(window_name)), + Q_ARG(void*, (void*)val), + Q_ARG(int, count), + Q_ARG(void*, (void*)on_notify), + Q_ARG(void*, (void*)userdata)); - return 1; //dummy value + return 1; //dummy value } CV_IMPL int cvStartWindowThread() { - return 0; + return 0; } CV_IMPL int cvCreateTrackbar(const char* name_bar, const char* window_name, int* value, int count, CvTrackbarCallback on_change) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "addSlider", - Qt::AutoConnection, - Q_ARG(QString, QString(name_bar)), - Q_ARG(QString, QString(window_name)), - Q_ARG(void*, (void*)value), - Q_ARG(int, count), - Q_ARG(void*, (void*)on_change)); + QMetaObject::invokeMethod(guiMainThread, + "addSlider", + Qt::AutoConnection, + Q_ARG(QString, QString(name_bar)), + Q_ARG(QString, QString(window_name)), + Q_ARG(void*, (void*)value), + Q_ARG(int, count), + Q_ARG(void*, (void*)on_change)); - return 1; //dummy value + return 1; //dummy value } CV_IMPL int cvCreateButton(const char* button_name, CvButtonCallback on_change, void* userdata, int button_type, int initial_button_state) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - if (initial_button_state < 0 || initial_button_state > 1) - return 0; + if (initial_button_state < 0 || initial_button_state > 1) + return 0; - QMetaObject::invokeMethod(guiMainThread, - "addButton", - Qt::AutoConnection, - Q_ARG(QString, QString(button_name)), - Q_ARG(int, button_type), - Q_ARG(int, initial_button_state), - Q_ARG(void*, (void*)on_change), - Q_ARG(void*, userdata)); + QMetaObject::invokeMethod(guiMainThread, + "addButton", + Qt::AutoConnection, + Q_ARG(QString, QString(button_name)), + Q_ARG(int, button_type), + Q_ARG(int, initial_button_state), + Q_ARG(void*, (void*)on_change), + Q_ARG(void*, userdata)); - return 1;//dummy value + return 1;//dummy value } CV_IMPL int cvGetTrackbarPos(const char* name_bar, const char* window_name) { - int result = -1; + int result = -1; - QPointer t = icvFindTrackBarByName(name_bar, window_name); + QPointer t = icvFindTrackBarByName(name_bar, window_name); - if (t) - result = t->slider->value(); + if (t) + result = t->slider->value(); - return result; + return result; } CV_IMPL void cvSetTrackbarPos(const char* name_bar, const char* window_name, int pos) { - QPointer t = icvFindTrackBarByName(name_bar, window_name); + QPointer t = icvFindTrackBarByName(name_bar, window_name); - if (t) - t->slider->setValue(pos); + if (t) + t->slider->setValue(pos); } /* assign callback for mouse events */ CV_IMPL void cvSetMouseCallback(const char* window_name, CvMouseCallback on_mouse, void* param) { - QPointer w = icvFindWindowByName(QLatin1String(window_name)); + QPointer w = icvFindWindowByName(QLatin1String(window_name)); - if (!w) - CV_Error(CV_StsNullPtr, "NULL window handler"); + if (!w) + CV_Error(CV_StsNullPtr, "NULL window handler"); - w->setMouseCallBack(on_mouse, param); + w->setMouseCallBack(on_mouse, param); } CV_IMPL void cvShowImage(const char* name, const CvArr* arr) { - if (!guiMainThread) - guiMainThread = new GuiReceiver; + if (!guiMainThread) + guiMainThread = new GuiReceiver; - QMetaObject::invokeMethod(guiMainThread, - "showImage", - //Qt::BlockingQueuedConnection, - Qt::DirectConnection, - Q_ARG(QString, QString(name)), - Q_ARG(void*, (void*)arr)); + QMetaObject::invokeMethod(guiMainThread, + "showImage", + //Qt::BlockingQueuedConnection, + Qt::DirectConnection, + Q_ARG(QString, QString(name)), + Q_ARG(void*, (void*)arr)); } @@ -673,53 +673,53 @@ CV_IMPL void cvShowImage(const char* name, const CvArr* arr) CV_IMPL void cvSetOpenGlDrawCallback(const char* window_name, CvOpenGlDrawCallback callback, void* userdata) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "setOpenGlDrawCallback", - Qt::AutoConnection, - Q_ARG(QString, QString(window_name)), - Q_ARG(void*, (void*)callback), - Q_ARG(void*, userdata)); + QMetaObject::invokeMethod(guiMainThread, + "setOpenGlDrawCallback", + Qt::AutoConnection, + Q_ARG(QString, QString(window_name)), + Q_ARG(void*, (void*)callback), + Q_ARG(void*, userdata)); } void icvSetOpenGlCleanCallback(const char* window_name, CvOpenGlCleanCallback callback, void* userdata) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "setOpenGlCleanCallback", - Qt::AutoConnection, - Q_ARG(QString, QString(window_name)), - Q_ARG(void*, (void*)callback), - Q_ARG(void*, userdata)); + QMetaObject::invokeMethod(guiMainThread, + "setOpenGlCleanCallback", + Qt::AutoConnection, + Q_ARG(QString, QString(window_name)), + Q_ARG(void*, (void*)callback), + Q_ARG(void*, userdata)); } CV_IMPL void cvSetOpenGlContext(const char* window_name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "setOpenGlContext", - Qt::AutoConnection, - Q_ARG(QString, QString(window_name))); + QMetaObject::invokeMethod(guiMainThread, + "setOpenGlContext", + Qt::AutoConnection, + Q_ARG(QString, QString(window_name))); } CV_IMPL void cvUpdateWindow(const char* window_name) { - if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + if (!guiMainThread) + CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); - QMetaObject::invokeMethod(guiMainThread, - "updateWindow", - Qt::AutoConnection, - Q_ARG(QString, QString(window_name))); + QMetaObject::invokeMethod(guiMainThread, + "updateWindow", + Qt::AutoConnection, + Q_ARG(QString, QString(window_name))); } #endif @@ -727,18 +727,18 @@ CV_IMPL void cvUpdateWindow(const char* window_name) double cvGetOpenGlProp_QT(const char* name) { - double result = -1; + double result = -1; - if (guiMainThread) + if (guiMainThread) { - QMetaObject::invokeMethod(guiMainThread, - "isOpenGl", - Qt::AutoConnection, - Q_RETURN_ARG(double, result), - Q_ARG(QString, QString(name))); + QMetaObject::invokeMethod(guiMainThread, + "isOpenGl", + Qt::AutoConnection, + Q_RETURN_ARG(double, result), + Q_ARG(QString, QString(name))); } - return result; + return result; } @@ -748,108 +748,108 @@ double cvGetOpenGlProp_QT(const char* name) GuiReceiver::GuiReceiver() : bTimeOut(false), nb_windows(0) { - doesExternalQAppExist = (QApplication::instance() != 0); - icvInitSystem(¶meterSystemC, parameterSystemV); + doesExternalQAppExist = (QApplication::instance() != 0); + icvInitSystem(¶meterSystemC, parameterSystemV); - timer = new QTimer(this); - QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timeOut())); - timer->setSingleShot(true); + timer = new QTimer(this); + QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timeOut())); + timer->setSingleShot(true); } void GuiReceiver::isLastWindow() { - if (--nb_windows <= 0) - { - delete guiMainThread;//delete global_control_panel too - guiMainThread = NULL; + if (--nb_windows <= 0) + { + delete guiMainThread;//delete global_control_panel too + guiMainThread = NULL; - if (!doesExternalQAppExist) - { - qApp->quit(); - } - } + if (!doesExternalQAppExist) + { + qApp->quit(); + } + } } GuiReceiver::~GuiReceiver() -{ - if (global_control_panel) - { - delete global_control_panel; - global_control_panel = NULL; - } +{ + if (global_control_panel) + { + delete global_control_panel; + global_control_panel = NULL; + } } void GuiReceiver::putText(void* arr, QString text, QPoint org, void* arg2) { - CV_Assert(arr); + CV_Assert(arr); - CvMat* mat, stub; - mat = cvGetMat(arr, &stub); + CvMat* mat, stub; + mat = cvGetMat(arr, &stub); - int nbChannelOriginImage = cvGetElemType(mat); - if (nbChannelOriginImage != CV_8UC3) return; //for now, font works only with 8UC3 + int nbChannelOriginImage = cvGetElemType(mat); + if (nbChannelOriginImage != CV_8UC3) return; //for now, font works only with 8UC3 - QImage qimg(mat->data.ptr, mat->cols, mat->rows, mat->step, QImage::Format_RGB888); + QImage qimg(mat->data.ptr, mat->cols, mat->rows, mat->step, QImage::Format_RGB888); - CvFont* font = (CvFont*)arg2; + CvFont* font = (CvFont*)arg2; - QPainter qp(&qimg); - if (font) - { - QFont f(font->nameFont, font->line_type/*PointSize*/, font->thickness/*weight*/); - f.setStyle((QFont::Style) font->font_face/*style*/); - f.setLetterSpacing(QFont::AbsoluteSpacing, font->dx/*spacing*/); - //cvScalar(blue_component, green_component, red_component[, alpha_component]) - //Qt map non-transparent to 0xFF and transparent to 0 - //OpenCV scalar is the reverse, so 255-font->color.val[3] - qp.setPen(QColor(font->color.val[2], font->color.val[1], font->color.val[0], 255 - font->color.val[3])); - qp.setFont(f); - } - qp.drawText(org, text); - qp.end(); + QPainter qp(&qimg); + if (font) + { + QFont f(font->nameFont, font->line_type/*PointSize*/, font->thickness/*weight*/); + f.setStyle((QFont::Style) font->font_face/*style*/); + f.setLetterSpacing(QFont::AbsoluteSpacing, font->dx/*spacing*/); + //cvScalar(blue_component, green_component, red_component[, alpha_component]) + //Qt map non-transparent to 0xFF and transparent to 0 + //OpenCV scalar is the reverse, so 255-font->color.val[3] + qp.setPen(QColor(font->color.val[2], font->color.val[1], font->color.val[0], 255 - font->color.val[3])); + qp.setFont(f); + } + qp.drawText(org, text); + qp.end(); } void GuiReceiver::saveWindowParameters(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->writeSettings(); + if (w) + w->writeSettings(); } void GuiReceiver::loadWindowParameters(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->readSettings(); + if (w) + w->readSettings(); } double GuiReceiver::getRatioWindow(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (!w) - return -1; + if (!w) + return -1; - return w->getRatio(); + return w->getRatio(); } void GuiReceiver::setRatioWindow(QString name, double arg2) { - QPointer w = icvFindWindowByName( name.toLatin1().data() ); + QPointer w = icvFindWindowByName( name.toLatin1().data() ); + + if (!w) + return; - if (!w) - return; - - int flags = (int) arg2; + int flags = (int) arg2; w->setRatio(flags); } @@ -857,23 +857,23 @@ void GuiReceiver::setRatioWindow(QString name, double arg2) double GuiReceiver::getPropWindow(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (!w) - return -1; + if (!w) + return -1; - return (double) w->getPropWindow(); + return (double) w->getPropWindow(); } void GuiReceiver::setPropWindow(QString name, double arg2) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (!w) - return; + if (!w) + return; - int flags = (int) arg2; + int flags = (int) arg2; w->setPropWindow(flags); } @@ -881,10 +881,10 @@ void GuiReceiver::setPropWindow(QString name, double arg2) double GuiReceiver::isFullScreen(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (!w) - return -1; + if (!w) + return -1; return w->isFullScreen() ? CV_WINDOW_FULLSCREEN : CV_WINDOW_NORMAL; } @@ -892,12 +892,12 @@ double GuiReceiver::isFullScreen(QString name) void GuiReceiver::toggleFullScreen(QString name, double arg2) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (!w) - return; + if (!w) + return; - int flags = (int) arg2; + int flags = (int) arg2; w->toggleFullScreen(flags); } @@ -905,53 +905,53 @@ void GuiReceiver::toggleFullScreen(QString name, double arg2) void GuiReceiver::createWindow(QString name, int flags) { - if (!qApp) - CV_Error(CV_StsNullPtr, "NULL session handler" ); + if (!qApp) + CV_Error(CV_StsNullPtr, "NULL session handler" ); - // Check the name in the storage - if (icvFindWindowByName(name.toLatin1().data())) - { - return; - } + // Check the name in the storage + if (icvFindWindowByName(name.toLatin1().data())) + { + return; + } - nb_windows++; - new CvWindow(name, flags); + nb_windows++; + new CvWindow(name, flags); } void GuiReceiver::timeOut() { - bTimeOut = true; + bTimeOut = true; } void GuiReceiver::displayInfo(QString name, QString text, int delayms) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->displayInfo(text, delayms); + if (w) + w->displayInfo(text, delayms); } void GuiReceiver::displayStatusBar(QString name, QString text, int delayms) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->displayStatusBar(text, delayms); + if (w) + w->displayStatusBar(text, delayms); } void GuiReceiver::showImage(QString name, void* arr) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (!w) //as observed in the previous implementation (W32, GTK or Carbon), create a new window is the pointer returned is null - { - cvNamedWindow(name.toLatin1().data()); - w = icvFindWindowByName(name); - } + if (!w) //as observed in the previous implementation (W32, GTK or Carbon), create a new window is the pointer returned is null + { + cvNamedWindow(name.toLatin1().data()); + w = icvFindWindowByName(name); + } if (!w || !arr) return; // keep silence here. @@ -960,253 +960,253 @@ void GuiReceiver::showImage(QString name, void* arr) { CvMat* mat, stub; - mat = cvGetMat(arr, &stub); + mat = cvGetMat(arr, &stub); cv::Mat im(mat); cv::imshow(name.toStdString(), im); } else { - w->updateImage(arr); + w->updateImage(arr); } - if (w->isHidden()) - w->show(); + if (w->isHidden()) + w->show(); } void GuiReceiver::destroyWindow(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - { - w->close(); + if (w) + { + w->close(); - //in not-multiThreads mode, looks like the window is hidden but not deleted - //so I do it manually - //otherwise QApplication do it for me if the exec command was executed (in multiThread mode) - if (!multiThreads) - delete w; - } + //in not-multiThreads mode, looks like the window is hidden but not deleted + //so I do it manually + //otherwise QApplication do it for me if the exec command was executed (in multiThread mode) + if (!multiThreads) + delete w; + } } void GuiReceiver::destroyAllWindow() { - if (!qApp) - CV_Error(CV_StsNullPtr, "NULL session handler" ); - - if (multiThreads) - { - // WARNING: this could even close windows from an external parent app - //#TODO check externalQAppExists and in case it does, close windows carefully, - // i.e. apply the className-check from below... - qApp->closeAllWindows(); - } - else - { - bool isWidgetDeleted = true; - while(isWidgetDeleted) - { - isWidgetDeleted = false; - QWidgetList list = QApplication::topLevelWidgets(); - for (int i = 0; i < list.count(); i++) - { - QObject *obj = list.at(i); - if (obj->metaObject()->className() == QString("CvWindow")) - { - delete obj; - isWidgetDeleted = true; - break; - } - } - } - } + if (!qApp) + CV_Error(CV_StsNullPtr, "NULL session handler" ); + + if (multiThreads) + { + // WARNING: this could even close windows from an external parent app + //#TODO check externalQAppExists and in case it does, close windows carefully, + // i.e. apply the className-check from below... + qApp->closeAllWindows(); + } + else + { + bool isWidgetDeleted = true; + while(isWidgetDeleted) + { + isWidgetDeleted = false; + QWidgetList list = QApplication::topLevelWidgets(); + for (int i = 0; i < list.count(); i++) + { + QObject *obj = list.at(i); + if (obj->metaObject()->className() == QString("CvWindow")) + { + delete obj; + isWidgetDeleted = true; + break; + } + } + } + } } void GuiReceiver::moveWindow(QString name, int x, int y) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->move(x, y); + if (w) + w->move(x, y); } void GuiReceiver::resizeWindow(QString name, int width, int height) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - { - w->showNormal(); + if (w) + { + w->showNormal(); w->setViewportSize(QSize(width, height)); - } + } } void GuiReceiver::enablePropertiesButtonEachWindow() { - //For each window, enable window property button - foreach (QWidget* widget, QApplication::topLevelWidgets()) - { - if (widget->isWindow() && !widget->parentWidget()) //is a window without parent - { - CvWinModel* temp = (CvWinModel*) widget; - if (temp->type == type_CvWindow) - { - CvWindow* w = (CvWindow*) widget; + //For each window, enable window property button + foreach (QWidget* widget, QApplication::topLevelWidgets()) + { + if (widget->isWindow() && !widget->parentWidget()) //is a window without parent + { + CvWinModel* temp = (CvWinModel*) widget; + if (temp->type == type_CvWindow) + { + CvWindow* w = (CvWindow*) widget; - //active window properties button - w->enablePropertiesButton(); - } - } - } + //active window properties button + w->enablePropertiesButton(); + } + } + } } void GuiReceiver::addButton(QString button_name, int button_type, int initial_button_state, void* on_change, void* userdata) { - if (!global_control_panel) - return; + if (!global_control_panel) + return; - QPointer b; + QPointer b; - if (global_control_panel->myLayout->count() == 0) //if that is the first button attach to the control panel, create a new button bar - { - b = CvWindow::createButtonBar(button_name); //the bar has the name of the first button attached to it - enablePropertiesButtonEachWindow(); + if (global_control_panel->myLayout->count() == 0) //if that is the first button attach to the control panel, create a new button bar + { + b = CvWindow::createButtonBar(button_name); //the bar has the name of the first button attached to it + enablePropertiesButtonEachWindow(); - } + } else { - CvBar* lastbar = (CvBar*) global_control_panel->myLayout->itemAt(global_control_panel->myLayout->count() - 1); + CvBar* lastbar = (CvBar*) global_control_panel->myLayout->itemAt(global_control_panel->myLayout->count() - 1); - if (lastbar->type == type_CvTrackbar) //if last bar is a trackbar, create a new buttonbar, else, attach to the current bar - b = CvWindow::createButtonBar(button_name); //the bar has the name of the first button attached to it - else - b = (CvButtonbar*) lastbar; + if (lastbar->type == type_CvTrackbar) //if last bar is a trackbar, create a new buttonbar, else, attach to the current bar + b = CvWindow::createButtonBar(button_name); //the bar has the name of the first button attached to it + else + b = (CvButtonbar*) lastbar; - } + } - b->addButton(button_name, (CvButtonCallback) on_change, userdata, button_type, initial_button_state); + b->addButton(button_name, (CvButtonCallback) on_change, userdata, button_type, initial_button_state); } void GuiReceiver::addSlider2(QString bar_name, QString window_name, void* value, int count, void* on_change, void *userdata) { - QBoxLayout *layout = NULL; - QPointer w; + QBoxLayout *layout = NULL; + QPointer w; if (!window_name.isEmpty()) - { - w = icvFindWindowByName(window_name); + { + w = icvFindWindowByName(window_name); - if (!w) - return; - } + if (!w) + return; + } else { - if (global_control_panel) - layout = global_control_panel->myLayout; - } + if (global_control_panel) + layout = global_control_panel->myLayout; + } - QPointer t = icvFindTrackBarByName(bar_name.toLatin1().data(), window_name.toLatin1().data(), layout); + QPointer t = icvFindTrackBarByName(bar_name.toLatin1().data(), window_name.toLatin1().data(), layout); - if (t) //trackbar exists - return; + if (t) //trackbar exists + return; - if (!value) - CV_Error(CV_StsNullPtr, "NULL value pointer" ); + if (!value) + CV_Error(CV_StsNullPtr, "NULL value pointer" ); - if (count <= 0) //count is the max value of the slider, so must be bigger than 0 - CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" ); + if (count <= 0) //count is the max value of the slider, so must be bigger than 0 + CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" ); - CvWindow::addSlider2(w, bar_name, (int*)value, count, (CvTrackbarCallback2) on_change, userdata); + CvWindow::addSlider2(w, bar_name, (int*)value, count, (CvTrackbarCallback2) on_change, userdata); } void GuiReceiver::addSlider(QString bar_name, QString window_name, void* value, int count, void* on_change) { - QBoxLayout *layout = NULL; - QPointer w; + QBoxLayout *layout = NULL; + QPointer w; - if (!window_name.isEmpty()) - { - w = icvFindWindowByName(window_name); + if (!window_name.isEmpty()) + { + w = icvFindWindowByName(window_name); - if (!w) - return; - } + if (!w) + return; + } else { - if (global_control_panel) - layout = global_control_panel->myLayout; - } + if (global_control_panel) + layout = global_control_panel->myLayout; + } - QPointer t = icvFindTrackBarByName(bar_name.toLatin1().data(), window_name.toLatin1().data(), layout); + QPointer t = icvFindTrackBarByName(bar_name.toLatin1().data(), window_name.toLatin1().data(), layout); - if (t) //trackbar exists - return; + if (t) //trackbar exists + return; - if (!value) - CV_Error(CV_StsNullPtr, "NULL value pointer" ); + if (!value) + CV_Error(CV_StsNullPtr, "NULL value pointer" ); - if (count <= 0) //count is the max value of the slider, so must be bigger than 0 - CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" ); + if (count <= 0) //count is the max value of the slider, so must be bigger than 0 + CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" ); - CvWindow::addSlider(w, bar_name, (int*)value, count, (CvTrackbarCallback) on_change); + CvWindow::addSlider(w, bar_name, (int*)value, count, (CvTrackbarCallback) on_change); } int GuiReceiver::start() { - return qApp->exec(); + return qApp->exec(); } void GuiReceiver::setOpenGlDrawCallback(QString name, void* callback, void* userdata) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->setOpenGlDrawCallback((CvOpenGlDrawCallback) callback, userdata); + if (w) + w->setOpenGlDrawCallback((CvOpenGlDrawCallback) callback, userdata); } void GuiReceiver::setOpenGlCleanCallback(QString name, void* callback, void* userdata) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->setOpenGlCleanCallback((CvOpenGlCleanCallback) callback, userdata); + if (w) + w->setOpenGlCleanCallback((CvOpenGlCleanCallback) callback, userdata); } void GuiReceiver::setOpenGlContext(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->makeCurrentOpenGlContext(); + if (w) + w->makeCurrentOpenGlContext(); } void GuiReceiver::updateWindow(QString name) { - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - w->updateGl(); + if (w) + w->updateGl(); } double GuiReceiver::isOpenGl(QString name) { double result = -1; - QPointer w = icvFindWindowByName(name); + QPointer w = icvFindWindowByName(name); - if (w) - result = (double) w->isOpenGl(); + if (w) + result = (double) w->isOpenGl(); return result; } @@ -1218,125 +1218,125 @@ double GuiReceiver::isOpenGl(QString name) CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback2 on_change, void* data) { - callback = NULL; - callback2 = on_change; - userdata = data; + callback = NULL; + callback2 = on_change; + userdata = data; - create(arg, name, value, count); + create(arg, name, value, count); } CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback on_change) { - callback = on_change; - callback2 = NULL; - userdata = NULL; + callback = on_change; + callback2 = NULL; + userdata = NULL; - create(arg, name, value, count); + create(arg, name, value, count); } void CvTrackbar::create(CvWindow* arg, QString name, int* value, int count) { - type = type_CvTrackbar; - myparent = arg; - name_bar = name; - setObjectName(name_bar); - dataSlider = value; + type = type_CvTrackbar; + myparent = arg; + name_bar = name; + setObjectName(name_bar); + dataSlider = value; - slider = new QSlider(Qt::Horizontal); - slider->setFocusPolicy(Qt::StrongFocus); - slider->setMinimum(0); - slider->setMaximum(count); - slider->setPageStep(5); - slider->setValue(*value); - slider->setTickPosition(QSlider::TicksBelow); + slider = new QSlider(Qt::Horizontal); + slider->setFocusPolicy(Qt::StrongFocus); + slider->setMinimum(0); + slider->setMaximum(count); + slider->setPageStep(5); + slider->setValue(*value); + slider->setTickPosition(QSlider::TicksBelow); - //Change style of the Slider - //slider->setStyleSheet(str_Trackbar_css); + //Change style of the Slider + //slider->setStyleSheet(str_Trackbar_css); - QFile qss(":/stylesheet-trackbar"); - if (qss.open(QFile::ReadOnly)) - { - slider->setStyleSheet(QLatin1String(qss.readAll())); - qss.close(); - } + QFile qss(":/stylesheet-trackbar"); + if (qss.open(QFile::ReadOnly)) + { + slider->setStyleSheet(QLatin1String(qss.readAll())); + qss.close(); + } - //this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?) - //slider->setTickPosition(QSlider::TicksBelow); - label = new QPushButton; - label->setFlat(true); - setLabel(slider->value()); + //this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?) + //slider->setTickPosition(QSlider::TicksBelow); + label = new QPushButton; + label->setFlat(true); + setLabel(slider->value()); - QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(update(int))); + QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(update(int))); - QObject::connect(label, SIGNAL(clicked()), this, SLOT(createDialog())); + QObject::connect(label, SIGNAL(clicked()), this, SLOT(createDialog())); - //label->setStyleSheet("QPushButton:disabled {color: black}"); + //label->setStyleSheet("QPushButton:disabled {color: black}"); - addWidget(label, Qt::AlignLeft);//name + value - addWidget(slider, Qt::AlignCenter);//slider + addWidget(label, Qt::AlignLeft);//name + value + addWidget(slider, Qt::AlignCenter);//slider } void CvTrackbar::createDialog() { - bool ok = false; + bool ok = false; - //crash if I access the values directly and give them to QInputDialog, so do a copy first. - int value = slider->value(); - int step = slider->singleStep(); - int min = slider->minimum(); - int max = slider->maximum(); + //crash if I access the values directly and give them to QInputDialog, so do a copy first. + int value = slider->value(); + int step = slider->singleStep(); + int min = slider->minimum(); + int max = slider->maximum(); - int i = + int i = #if QT_VERSION >= 0x040500 - QInputDialog::getInt + QInputDialog::getInt #else - QInputDialog::getInteger + QInputDialog::getInteger #endif - (this->parentWidget(), - tr("Slider %1").arg(name_bar), - tr("New value:"), - value, - min, - max, - step, - &ok); + (this->parentWidget(), + tr("Slider %1").arg(name_bar), + tr("New value:"), + value, + min, + max, + step, + &ok); - if (ok) - slider->setValue(i); + if (ok) + slider->setValue(i); } void CvTrackbar::update(int myvalue) { - setLabel(myvalue); + setLabel(myvalue); - *dataSlider = myvalue; - if (callback) - { - callback(myvalue); - return; - } + *dataSlider = myvalue; + if (callback) + { + callback(myvalue); + return; + } - if (callback2) - { - callback2(myvalue, userdata); - return; - } + if (callback2) + { + callback2(myvalue, userdata); + return; + } } void CvTrackbar::setLabel(int myvalue) { - QString nameNormalized = name_bar.leftJustified( 10, ' ', true ); - QString valueMaximum = QString("%1").arg(slider->maximum()); - QString str = QString("%1 (%2/%3)").arg(nameNormalized).arg(myvalue,valueMaximum.length(),10,QChar('0')).arg(valueMaximum); - label->setText(str); + QString nameNormalized = name_bar.leftJustified( 10, ' ', true ); + QString valueMaximum = QString("%1").arg(slider->maximum()); + QString str = QString("%1 (%2/%3)").arg(nameNormalized).arg(myvalue,valueMaximum.length(),10,QChar('0')).arg(valueMaximum); + label->setText(str); } @@ -1347,52 +1347,52 @@ void CvTrackbar::setLabel(int myvalue) //here CvButtonbar class CvButtonbar::CvButtonbar(QWidget* arg, QString arg2) { - type = type_CvButtonbar; - myparent = arg; - name_bar = arg2; - setObjectName(name_bar); + type = type_CvButtonbar; + myparent = arg; + name_bar = arg2; + setObjectName(name_bar); - group_button = new QButtonGroup(this); + group_button = new QButtonGroup(this); } void CvButtonbar::setLabel() { - QString nameNormalized = name_bar.leftJustified(10, ' ', true); - label->setText(nameNormalized); + QString nameNormalized = name_bar.leftJustified(10, ' ', true); + label->setText(nameNormalized); } void CvButtonbar::addButton(QString name, CvButtonCallback call, void* userdata, int button_type, int initial_button_state) { - QString button_name = name; + QString button_name = name; - if (button_name == "") - button_name = tr("button %1").arg(this->count()); + if (button_name == "") + button_name = tr("button %1").arg(this->count()); - QPointer button; + QPointer button; - if (button_type == CV_PUSH_BUTTON) - button = (QAbstractButton*) new CvPushButton(this, button_name,call, userdata); + if (button_type == CV_PUSH_BUTTON) + button = (QAbstractButton*) new CvPushButton(this, button_name,call, userdata); - if (button_type == CV_CHECKBOX) - button = (QAbstractButton*) new CvCheckBox(this, button_name,call, userdata, initial_button_state); + if (button_type == CV_CHECKBOX) + button = (QAbstractButton*) new CvCheckBox(this, button_name,call, userdata, initial_button_state); - if (button_type == CV_RADIOBOX) - { - button = (QAbstractButton*) new CvRadioButton(this, button_name,call, userdata, initial_button_state); - group_button->addButton(button); - } + if (button_type == CV_RADIOBOX) + { + button = (QAbstractButton*) new CvRadioButton(this, button_name,call, userdata, initial_button_state); + group_button->addButton(button); + } - if (button) - { - if (button_type == CV_PUSH_BUTTON) - QObject::connect(button, SIGNAL(clicked(bool)), button, SLOT(callCallBack(bool))); - else - QObject::connect(button, SIGNAL(toggled(bool)), button, SLOT(callCallBack(bool))); + if (button) + { + if (button_type == CV_PUSH_BUTTON) + QObject::connect(button, SIGNAL(clicked(bool)), button, SLOT(callCallBack(bool))); + else + QObject::connect(button, SIGNAL(toggled(bool)), button, SLOT(callCallBack(bool))); - addWidget(button, Qt::AlignCenter); - } + addWidget(button, Qt::AlignCenter); + } } @@ -1403,68 +1403,68 @@ void CvButtonbar::addButton(QString name, CvButtonCallback call, void* userdata, //buttons here CvPushButton::CvPushButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4) { - myparent = arg1; - button_name = arg2; - callback = arg3; - userdata = arg4; + myparent = arg1; + button_name = arg2; + callback = arg3; + userdata = arg4; - setObjectName(button_name); - setText(button_name); + setObjectName(button_name); + setText(button_name); - if (isChecked()) - callCallBack(true); + if (isChecked()) + callCallBack(true); } void CvPushButton::callCallBack(bool checked) { - if (callback) - callback(checked, userdata); + if (callback) + callback(checked, userdata); } CvCheckBox::CvCheckBox(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, int initial_button_state) { - myparent = arg1; - button_name = arg2; - callback = arg3; - userdata = arg4; + myparent = arg1; + button_name = arg2; + callback = arg3; + userdata = arg4; - setObjectName(button_name); - setCheckState((initial_button_state == 1 ? Qt::Checked : Qt::Unchecked)); - setText(button_name); + setObjectName(button_name); + setCheckState((initial_button_state == 1 ? Qt::Checked : Qt::Unchecked)); + setText(button_name); - if (isChecked()) - callCallBack(true); + if (isChecked()) + callCallBack(true); } void CvCheckBox::callCallBack(bool checked) { - if (callback) - callback(checked, userdata); + if (callback) + callback(checked, userdata); } CvRadioButton::CvRadioButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, int initial_button_state) { - myparent = arg1; - button_name = arg2; - callback = arg3; - userdata = arg4; + myparent = arg1; + button_name = arg2; + callback = arg3; + userdata = arg4; - setObjectName(button_name); - setChecked(initial_button_state); - setText(button_name); + setObjectName(button_name); + setChecked(initial_button_state); + setText(button_name); - if (isChecked()) - callCallBack(true); + if (isChecked()) + callCallBack(true); } void CvRadioButton::callCallBack(bool checked) { - if (callback) - callback(checked, userdata); + if (callback) + callback(checked, userdata); } @@ -1475,67 +1475,67 @@ void CvRadioButton::callCallBack(bool checked) //here CvWinProperties class CvWinProperties::CvWinProperties(QString name_paraWindow, QObject* parent) { - //setParent(parent); - type = type_CvWinProperties; - setWindowFlags(Qt::Tool); - setContentsMargins(0, 0, 0, 0); - setWindowTitle(name_paraWindow); - setObjectName(name_paraWindow); - resize(100, 50); + //setParent(parent); + type = type_CvWinProperties; + setWindowFlags(Qt::Tool); + setContentsMargins(0, 0, 0, 0); + setWindowTitle(name_paraWindow); + setObjectName(name_paraWindow); + resize(100, 50); - myLayout = new QBoxLayout(QBoxLayout::TopToBottom); - myLayout->setObjectName(QString::fromUtf8("boxLayout")); - myLayout->setContentsMargins(0, 0, 0, 0); - myLayout->setSpacing(0); - myLayout->setMargin(0); - myLayout->setSizeConstraint(QLayout::SetFixedSize); - setLayout(myLayout); + myLayout = new QBoxLayout(QBoxLayout::TopToBottom); + myLayout->setObjectName(QString::fromUtf8("boxLayout")); + myLayout->setContentsMargins(0, 0, 0, 0); + myLayout->setSpacing(0); + myLayout->setMargin(0); + myLayout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(myLayout); - hide(); + hide(); } void CvWinProperties::closeEvent(QCloseEvent* e) { - e->accept(); //intersept the close event (not sure I really need it) - //an hide event is also sent. I will intercept it and do some processing + e->accept(); //intersept the close event (not sure I really need it) + //an hide event is also sent. I will intercept it and do some processing } void CvWinProperties::showEvent(QShowEvent* event) { - //why -1,-1 ?: do this trick because the first time the code is run, - //no value pos was saved so we let Qt move the window in the middle of its parent (event ignored). - //then hide will save the last position and thus, we want to retreive it (event accepted). - QPoint mypos(-1, -1); - QSettings settings("OpenCV2", windowTitle()); - mypos = settings.value("pos", mypos).toPoint(); + //why -1,-1 ?: do this trick because the first time the code is run, + //no value pos was saved so we let Qt move the window in the middle of its parent (event ignored). + //then hide will save the last position and thus, we want to retreive it (event accepted). + QPoint mypos(-1, -1); + QSettings settings("OpenCV2", windowTitle()); + mypos = settings.value("pos", mypos).toPoint(); - if (mypos.x() >= 0) - { - move(mypos); - event->accept(); - } - else + if (mypos.x() >= 0) + { + move(mypos); + event->accept(); + } + else { - event->ignore(); - } + event->ignore(); + } } void CvWinProperties::hideEvent(QHideEvent* event) { - QSettings settings("OpenCV2", windowTitle()); - settings.setValue("pos", pos()); //there is an offset of 6 pixels (so the window's position is wrong -- why ?) - event->accept(); + QSettings settings("OpenCV2", windowTitle()); + settings.setValue("pos", pos()); //there is an offset of 6 pixels (so the window's position is wrong -- why ?) + event->accept(); } CvWinProperties::~CvWinProperties() { - //clear the setting pos - QSettings settings("OpenCV2", windowTitle()); - settings.remove("pos"); + //clear the setting pos + QSettings settings("OpenCV2", windowTitle()); + settings.remove("pos"); } @@ -1545,102 +1545,102 @@ CvWinProperties::~CvWinProperties() CvWindow::CvWindow(QString name, int arg2) { - type = type_CvWindow; - moveToThread(qApp->instance()->thread()); + type = type_CvWindow; + moveToThread(qApp->instance()->thread()); - param_flags = arg2 & 0x0000000F; - param_gui_mode = arg2 & 0x000000F0; - param_ratio_mode = arg2 & 0x00000F00; + param_flags = arg2 & 0x0000000F; + param_gui_mode = arg2 & 0x000000F0; + param_ratio_mode = arg2 & 0x00000F00; - //setAttribute(Qt::WA_DeleteOnClose); //in other case, does not release memory - setContentsMargins(0, 0, 0, 0); - setWindowTitle(name); + //setAttribute(Qt::WA_DeleteOnClose); //in other case, does not release memory + setContentsMargins(0, 0, 0, 0); + setWindowTitle(name); setObjectName(name); setFocus( Qt::PopupFocusReason ); //#1695 arrow keys are not recieved without the explicit focus - resize(400, 300); - setMinimumSize(1, 1); + resize(400, 300); + setMinimumSize(1, 1); - //1: create control panel - if (!global_control_panel) - global_control_panel = createParameterWindow(); + //1: create control panel + if (!global_control_panel) + global_control_panel = createParameterWindow(); - //2: Layouts - createBarLayout(); - createGlobalLayout(); + //2: Layouts + createBarLayout(); + createGlobalLayout(); - //3: my view + //3: my view #ifndef HAVE_QT_OPENGL if (arg2 & CV_WINDOW_OPENGL) CV_Error( CV_OpenGlNotSupported, "Library was built without OpenGL support" ); - mode_display = CV_MODE_NORMAL; + mode_display = CV_MODE_NORMAL; #else mode_display = arg2 & CV_WINDOW_OPENGL ? CV_MODE_OPENGL : CV_MODE_NORMAL; if (mode_display == CV_MODE_OPENGL) param_gui_mode = CV_GUI_NORMAL; #endif - createView(); + createView(); - //4: shortcuts and actions - //5: toolBar and statusbar - if (param_gui_mode == CV_GUI_EXPANDED) - { + //4: shortcuts and actions + //5: toolBar and statusbar + if (param_gui_mode == CV_GUI_EXPANDED) + { createActions(); createShortcuts(); - createToolBar(); - createStatusBar(); - } + createToolBar(); + createStatusBar(); + } - //Now attach everything - if (myToolBar) - myGlobalLayout->addWidget(myToolBar, Qt::AlignCenter); + //Now attach everything + if (myToolBar) + myGlobalLayout->addWidget(myToolBar, Qt::AlignCenter); - myGlobalLayout->addWidget(myView->getWidget(), Qt::AlignCenter); + myGlobalLayout->addWidget(myView->getWidget(), Qt::AlignCenter); - myGlobalLayout->addLayout(myBarLayout, Qt::AlignCenter); + myGlobalLayout->addLayout(myBarLayout, Qt::AlignCenter); - if (myStatusBar) - myGlobalLayout->addWidget(myStatusBar, Qt::AlignCenter); + if (myStatusBar) + myGlobalLayout->addWidget(myStatusBar, Qt::AlignCenter); - setLayout(myGlobalLayout); - show(); + setLayout(myGlobalLayout); + show(); } CvWindow::~CvWindow() { - if (guiMainThread) - guiMainThread->isLastWindow(); + if (guiMainThread) + guiMainThread->isLastWindow(); } void CvWindow::setMouseCallBack(CvMouseCallback callback, void* param) { - myView->setMouseCallBack(callback, param); + myView->setMouseCallBack(callback, param); } void CvWindow::writeSettings() { - //organisation and application's name - QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()); + //organisation and application's name + QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()); - settings.setValue("pos", pos()); - settings.setValue("size", size()); - settings.setValue("mode_resize" ,param_flags); - settings.setValue("mode_gui", param_gui_mode); + settings.setValue("pos", pos()); + settings.setValue("size", size()); + settings.setValue("mode_resize" ,param_flags); + settings.setValue("mode_gui", param_gui_mode); myView->writeSettings(settings); - icvSaveTrackbars(&settings); + icvSaveTrackbars(&settings); - if (global_control_panel) - { - icvSaveControlPanel(); - settings.setValue("posPanel", global_control_panel->pos()); - } + if (global_control_panel) + { + icvSaveControlPanel(); + settings.setValue("posPanel", global_control_panel->pos()); + } } @@ -1648,30 +1648,30 @@ void CvWindow::writeSettings() //TODO: load CV_GUI flag (done) and act accordingly (create win property if needed and attach trackbars) void CvWindow::readSettings() { - //organisation and application's name - QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()); + //organisation and application's name + QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()); - QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); - QSize size = settings.value("size", QSize(400, 400)).toSize(); + QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); + QSize size = settings.value("size", QSize(400, 400)).toSize(); - param_flags = settings.value("mode_resize", param_flags).toInt(); - param_gui_mode = settings.value("mode_gui", param_gui_mode).toInt(); + param_flags = settings.value("mode_resize", param_flags).toInt(); + param_gui_mode = settings.value("mode_gui", param_gui_mode).toInt(); - param_flags = settings.value("mode_resize", param_flags).toInt(); + param_flags = settings.value("mode_resize", param_flags).toInt(); - myView->readSettings(settings); + myView->readSettings(settings); - //trackbar here - icvLoadTrackbars(&settings); + //trackbar here + icvLoadTrackbars(&settings); - resize(size); - move(pos); + resize(size); + move(pos); - if (global_control_panel) - { - icvLoadControlPanel(); - global_control_panel->move(settings.value("posPanel", global_control_panel->pos()).toPoint()); - } + if (global_control_panel) + { + icvLoadControlPanel(); + global_control_panel->move(settings.value("posPanel", global_control_panel->pos()).toPoint()); + } } @@ -1687,30 +1687,30 @@ void CvWindow::setRatio(int flags) } -int CvWindow::getPropWindow() -{ - return param_flags; +int CvWindow::getPropWindow() +{ + return param_flags; } void CvWindow::setPropWindow(int flags) { if (param_flags == flags) //nothing to do - return; + return; switch(flags) { case CV_WINDOW_NORMAL: - myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); - param_flags = flags; + myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); + param_flags = flags; - break; + break; case CV_WINDOW_AUTOSIZE: - myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize); - param_flags = flags; + myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize); + param_flags = flags; - break; + break; default: ; @@ -1722,36 +1722,36 @@ void CvWindow::toggleFullScreen(int flags) { if (isFullScreen() && flags == CV_WINDOW_NORMAL) { - showTools(); - showNormal(); - return; + showTools(); + showNormal(); + return; } if (!isFullScreen() && flags == CV_WINDOW_FULLSCREEN) { - hideTools(); - showFullScreen(); - return; + hideTools(); + showFullScreen(); + return; } } void CvWindow::updateImage(void* arr) { - myView->updateImage(arr); + myView->updateImage(arr); } void CvWindow::displayInfo(QString text, int delayms) { - myView->startDisplayInfo(text, delayms); + myView->startDisplayInfo(text, delayms); } void CvWindow::displayStatusBar(QString text, int delayms) { if (myStatusBar) - myStatusBar->showMessage(text, delayms); + myStatusBar->showMessage(text, delayms); } @@ -1763,74 +1763,74 @@ void CvWindow::enablePropertiesButton() CvButtonbar* CvWindow::createButtonBar(QString name_bar) { - QPointer t = new CvButtonbar(global_control_panel, name_bar); - t->setAlignment(Qt::AlignHCenter); + QPointer t = new CvButtonbar(global_control_panel, name_bar); + t->setAlignment(Qt::AlignHCenter); - QPointer myLayout = global_control_panel->myLayout; + QPointer myLayout = global_control_panel->myLayout; - myLayout->insertLayout(myLayout->count(), t); + myLayout->insertLayout(myLayout->count(), t); - return t; + return t; } void CvWindow::addSlider(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback on_change) { - QPointer t = new CvTrackbar(w, name, value, count, on_change); - t->setAlignment(Qt::AlignHCenter); + QPointer t = new CvTrackbar(w, name, value, count, on_change); + t->setAlignment(Qt::AlignHCenter); - QPointer myLayout; + QPointer myLayout; - if (w) - { - myLayout = w->myBarLayout; - } - else - { - myLayout = global_control_panel->myLayout; + if (w) + { + myLayout = w->myBarLayout; + } + else + { + myLayout = global_control_panel->myLayout; - //if first one, enable control panel - if (myLayout->count() == 0) - guiMainThread->enablePropertiesButtonEachWindow(); - } + //if first one, enable control panel + if (myLayout->count() == 0) + guiMainThread->enablePropertiesButtonEachWindow(); + } - myLayout->insertLayout(myLayout->count(), t); + myLayout->insertLayout(myLayout->count(), t); } void CvWindow::addSlider2(CvWindow* w, QString name, int* value, int count, CvTrackbarCallback2 on_change, void* userdata) { - QPointer t = new CvTrackbar(w, name, value, count, on_change, userdata); - t->setAlignment(Qt::AlignHCenter); + QPointer t = new CvTrackbar(w, name, value, count, on_change, userdata); + t->setAlignment(Qt::AlignHCenter); - QPointer myLayout; + QPointer myLayout; - if (w) - { - myLayout = w->myBarLayout; - } - else - { - myLayout = global_control_panel->myLayout; + if (w) + { + myLayout = w->myBarLayout; + } + else + { + myLayout = global_control_panel->myLayout; - //if first one, enable control panel - if (myLayout->count() == 0) - guiMainThread->enablePropertiesButtonEachWindow(); - } + //if first one, enable control panel + if (myLayout->count() == 0) + guiMainThread->enablePropertiesButtonEachWindow(); + } - myLayout->insertLayout(myLayout->count(), t); + myLayout->insertLayout(myLayout->count(), t); } void CvWindow::setOpenGlDrawCallback(CvOpenGlDrawCallback callback, void* userdata) { - myView->setOpenGlDrawCallback(callback, userdata); + myView->setOpenGlDrawCallback(callback, userdata); } void CvWindow::setOpenGlCleanCallback(CvOpenGlCleanCallback callback, void* userdata) { - myView->setOpenGlCleanCallback(callback, userdata); + myView->setOpenGlCleanCallback(callback, userdata); } @@ -1861,27 +1861,27 @@ void CvWindow::setViewportSize(QSize size) void CvWindow::createBarLayout() { - myBarLayout = new QBoxLayout(QBoxLayout::TopToBottom); - myBarLayout->setObjectName(QString::fromUtf8("barLayout")); - myBarLayout->setContentsMargins(0, 0, 0, 0); - myBarLayout->setSpacing(0); - myBarLayout->setMargin(0); + myBarLayout = new QBoxLayout(QBoxLayout::TopToBottom); + myBarLayout->setObjectName(QString::fromUtf8("barLayout")); + myBarLayout->setContentsMargins(0, 0, 0, 0); + myBarLayout->setSpacing(0); + myBarLayout->setMargin(0); } void CvWindow::createGlobalLayout() { - myGlobalLayout = new QBoxLayout(QBoxLayout::TopToBottom); - myGlobalLayout->setObjectName(QString::fromUtf8("boxLayout")); - myGlobalLayout->setContentsMargins(0, 0, 0, 0); - myGlobalLayout->setSpacing(0); - myGlobalLayout->setMargin(0); - setMinimumSize(1, 1); + myGlobalLayout = new QBoxLayout(QBoxLayout::TopToBottom); + myGlobalLayout->setObjectName(QString::fromUtf8("boxLayout")); + myGlobalLayout->setContentsMargins(0, 0, 0, 0); + myGlobalLayout->setSpacing(0); + myGlobalLayout->setMargin(0); + setMinimumSize(1, 1); - if (param_flags == CV_WINDOW_AUTOSIZE) - myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize); - else if (param_flags == CV_WINDOW_NORMAL) - myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); + if (param_flags == CV_WINDOW_AUTOSIZE) + myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize); + else if (param_flags == CV_WINDOW_NORMAL) + myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); } @@ -1889,180 +1889,180 @@ void CvWindow::createView() { #ifdef HAVE_QT_OPENGL if (isOpenGl()) - myView = new OpenGlViewPort(this); + myView = new OpenGlViewPort(this); else #endif - myView = new DefaultViewPort(this, param_ratio_mode); + myView = new DefaultViewPort(this, param_ratio_mode); } void CvWindow::createActions() { - vect_QActions.resize(10); + vect_QActions.resize(10); QWidget* view = myView->getWidget(); - //if the shortcuts are changed in window_QT.h, we need to update the tooltip manually - vect_QActions[0] = new QAction(QIcon(":/left-icon"), "Panning left (CTRL+arrowLEFT)", this); - vect_QActions[0]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[0], SIGNAL(triggered()), view, SLOT(siftWindowOnLeft())); + //if the shortcuts are changed in window_QT.h, we need to update the tooltip manually + vect_QActions[0] = new QAction(QIcon(":/left-icon"), "Panning left (CTRL+arrowLEFT)", this); + vect_QActions[0]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[0], SIGNAL(triggered()), view, SLOT(siftWindowOnLeft())); - vect_QActions[1] = new QAction(QIcon(":/right-icon"), "Panning right (CTRL+arrowRIGHT)", this); - vect_QActions[1]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[1], SIGNAL(triggered()), view, SLOT(siftWindowOnRight())); + vect_QActions[1] = new QAction(QIcon(":/right-icon"), "Panning right (CTRL+arrowRIGHT)", this); + vect_QActions[1]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[1], SIGNAL(triggered()), view, SLOT(siftWindowOnRight())); - vect_QActions[2] = new QAction(QIcon(":/up-icon"), "Panning up (CTRL+arrowUP)", this); - vect_QActions[2]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[2], SIGNAL(triggered()), view, SLOT(siftWindowOnUp())); + vect_QActions[2] = new QAction(QIcon(":/up-icon"), "Panning up (CTRL+arrowUP)", this); + vect_QActions[2]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[2], SIGNAL(triggered()), view, SLOT(siftWindowOnUp())); - vect_QActions[3] = new QAction(QIcon(":/down-icon"), "Panning down (CTRL+arrowDOWN)", this); - vect_QActions[3]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[3], SIGNAL(triggered()), view, SLOT(siftWindowOnDown()) ); + vect_QActions[3] = new QAction(QIcon(":/down-icon"), "Panning down (CTRL+arrowDOWN)", this); + vect_QActions[3]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[3], SIGNAL(triggered()), view, SLOT(siftWindowOnDown()) ); - vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"), "Zoom x1 (CTRL+P)", this); - vect_QActions[4]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[4], SIGNAL(triggered()), view, SLOT(resetZoom())); + vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"), "Zoom x1 (CTRL+P)", this); + vect_QActions[4]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[4], SIGNAL(triggered()), view, SLOT(resetZoom())); - vect_QActions[5] = new QAction(QIcon(":/imgRegion-icon"), tr("Zoom x%1 (see label) (CTRL+X)").arg(threshold_zoom_img_region), this); - vect_QActions[5]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[5], SIGNAL(triggered()), view, SLOT(imgRegion())); + vect_QActions[5] = new QAction(QIcon(":/imgRegion-icon"), tr("Zoom x%1 (see label) (CTRL+X)").arg(threshold_zoom_img_region), this); + vect_QActions[5]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[5], SIGNAL(triggered()), view, SLOT(imgRegion())); - vect_QActions[6] = new QAction(QIcon(":/zoom_in-icon"), "Zoom in (CTRL++)", this); - vect_QActions[6]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[6], SIGNAL(triggered()), view, SLOT(ZoomIn())); + vect_QActions[6] = new QAction(QIcon(":/zoom_in-icon"), "Zoom in (CTRL++)", this); + vect_QActions[6]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[6], SIGNAL(triggered()), view, SLOT(ZoomIn())); - vect_QActions[7] = new QAction(QIcon(":/zoom_out-icon"), "Zoom out (CTRL+-)", this); - vect_QActions[7]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[7], SIGNAL(triggered()), view, SLOT(ZoomOut())); + vect_QActions[7] = new QAction(QIcon(":/zoom_out-icon"), "Zoom out (CTRL+-)", this); + vect_QActions[7]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[7], SIGNAL(triggered()), view, SLOT(ZoomOut())); - vect_QActions[8] = new QAction(QIcon(":/save-icon"), "Save current image (CTRL+S)", this); - vect_QActions[8]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[8], SIGNAL(triggered()), view, SLOT(saveView())); + vect_QActions[8] = new QAction(QIcon(":/save-icon"), "Save current image (CTRL+S)", this); + vect_QActions[8]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[8], SIGNAL(triggered()), view, SLOT(saveView())); - vect_QActions[9] = new QAction(QIcon(":/properties-icon"), "Display properties window (CTRL+P)", this); - vect_QActions[9]->setIconVisibleInMenu(true); - QObject::connect(vect_QActions[9], SIGNAL(triggered()), this, SLOT(displayPropertiesWin())); + vect_QActions[9] = new QAction(QIcon(":/properties-icon"), "Display properties window (CTRL+P)", this); + vect_QActions[9]->setIconVisibleInMenu(true); + QObject::connect(vect_QActions[9], SIGNAL(triggered()), this, SLOT(displayPropertiesWin())); - if (global_control_panel->myLayout->count() == 0) - vect_QActions[9]->setDisabled(true); + if (global_control_panel->myLayout->count() == 0) + vect_QActions[9]->setDisabled(true); } void CvWindow::createShortcuts() { - vect_QShortcuts.resize(10); + vect_QShortcuts.resize(10); QWidget* view = myView->getWidget(); - vect_QShortcuts[0] = new QShortcut(shortcut_panning_left, this); - QObject::connect(vect_QShortcuts[0], SIGNAL(activated()), view, SLOT(siftWindowOnLeft())); + vect_QShortcuts[0] = new QShortcut(shortcut_panning_left, this); + QObject::connect(vect_QShortcuts[0], SIGNAL(activated()), view, SLOT(siftWindowOnLeft())); - vect_QShortcuts[1] = new QShortcut(shortcut_panning_right, this); - QObject::connect(vect_QShortcuts[1], SIGNAL(activated()), view, SLOT(siftWindowOnRight())); + vect_QShortcuts[1] = new QShortcut(shortcut_panning_right, this); + QObject::connect(vect_QShortcuts[1], SIGNAL(activated()), view, SLOT(siftWindowOnRight())); - vect_QShortcuts[2] = new QShortcut(shortcut_panning_up, this); - QObject::connect(vect_QShortcuts[2], SIGNAL(activated()), view, SLOT(siftWindowOnUp())); + vect_QShortcuts[2] = new QShortcut(shortcut_panning_up, this); + QObject::connect(vect_QShortcuts[2], SIGNAL(activated()), view, SLOT(siftWindowOnUp())); - vect_QShortcuts[3] = new QShortcut(shortcut_panning_down, this); - QObject::connect(vect_QShortcuts[3], SIGNAL(activated()), view, SLOT(siftWindowOnDown())); + vect_QShortcuts[3] = new QShortcut(shortcut_panning_down, this); + QObject::connect(vect_QShortcuts[3], SIGNAL(activated()), view, SLOT(siftWindowOnDown())); - vect_QShortcuts[4] = new QShortcut(shortcut_zoom_normal, this); - QObject::connect(vect_QShortcuts[4], SIGNAL(activated()), view, SLOT(resetZoom())); + vect_QShortcuts[4] = new QShortcut(shortcut_zoom_normal, this); + QObject::connect(vect_QShortcuts[4], SIGNAL(activated()), view, SLOT(resetZoom())); - vect_QShortcuts[5] = new QShortcut(shortcut_zoom_imgRegion, this); - QObject::connect(vect_QShortcuts[5], SIGNAL(activated()), view, SLOT(imgRegion())); + vect_QShortcuts[5] = new QShortcut(shortcut_zoom_imgRegion, this); + QObject::connect(vect_QShortcuts[5], SIGNAL(activated()), view, SLOT(imgRegion())); - vect_QShortcuts[6] = new QShortcut(shortcut_zoom_in, this); - QObject::connect(vect_QShortcuts[6], SIGNAL(activated()), view, SLOT(ZoomIn())); + vect_QShortcuts[6] = new QShortcut(shortcut_zoom_in, this); + QObject::connect(vect_QShortcuts[6], SIGNAL(activated()), view, SLOT(ZoomIn())); - vect_QShortcuts[7] = new QShortcut(shortcut_zoom_out, this); - QObject::connect(vect_QShortcuts[7], SIGNAL(activated()), view, SLOT(ZoomOut())); + vect_QShortcuts[7] = new QShortcut(shortcut_zoom_out, this); + QObject::connect(vect_QShortcuts[7], SIGNAL(activated()), view, SLOT(ZoomOut())); - vect_QShortcuts[8] = new QShortcut(shortcut_save_img, this); - QObject::connect(vect_QShortcuts[8], SIGNAL(activated()), view, SLOT(saveView())); + vect_QShortcuts[8] = new QShortcut(shortcut_save_img, this); + QObject::connect(vect_QShortcuts[8], SIGNAL(activated()), view, SLOT(saveView())); - vect_QShortcuts[9] = new QShortcut(shortcut_properties_win, this); - QObject::connect(vect_QShortcuts[9], SIGNAL(activated()), this, SLOT(displayPropertiesWin())); + vect_QShortcuts[9] = new QShortcut(shortcut_properties_win, this); + QObject::connect(vect_QShortcuts[9], SIGNAL(activated()), this, SLOT(displayPropertiesWin())); } void CvWindow::createToolBar() { - myToolBar = new QToolBar(this); - myToolBar->setFloatable(false); //is not a window - myToolBar->setFixedHeight(28); - myToolBar->setMinimumWidth(1); + myToolBar = new QToolBar(this); + myToolBar->setFloatable(false); //is not a window + myToolBar->setFixedHeight(28); + myToolBar->setMinimumWidth(1); - foreach (QAction *a, vect_QActions) - myToolBar->addAction(a); + foreach (QAction *a, vect_QActions) + myToolBar->addAction(a); } void CvWindow::createStatusBar() { - myStatusBar = new QStatusBar(this); - myStatusBar->setSizeGripEnabled(false); - myStatusBar->setFixedHeight(20); - myStatusBar->setMinimumWidth(1); - myStatusBar_msg = new QLabel; + myStatusBar = new QStatusBar(this); + myStatusBar->setSizeGripEnabled(false); + myStatusBar->setFixedHeight(20); + myStatusBar->setMinimumWidth(1); + myStatusBar_msg = new QLabel; - //I comment this because if we change the style, myview (the picture) - //will not be the correct size anymore (will lost 2 pixel because of the borders) + //I comment this because if we change the style, myview (the picture) + //will not be the correct size anymore (will lost 2 pixel because of the borders) - //myStatusBar_msg->setFrameStyle(QFrame::Raised); + //myStatusBar_msg->setFrameStyle(QFrame::Raised); - myStatusBar_msg->setAlignment(Qt::AlignHCenter); - myStatusBar->addWidget(myStatusBar_msg); + myStatusBar_msg->setAlignment(Qt::AlignHCenter); + myStatusBar->addWidget(myStatusBar_msg); } void CvWindow::hideTools() { - if (myToolBar) - myToolBar->hide(); + if (myToolBar) + myToolBar->hide(); - if (myStatusBar) - myStatusBar->hide(); + if (myStatusBar) + myStatusBar->hide(); - if (global_control_panel) - global_control_panel->hide(); + if (global_control_panel) + global_control_panel->hide(); } void CvWindow::showTools() { - if (myToolBar) - myToolBar->show(); + if (myToolBar) + myToolBar->show(); - if (myStatusBar) - myStatusBar->show(); + if (myStatusBar) + myStatusBar->show(); } CvWinProperties* CvWindow::createParameterWindow() { - QString name_paraWindow = QFileInfo(QApplication::applicationFilePath()).fileName() + " settings"; + QString name_paraWindow = QFileInfo(QApplication::applicationFilePath()).fileName() + " settings"; - CvWinProperties* result = new CvWinProperties(name_paraWindow, guiMainThread); + CvWinProperties* result = new CvWinProperties(name_paraWindow, guiMainThread); - return result; + return result; } void CvWindow::displayPropertiesWin() { - if (global_control_panel->isHidden()) - global_control_panel->show(); - else - global_control_panel->hide(); + if (global_control_panel->isHidden()) + global_control_panel->show(); + else + global_control_panel->hide(); } //Need more test here ! void CvWindow::keyPressEvent(QKeyEvent *event) { - //see http://doc.trolltech.com/4.6/qt.html#Key-enum - int key = event->key(); + //see http://doc.trolltech.com/4.6/qt.html#Key-enum + int key = event->key(); Qt::Key qtkey = static_cast(key); char asciiCode = QTest::keyToAscii(qtkey); @@ -2071,187 +2071,187 @@ void CvWindow::keyPressEvent(QKeyEvent *event) else key = event->nativeVirtualKey(); //same codes as returned by GTK-based backend - //control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions + //control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions if (event->modifiers() != Qt::ControlModifier) { - mutexKey.lock(); - last_key = key; - mutexKey.unlock(); - key_pressed.wakeAll(); - //event->accept(); - } + mutexKey.lock(); + last_key = key; + mutexKey.unlock(); + key_pressed.wakeAll(); + //event->accept(); + } - QWidget::keyPressEvent(event); + QWidget::keyPressEvent(event); } void CvWindow::icvLoadControlPanel() { - QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName() + " control panel"); - + QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName() + " control panel"); + int size = settings.beginReadArray("bars"); - if (size == global_control_panel->myLayout->layout()->count()) + if (size == global_control_panel->myLayout->layout()->count()) { - for (int i = 0; i < size; ++i) + for (int i = 0; i < size; ++i) { - CvBar* t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i); - settings.setArrayIndex(i); - if (t->type == type_CvTrackbar) - { - if (t->name_bar == settings.value("namebar").toString()) - { - ((CvTrackbar*)t)->slider->setValue(settings.value("valuebar").toInt()); - } - } - if (t->type == type_CvButtonbar) - { - int subsize = settings.beginReadArray(QString("buttonbar")+i); + CvBar* t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i); + settings.setArrayIndex(i); + if (t->type == type_CvTrackbar) + { + if (t->name_bar == settings.value("namebar").toString()) + { + ((CvTrackbar*)t)->slider->setValue(settings.value("valuebar").toInt()); + } + } + if (t->type == type_CvButtonbar) + { + int subsize = settings.beginReadArray(QString("buttonbar")+i); + + if ( subsize == ((CvButtonbar*)t)->layout()->count() ) + icvLoadButtonbar((CvButtonbar*)t,&settings); - if ( subsize == ((CvButtonbar*)t)->layout()->count() ) - icvLoadButtonbar((CvButtonbar*)t,&settings); - - settings.endArray(); - } - } + settings.endArray(); + } + } } - settings.endArray(); + settings.endArray(); } void CvWindow::icvSaveControlPanel() { - QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()+" control panel"); + QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()+" control panel"); - settings.beginWriteArray("bars"); + settings.beginWriteArray("bars"); - for (int i = 0; i < global_control_panel->myLayout->layout()->count(); ++i) + for (int i = 0; i < global_control_panel->myLayout->layout()->count(); ++i) { - CvBar* t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i); - settings.setArrayIndex(i); - if (t->type == type_CvTrackbar) - { - settings.setValue("namebar", QString(t->name_bar)); - settings.setValue("valuebar",((CvTrackbar*)t)->slider->value()); - } - if (t->type == type_CvButtonbar) - { - settings.beginWriteArray(QString("buttonbar")+i); - icvSaveButtonbar((CvButtonbar*)t,&settings); - settings.endArray(); - } - } + CvBar* t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i); + settings.setArrayIndex(i); + if (t->type == type_CvTrackbar) + { + settings.setValue("namebar", QString(t->name_bar)); + settings.setValue("valuebar",((CvTrackbar*)t)->slider->value()); + } + if (t->type == type_CvButtonbar) + { + settings.beginWriteArray(QString("buttonbar")+i); + icvSaveButtonbar((CvButtonbar*)t,&settings); + settings.endArray(); + } + } - settings.endArray(); + settings.endArray(); } void CvWindow::icvSaveButtonbar(CvButtonbar* b, QSettings* settings) { - for (int i = 0, count = b->layout()->count(); i < count; ++i) + for (int i = 0, count = b->layout()->count(); i < count; ++i) { - settings->setArrayIndex(i); + settings->setArrayIndex(i); - QWidget* temp = (QWidget*) b->layout()->itemAt(i)->widget(); + QWidget* temp = (QWidget*) b->layout()->itemAt(i)->widget(); QString myclass(QLatin1String(temp->metaObject()->className())); - if (myclass == "CvPushButton") - { - CvPushButton* button = (CvPushButton*) temp; - settings->setValue("namebutton", button->text()); - settings->setValue("valuebutton", int(button->isChecked())); - } - else if (myclass == "CvCheckBox") - { - CvCheckBox* button = (CvCheckBox*) temp; - settings->setValue("namebutton", button->text()); - settings->setValue("valuebutton", int(button->isChecked())); - } - else if (myclass == "CvRadioButton") - { - CvRadioButton* button = (CvRadioButton*) temp; - settings->setValue("namebutton", button->text()); - settings->setValue("valuebutton", int(button->isChecked())); - } - } + if (myclass == "CvPushButton") + { + CvPushButton* button = (CvPushButton*) temp; + settings->setValue("namebutton", button->text()); + settings->setValue("valuebutton", int(button->isChecked())); + } + else if (myclass == "CvCheckBox") + { + CvCheckBox* button = (CvCheckBox*) temp; + settings->setValue("namebutton", button->text()); + settings->setValue("valuebutton", int(button->isChecked())); + } + else if (myclass == "CvRadioButton") + { + CvRadioButton* button = (CvRadioButton*) temp; + settings->setValue("namebutton", button->text()); + settings->setValue("valuebutton", int(button->isChecked())); + } + } } void CvWindow::icvLoadButtonbar(CvButtonbar* b, QSettings* settings) { - for (int i = 0, count = b->layout()->count(); i < count; ++i) - { - settings->setArrayIndex(i); + for (int i = 0, count = b->layout()->count(); i < count; ++i) + { + settings->setArrayIndex(i); - QWidget* temp = (QWidget*) b->layout()->itemAt(i)->widget(); - QString myclass(QLatin1String(temp->metaObject()->className())); + QWidget* temp = (QWidget*) b->layout()->itemAt(i)->widget(); + QString myclass(QLatin1String(temp->metaObject()->className())); - if (myclass == "CvPushButton") - { - CvPushButton* button = (CvPushButton*) temp; + if (myclass == "CvPushButton") + { + CvPushButton* button = (CvPushButton*) temp; - if (button->text() == settings->value("namebutton").toString()) - button->setChecked(settings->value("valuebutton").toInt()); - } - else if (myclass == "CvCheckBox") - { - CvCheckBox* button = (CvCheckBox*) temp; + if (button->text() == settings->value("namebutton").toString()) + button->setChecked(settings->value("valuebutton").toInt()); + } + else if (myclass == "CvCheckBox") + { + CvCheckBox* button = (CvCheckBox*) temp; - if (button->text() == settings->value("namebutton").toString()) - button->setChecked(settings->value("valuebutton").toInt()); - } - else if (myclass == "CvRadioButton") - { - CvRadioButton* button = (CvRadioButton*) temp; + if (button->text() == settings->value("namebutton").toString()) + button->setChecked(settings->value("valuebutton").toInt()); + } + else if (myclass == "CvRadioButton") + { + CvRadioButton* button = (CvRadioButton*) temp; - if (button->text() == settings->value("namebutton").toString()) - button->setChecked(settings->value("valuebutton").toInt()); - } + if (button->text() == settings->value("namebutton").toString()) + button->setChecked(settings->value("valuebutton").toInt()); + } - } + } } void CvWindow::icvLoadTrackbars(QSettings* settings) { - int size = settings->beginReadArray("trackbars"); + int size = settings->beginReadArray("trackbars"); - //trackbar are saved in the same order, so no need to use icvFindTrackbarByName + //trackbar are saved in the same order, so no need to use icvFindTrackbarByName - if (myBarLayout->layout()->count() == size) //if not the same number, the window saved and loaded is not the same (nb trackbar not equal) + if (myBarLayout->layout()->count() == size) //if not the same number, the window saved and loaded is not the same (nb trackbar not equal) { - for (int i = 0; i < size; ++i) - { - settings->setArrayIndex(i); + for (int i = 0; i < size; ++i) + { + settings->setArrayIndex(i); - CvTrackbar* t = (CvTrackbar*) myBarLayout->layout()->itemAt(i); + CvTrackbar* t = (CvTrackbar*) myBarLayout->layout()->itemAt(i); - if (t->name_bar == settings->value("name").toString()) - t->slider->setValue(settings->value("value").toInt()); + if (t->name_bar == settings->value("name").toString()) + t->slider->setValue(settings->value("value").toInt()); - } + } } - settings->endArray(); + settings->endArray(); } void CvWindow::icvSaveTrackbars(QSettings* settings) { - settings->beginWriteArray("trackbars"); + settings->beginWriteArray("trackbars"); - for (int i = 0; i < myBarLayout->layout()->count(); ++i) + for (int i = 0; i < myBarLayout->layout()->count(); ++i) { - settings->setArrayIndex(i); + settings->setArrayIndex(i); - CvTrackbar* t = (CvTrackbar*) myBarLayout->layout()->itemAt(i); + CvTrackbar* t = (CvTrackbar*) myBarLayout->layout()->itemAt(i); - settings->setValue("name", t->name_bar); - settings->setValue("value", t->slider->value()); - } + settings->setValue("name", t->name_bar); + settings->setValue("value", t->slider->value()); + } - settings->endArray(); + settings->endArray(); } @@ -2261,44 +2261,44 @@ void CvWindow::icvSaveTrackbars(QSettings* settings) DefaultViewPort::DefaultViewPort(CvWindow* arg, int arg2) : QGraphicsView(arg), image2Draw_mat(0) { - centralWidget = arg; + centralWidget = arg; param_keepRatio = arg2; - setContentsMargins(0, 0, 0, 0); - setMinimumSize(1, 1); + setContentsMargins(0, 0, 0, 0); + setMinimumSize(1, 1); setAlignment(Qt::AlignHCenter); - setObjectName(QString::fromUtf8("graphicsView")); + setObjectName(QString::fromUtf8("graphicsView")); - timerDisplay = new QTimer(this); - timerDisplay->setSingleShot(true); - connect(timerDisplay, SIGNAL(timeout()), this, SLOT(stopDisplayInfo())); + timerDisplay = new QTimer(this); + timerDisplay->setSingleShot(true); + connect(timerDisplay, SIGNAL(timeout()), this, SLOT(stopDisplayInfo())); - drawInfo = false; - positionGrabbing = QPointF(0, 0); - positionCorners = QRect(0, 0, size().width(), size().height()); + drawInfo = false; + positionGrabbing = QPointF(0, 0); + positionCorners = QRect(0, 0, size().width(), size().height()); - on_mouse = 0; + on_mouse = 0; on_mouse_param = 0; - mouseCoordinate = QPoint(-1, -1); + mouseCoordinate = QPoint(-1, -1); - //no border - setStyleSheet( "QGraphicsView { border-style: none; }" ); + //no border + setStyleSheet( "QGraphicsView { border-style: none; }" ); image2Draw_mat = cvCreateMat(viewport()->height(), viewport()->width(), CV_8UC3); cvZero(image2Draw_mat); nbChannelOriginImage = 0; - setInteractive(false); - setMouseTracking(true); //receive mouse event everytime + setInteractive(false); + setMouseTracking(true); //receive mouse event everytime } DefaultViewPort::~DefaultViewPort() { - if (image2Draw_mat) - cvReleaseMat(&image2Draw_mat); + if (image2Draw_mat) + cvReleaseMat(&image2Draw_mat); } @@ -2310,9 +2310,9 @@ QWidget* DefaultViewPort::getWidget() void DefaultViewPort::setMouseCallBack(CvMouseCallback m, void* param) { - on_mouse = m; + on_mouse = m; - on_mouse_param = param; + on_mouse_param = param; } void DefaultViewPort::writeSettings(QSettings& settings) @@ -2354,63 +2354,63 @@ double DefaultViewPort::getRatio() void DefaultViewPort::setRatio(int flags) { if (getRatio() == flags) //nothing to do - return; + return; - //if valid flags - if (flags == CV_WINDOW_FREERATIO || flags == CV_WINDOW_KEEPRATIO) + //if valid flags + if (flags == CV_WINDOW_FREERATIO || flags == CV_WINDOW_KEEPRATIO) { centralWidget->param_ratio_mode = flags; - param_keepRatio = flags; - updateGeometry(); - viewport()->update(); + param_keepRatio = flags; + updateGeometry(); + viewport()->update(); } } void DefaultViewPort::updateImage(const CvArr* arr) { - CV_Assert(arr); + CV_Assert(arr); - CvMat* mat, stub; - int origin = 0; + CvMat* mat, stub; + int origin = 0; - if (CV_IS_IMAGE_HDR(arr)) - origin = ((IplImage*)arr)->origin; + if (CV_IS_IMAGE_HDR(arr)) + origin = ((IplImage*)arr)->origin; - mat = cvGetMat(arr, &stub); + mat = cvGetMat(arr, &stub); - if (!image2Draw_mat || !CV_ARE_SIZES_EQ(image2Draw_mat, mat)) - { + if (!image2Draw_mat || !CV_ARE_SIZES_EQ(image2Draw_mat, mat)) + { if (image2Draw_mat) - cvReleaseMat(&image2Draw_mat); + cvReleaseMat(&image2Draw_mat); - //the image in ipl (to do a deep copy with cvCvtColor) - image2Draw_mat = cvCreateMat(mat->rows, mat->cols, CV_8UC3); - image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows, image2Draw_mat->step, QImage::Format_RGB888); + //the image in ipl (to do a deep copy with cvCvtColor) + image2Draw_mat = cvCreateMat(mat->rows, mat->cols, CV_8UC3); + image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows, image2Draw_mat->step, QImage::Format_RGB888); - //use to compute mouse coordinate, I need to update the ratio here and in resizeEvent - ratioX = width() / float(image2Draw_mat->cols); - ratioY = height() / float(image2Draw_mat->rows); + //use to compute mouse coordinate, I need to update the ratio here and in resizeEvent + ratioX = width() / float(image2Draw_mat->cols); + ratioY = height() / float(image2Draw_mat->rows); - updateGeometry(); - } + updateGeometry(); + } - nbChannelOriginImage = cvGetElemType(mat); + nbChannelOriginImage = cvGetElemType(mat); - cvConvertImage(mat, image2Draw_mat, (origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB); + cvConvertImage(mat, image2Draw_mat, (origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB); - viewport()->update(); + viewport()->update(); } void DefaultViewPort::startDisplayInfo(QString text, int delayms) { - if (timerDisplay->isActive()) - stopDisplayInfo(); + if (timerDisplay->isActive()) + stopDisplayInfo(); - infoText = text; - if (delayms > 0) timerDisplay->start(delayms); - drawInfo = true; + infoText = text; + if (delayms > 0) timerDisplay->start(delayms); + drawInfo = true; } @@ -2441,120 +2441,120 @@ void DefaultViewPort::updateGl() //Note: move 2 percent of the window void DefaultViewPort::siftWindowOnLeft() { - float delta = 2 * width() / (100.0 * param_matrixWorld.m11()); - moveView(QPointF(delta, 0)); + float delta = 2 * width() / (100.0 * param_matrixWorld.m11()); + moveView(QPointF(delta, 0)); } //Note: move 2 percent of the window void DefaultViewPort::siftWindowOnRight() { - float delta = -2 * width() / (100.0 * param_matrixWorld.m11()); - moveView(QPointF(delta, 0)); + float delta = -2 * width() / (100.0 * param_matrixWorld.m11()); + moveView(QPointF(delta, 0)); } //Note: move 2 percent of the window void DefaultViewPort::siftWindowOnUp() { - float delta = 2 * height() / (100.0 * param_matrixWorld.m11()); - moveView(QPointF(0, delta)); + float delta = 2 * height() / (100.0 * param_matrixWorld.m11()); + moveView(QPointF(0, delta)); } //Note: move 2 percent of the window void DefaultViewPort::siftWindowOnDown() { - float delta = -2 * height() / (100.0 * param_matrixWorld.m11()); - moveView(QPointF(0, delta)); + float delta = -2 * height() / (100.0 * param_matrixWorld.m11()); + moveView(QPointF(0, delta)); } void DefaultViewPort::imgRegion() { - scaleView((threshold_zoom_img_region / param_matrixWorld.m11() - 1) * 5, QPointF(size().width() / 2, size().height() / 2)); + scaleView((threshold_zoom_img_region / param_matrixWorld.m11() - 1) * 5, QPointF(size().width() / 2, size().height() / 2)); } void DefaultViewPort::resetZoom() { - param_matrixWorld.reset(); - controlImagePosition(); + param_matrixWorld.reset(); + controlImagePosition(); } void DefaultViewPort::ZoomIn() { - scaleView(0.5, QPointF(size().width() / 2, size().height() / 2)); + scaleView(0.5, QPointF(size().width() / 2, size().height() / 2)); } void DefaultViewPort::ZoomOut() { - scaleView(-0.5, QPointF(size().width() / 2, size().height() / 2)); + scaleView(-0.5, QPointF(size().width() / 2, size().height() / 2)); } //can save as JPG, JPEG, BMP, PNG void DefaultViewPort::saveView() { - QDate date_d = QDate::currentDate(); - QString date_s = date_d.toString("dd.MM.yyyy"); + QDate date_d = QDate::currentDate(); + QString date_s = date_d.toString("dd.MM.yyyy"); QString name_s = centralWidget->windowTitle() + "_screenshot_" + date_s; - QString fileName = QFileDialog::getSaveFileName(this, tr("Save File %1").arg(name_s), name_s + ".png", tr("Images (*.png *.jpg *.bmp *.jpeg)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File %1").arg(name_s), name_s + ".png", tr("Images (*.png *.jpg *.bmp *.jpeg)")); + + if (!fileName.isEmpty()) //save the picture + { + QString extension = fileName.right(3); - if (!fileName.isEmpty()) //save the picture - { - QString extension = fileName.right(3); + // (no need anymore) create the image resized to receive the 'screenshot' + // image2Draw_qt_resized = QImage(viewport()->width(), viewport()->height(),QImage::Format_RGB888); - // (no need anymore) create the image resized to receive the 'screenshot' - // image2Draw_qt_resized = QImage(viewport()->width(), viewport()->height(),QImage::Format_RGB888); - - QPainter saveimage(&image2Draw_qt_resized); - this->render(&saveimage); + QPainter saveimage(&image2Draw_qt_resized); + this->render(&saveimage); - // Save it.. - if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0) - { - image2Draw_qt_resized.save(fileName, "PNG"); - return; - } + // Save it.. + if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0) + { + image2Draw_qt_resized.save(fileName, "PNG"); + return; + } - if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0) - { - image2Draw_qt_resized.save(fileName, "JPG"); - return; - } + if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0) + { + image2Draw_qt_resized.save(fileName, "JPG"); + return; + } - if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0) - { - image2Draw_qt_resized.save(fileName, "BMP"); - return; - } + if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0) + { + image2Draw_qt_resized.save(fileName, "BMP"); + return; + } - if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0) - { - image2Draw_qt_resized.save(fileName, "JPEG"); - return; - } + if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0) + { + image2Draw_qt_resized.save(fileName, "JPEG"); + return; + } - CV_Error(CV_StsNullPtr, "file extension not recognized, please choose between JPG, JPEG, BMP or PNG"); - } + CV_Error(CV_StsNullPtr, "file extension not recognized, please choose between JPG, JPEG, BMP or PNG"); + } } void DefaultViewPort::contextMenuEvent(QContextMenuEvent* event) { - if (centralWidget->vect_QActions.size() > 0) - { - QMenu menu(this); + if (centralWidget->vect_QActions.size() > 0) + { + QMenu menu(this); - foreach (QAction *a, centralWidget->vect_QActions) - menu.addAction(a); + foreach (QAction *a, centralWidget->vect_QActions) + menu.addAction(a); - menu.exec(event->globalPos()); - } + menu.exec(event->globalPos()); + } } @@ -2565,248 +2565,248 @@ void DefaultViewPort::resizeEvent(QResizeEvent* event) //use to compute mouse coordinate, I need to update the ratio here and in resizeEvent ratioX = width() / float(image2Draw_mat->cols); ratioY = height() / float(image2Draw_mat->rows); - + if (param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio { - QSize newSize = QSize(image2Draw_mat->cols, image2Draw_mat->rows); - newSize.scale(event->size(), Qt::KeepAspectRatio); + QSize newSize = QSize(image2Draw_mat->cols, image2Draw_mat->rows); + newSize.scale(event->size(), Qt::KeepAspectRatio); - //imageWidth/imageHeight = newWidth/newHeight +/- epsilon - //ratioX = ratioY +/- epsilon - //||ratioX - ratioY|| = epsilon - if (fabs(ratioX - ratioY) * 100 > ratioX) //avoid infinity loop / epsilon = 1% of ratioX - { - resize(newSize); + //imageWidth/imageHeight = newWidth/newHeight +/- epsilon + //ratioX = ratioY +/- epsilon + //||ratioX - ratioY|| = epsilon + if (fabs(ratioX - ratioY) * 100 > ratioX) //avoid infinity loop / epsilon = 1% of ratioX + { + resize(newSize); - //move to the middle - //newSize get the delta offset to place the picture in the middle of its parent - newSize = (event->size() - newSize) / 2; + //move to the middle + //newSize get the delta offset to place the picture in the middle of its parent + newSize = (event->size() - newSize) / 2; - //if the toolbar is displayed, avoid drawing myview on top of it - if (centralWidget->myToolBar) - if(!centralWidget->myToolBar->isHidden()) - newSize += QSize(0, centralWidget->myToolBar->height()); + //if the toolbar is displayed, avoid drawing myview on top of it + if (centralWidget->myToolBar) + if(!centralWidget->myToolBar->isHidden()) + newSize += QSize(0, centralWidget->myToolBar->height()); - move(newSize.width(), newSize.height()); - } + move(newSize.width(), newSize.height()); + } } - return QGraphicsView::resizeEvent(event); + return QGraphicsView::resizeEvent(event); } void DefaultViewPort::wheelEvent(QWheelEvent* event) { - scaleView(event->delta() / 240.0, event->pos()); - viewport()->update(); + scaleView(event->delta() / 240.0, event->pos()); + viewport()->update(); } void DefaultViewPort::mousePressEvent(QMouseEvent* event) { - int cv_event = -1, flags = 0; - QPoint pt = event->pos(); + int cv_event = -1, flags = 0; + QPoint pt = event->pos(); - //icvmouseHandler: pass parameters for cv_event, flags - icvmouseHandler(event, mouse_down, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + //icvmouseHandler: pass parameters for cv_event, flags + icvmouseHandler(event, mouse_down, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - if (param_matrixWorld.m11()>1) - { - setCursor(Qt::ClosedHandCursor); - positionGrabbing = event->pos(); - } + if (param_matrixWorld.m11()>1) + { + setCursor(Qt::ClosedHandCursor); + positionGrabbing = event->pos(); + } - QWidget::mousePressEvent(event); + QWidget::mousePressEvent(event); } void DefaultViewPort::mouseReleaseEvent(QMouseEvent* event) { - int cv_event = -1, flags = 0; - QPoint pt = event->pos(); + int cv_event = -1, flags = 0; + QPoint pt = event->pos(); - //icvmouseHandler: pass parameters for cv_event, flags - icvmouseHandler(event, mouse_up, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + //icvmouseHandler: pass parameters for cv_event, flags + icvmouseHandler(event, mouse_up, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - if (param_matrixWorld.m11()>1) - setCursor(Qt::OpenHandCursor); + if (param_matrixWorld.m11()>1) + setCursor(Qt::OpenHandCursor); - QWidget::mouseReleaseEvent(event); + QWidget::mouseReleaseEvent(event); } void DefaultViewPort::mouseDoubleClickEvent(QMouseEvent* event) { - int cv_event = -1, flags = 0; - QPoint pt = event->pos(); + int cv_event = -1, flags = 0; + QPoint pt = event->pos(); - //icvmouseHandler: pass parameters for cv_event, flags - icvmouseHandler(event, mouse_dbclick, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + //icvmouseHandler: pass parameters for cv_event, flags + icvmouseHandler(event, mouse_dbclick, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - QWidget::mouseDoubleClickEvent(event); + QWidget::mouseDoubleClickEvent(event); } void DefaultViewPort::mouseMoveEvent(QMouseEvent* event) { - int cv_event = CV_EVENT_MOUSEMOVE, flags = 0; - QPoint pt = event->pos(); + int cv_event = CV_EVENT_MOUSEMOVE, flags = 0; + QPoint pt = event->pos(); - //icvmouseHandler: pass parameters for cv_event, flags - icvmouseHandler(event, mouse_move, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + //icvmouseHandler: pass parameters for cv_event, flags + icvmouseHandler(event, mouse_move, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - if (param_matrixWorld.m11() > 1 && event->buttons() == Qt::LeftButton) - { - QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11(); - positionGrabbing = event->pos(); - moveView(dxy); - } + if (param_matrixWorld.m11() > 1 && event->buttons() == Qt::LeftButton) + { + QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11(); + positionGrabbing = event->pos(); + moveView(dxy); + } - //I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp) - //the status bar will only be repaint when a click occurs. - if (centralWidget->myStatusBar) - viewport()->update(); + //I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp) + //the status bar will only be repaint when a click occurs. + if (centralWidget->myStatusBar) + viewport()->update(); - QWidget::mouseMoveEvent(event); + QWidget::mouseMoveEvent(event); } void DefaultViewPort::paintEvent(QPaintEvent* event) { - QPainter myPainter(viewport()); - myPainter.setWorldTransform(param_matrixWorld); + QPainter myPainter(viewport()); + myPainter.setWorldTransform(param_matrixWorld); - draw2D(&myPainter); + draw2D(&myPainter); - //Now disable matrixWorld for overlay display - myPainter.setWorldMatrixEnabled(false); + //Now disable matrixWorld for overlay display + myPainter.setWorldMatrixEnabled(false); - //in mode zoom/panning - if (param_matrixWorld.m11() > 1) - { - if (param_matrixWorld.m11() >= threshold_zoom_img_region) - { - if (centralWidget->param_flags == CV_WINDOW_NORMAL) - startDisplayInfo("WARNING: The values displayed are the resized image's values. If you want the original image's values, use CV_WINDOW_AUTOSIZE", 1000); + //in mode zoom/panning + if (param_matrixWorld.m11() > 1) + { + if (param_matrixWorld.m11() >= threshold_zoom_img_region) + { + if (centralWidget->param_flags == CV_WINDOW_NORMAL) + startDisplayInfo("WARNING: The values displayed are the resized image's values. If you want the original image's values, use CV_WINDOW_AUTOSIZE", 1000); - drawImgRegion(&myPainter); - } + drawImgRegion(&myPainter); + } - drawViewOverview(&myPainter); - } + drawViewOverview(&myPainter); + } - //for information overlay - if (drawInfo) - drawInstructions(&myPainter); + //for information overlay + if (drawInfo) + drawInstructions(&myPainter); - //for statusbar - if (centralWidget->myStatusBar) - drawStatusBar(); + //for statusbar + if (centralWidget->myStatusBar) + drawStatusBar(); - QGraphicsView::paintEvent(event); + QGraphicsView::paintEvent(event); } void DefaultViewPort::stopDisplayInfo() { - timerDisplay->stop(); - drawInfo = false; + timerDisplay->stop(); + drawInfo = false; } inline bool DefaultViewPort::isSameSize(IplImage* img1, IplImage* img2) { - return img1->width == img2->width && img1->height == img2->height; + return img1->width == img2->width && img1->height == img2->height; } void DefaultViewPort::controlImagePosition() { - qreal left, top, right, bottom; - - //after check top-left, bottom right corner to avoid getting "out" during zoom/panning - param_matrixWorld.map(0,0,&left,&top); - - if (left > 0) - { - param_matrixWorld.translate(-left,0); - left = 0; - } - if (top > 0) - { - param_matrixWorld.translate(0,-top); - top = 0; - } - //------- - - QSize sizeImage = size(); - param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom); - if (right < sizeImage.width()) - { - param_matrixWorld.translate(sizeImage.width()-right,0); - right = sizeImage.width(); - } - if (bottom < sizeImage.height()) - { - param_matrixWorld.translate(0,sizeImage.height()-bottom); - bottom = sizeImage.height(); - } - - //save corner position - positionCorners.setTopLeft(QPoint(left,top)); - positionCorners.setBottomRight(QPoint(right,bottom)); - //save also the inv matrix - matrixWorld_inv = param_matrixWorld.inverted(); - - //viewport()->update(); + qreal left, top, right, bottom; + + //after check top-left, bottom right corner to avoid getting "out" during zoom/panning + param_matrixWorld.map(0,0,&left,&top); + + if (left > 0) + { + param_matrixWorld.translate(-left,0); + left = 0; + } + if (top > 0) + { + param_matrixWorld.translate(0,-top); + top = 0; + } + //------- + + QSize sizeImage = size(); + param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom); + if (right < sizeImage.width()) + { + param_matrixWorld.translate(sizeImage.width()-right,0); + right = sizeImage.width(); + } + if (bottom < sizeImage.height()) + { + param_matrixWorld.translate(0,sizeImage.height()-bottom); + bottom = sizeImage.height(); + } + + //save corner position + positionCorners.setTopLeft(QPoint(left,top)); + positionCorners.setBottomRight(QPoint(right,bottom)); + //save also the inv matrix + matrixWorld_inv = param_matrixWorld.inverted(); + + //viewport()->update(); } void DefaultViewPort::moveView(QPointF delta) { - param_matrixWorld.translate(delta.x(),delta.y()); - controlImagePosition(); - viewport()->update(); + param_matrixWorld.translate(delta.x(),delta.y()); + controlImagePosition(); + viewport()->update(); } //factor is -0.5 (zoom out) or 0.5 (zoom in) void DefaultViewPort::scaleView(qreal factor,QPointF center) { - factor/=5;//-0.1 <-> 0.1 - factor+=1;//0.9 <-> 1.1 + factor/=5;//-0.1 <-> 0.1 + factor+=1;//0.9 <-> 1.1 - //limit zoom out --- - if (param_matrixWorld.m11()==1 && factor < 1) - return; + //limit zoom out --- + if (param_matrixWorld.m11()==1 && factor < 1) + return; - if (param_matrixWorld.m11()*factor<1) - factor = 1/param_matrixWorld.m11(); + if (param_matrixWorld.m11()*factor<1) + factor = 1/param_matrixWorld.m11(); - //limit zoom int --- - if (param_matrixWorld.m11()>100 && factor > 1) - return; + //limit zoom int --- + if (param_matrixWorld.m11()>100 && factor > 1) + return; - //inverse the transform - int a, b; - matrixWorld_inv.map(center.x(),center.y(),&a,&b); + //inverse the transform + int a, b; + matrixWorld_inv.map(center.x(),center.y(),&a,&b); - param_matrixWorld.translate(a-factor*a,b-factor*b); - param_matrixWorld.scale(factor,factor); + param_matrixWorld.translate(a-factor*a,b-factor*b); + param_matrixWorld.scale(factor,factor); - controlImagePosition(); + controlImagePosition(); - //display new zoom - if (centralWidget->myStatusBar) - centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000); + //display new zoom + if (centralWidget->myStatusBar) + centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000); - if (param_matrixWorld.m11()>1) - setCursor(Qt::OpenHandCursor); - else - unsetCursor(); + if (param_matrixWorld.m11()>1) + setCursor(Qt::OpenHandCursor); + else + unsetCursor(); } @@ -2815,7 +2815,7 @@ void DefaultViewPort::icvmouseHandler(QMouseEvent *event, type_mouse_event categ { Qt::KeyboardModifiers modifiers = event->modifiers(); Qt::MouseButtons buttons = event->buttons(); - + flags = 0; if(modifiers & Qt::ShiftModifier) flags |= CV_EVENT_FLAG_SHIFTKEY; @@ -2853,208 +2853,208 @@ void DefaultViewPort::icvmouseHandler(QMouseEvent *event, type_mouse_event categ void DefaultViewPort::icvmouseProcessing(QPointF pt, int cv_event, int flags) { - //to convert mouse coordinate - qreal pfx, pfy; - matrixWorld_inv.map(pt.x(),pt.y(),&pfx,&pfy); - - mouseCoordinate.rx()=floor(pfx/ratioX); - mouseCoordinate.ry()=floor(pfy/ratioY); + //to convert mouse coordinate + qreal pfx, pfy; + matrixWorld_inv.map(pt.x(),pt.y(),&pfx,&pfy); + + mouseCoordinate.rx()=floor(pfx/ratioX); + mouseCoordinate.ry()=floor(pfy/ratioY); - if (on_mouse) - on_mouse( cv_event, mouseCoordinate.x(), + if (on_mouse) + on_mouse( cv_event, mouseCoordinate.x(), mouseCoordinate.y(), flags, on_mouse_param ); } QSize DefaultViewPort::sizeHint() const { - if(image2Draw_mat) - return QSize(image2Draw_mat->cols, image2Draw_mat->rows); - else - return QGraphicsView::sizeHint(); + if(image2Draw_mat) + return QSize(image2Draw_mat->cols, image2Draw_mat->rows); + else + return QGraphicsView::sizeHint(); } void DefaultViewPort::draw2D(QPainter *painter) { - image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows,image2Draw_mat->step,QImage::Format_RGB888); - image2Draw_qt_resized = image2Draw_qt.scaled(viewport()->width(),viewport()->height(),Qt::IgnoreAspectRatio,Qt::FastTransformation);//Qt::SmoothTransformation); - painter->drawImage(0,0,image2Draw_qt_resized); + image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows,image2Draw_mat->step,QImage::Format_RGB888); + image2Draw_qt_resized = image2Draw_qt.scaled(viewport()->width(),viewport()->height(),Qt::IgnoreAspectRatio,Qt::FastTransformation);//Qt::SmoothTransformation); + painter->drawImage(0,0,image2Draw_qt_resized); } //only if CV_8UC1 or CV_8UC3 void DefaultViewPort::drawStatusBar() { - if (nbChannelOriginImage!=CV_8UC1 && nbChannelOriginImage!=CV_8UC3) - return; - - if (mouseCoordinate.x()>=0 && - mouseCoordinate.y()>=0 && - mouseCoordinate.x()=0 && mouseCoordinate.y()>=0) - { - QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate); - - if (nbChannelOriginImage==CV_8UC3 ) - { - centralWidget->myStatusBar_msg->setText(tr("(x=%1, y=%2) ~ ") - .arg(mouseCoordinate.x()) - .arg(mouseCoordinate.y())+ - tr("R:%3 ").arg(qRed(rgbValue))+//.arg(value.val[0])+ - tr("G:%4 ").arg(qGreen(rgbValue))+//.arg(value.val[1])+ - tr("B:%5").arg(qBlue(rgbValue))//.arg(value.val[2]) - ); - } - - if (nbChannelOriginImage==CV_8UC1) - { - //all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed - centralWidget->myStatusBar_msg->setText(tr("(x=%1, y=%2) ~ ") - .arg(mouseCoordinate.x()) - .arg(mouseCoordinate.y())+ - tr("L:%3 ").arg(qRed(rgbValue)) - ); - } - } + if (nbChannelOriginImage!=CV_8UC1 && nbChannelOriginImage!=CV_8UC3) + return; + + if (mouseCoordinate.x()>=0 && + mouseCoordinate.y()>=0 && + mouseCoordinate.x()=0 && mouseCoordinate.y()>=0) + { + QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate); + + if (nbChannelOriginImage==CV_8UC3 ) + { + centralWidget->myStatusBar_msg->setText(tr("(x=%1, y=%2) ~ ") + .arg(mouseCoordinate.x()) + .arg(mouseCoordinate.y())+ + tr("R:%3 ").arg(qRed(rgbValue))+//.arg(value.val[0])+ + tr("G:%4 ").arg(qGreen(rgbValue))+//.arg(value.val[1])+ + tr("B:%5").arg(qBlue(rgbValue))//.arg(value.val[2]) + ); + } + + if (nbChannelOriginImage==CV_8UC1) + { + //all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed + centralWidget->myStatusBar_msg->setText(tr("(x=%1, y=%2) ~ ") + .arg(mouseCoordinate.x()) + .arg(mouseCoordinate.y())+ + tr("L:%3 ").arg(qRed(rgbValue)) + ); + } + } } //accept only CV_8UC1 and CV_8UC8 image for now void DefaultViewPort::drawImgRegion(QPainter *painter) { - if (nbChannelOriginImage!=CV_8UC1 && nbChannelOriginImage!=CV_8UC3) - return; - - qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11(); - offsetX = offsetX - floor(offsetX); - qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11(); - offsetY = offsetY - floor(offsetY); - - QSize view = size(); - QVarLengthArray linesX; - for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() ) - linesX.append(QLineF(x, 0, x, view.height())); + if (nbChannelOriginImage!=CV_8UC1 && nbChannelOriginImage!=CV_8UC3) + return; - QVarLengthArray linesY; - for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() ) - linesY.append(QLineF(0, y, view.width(), y)); + qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11(); + offsetX = offsetX - floor(offsetX); + qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11(); + offsetY = offsetY - floor(offsetY); + QSize view = size(); + QVarLengthArray linesX; + for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() ) + linesX.append(QLineF(x, 0, x, view.height())); - QFont f = painter->font(); - int original_font_size = f.pointSize(); - //change font size - //f.setPointSize(4+(param_matrixWorld.m11()-threshold_zoom_img_region)/5); - f.setPixelSize(10+(param_matrixWorld.m11()-threshold_zoom_img_region)/5); - painter->setFont(f); - QString val; - QRgb rgbValue; + QVarLengthArray linesY; + for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() ) + linesY.append(QLineF(0, y, view.width(), y)); - QPointF point1;//sorry, I do not know how to name it - QPointF point2;//idem - for (int j=-1;jfont(); + int original_font_size = f.pointSize(); + //change font size + //f.setPointSize(4+(param_matrixWorld.m11()-threshold_zoom_img_region)/5); + f.setPixelSize(10+(param_matrixWorld.m11()-threshold_zoom_img_region)/5); + painter->setFont(f); + QString val; + QRgb rgbValue; - matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry()); + QPointF point1;//sorry, I do not know how to name it + QPointF point2;//idem - point2.rx()= (long) (point2.x() + 0.5); - point2.ry()= (long) (point2.y() + 0.5); - - if (point2.x() >= 0 && point2.y() >= 0) - rgbValue = image2Draw_qt_resized.pixel(QPoint(point2.x(),point2.y())); - else - rgbValue = qRgb(0,0,0); + for (int j=-1;jsetPen(QPen(Qt::black, 1)); - painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/2), - Qt::AlignCenter, val); - */ + matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry()); - val = tr("%1").arg(qRed(rgbValue)); - painter->setPen(QPen(Qt::red, 1)); - painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3), - Qt::AlignCenter, val); + point2.rx()= (long) (point2.x() + 0.5); + point2.ry()= (long) (point2.y() + 0.5); - val = tr("%1").arg(qGreen(rgbValue)); - painter->setPen(QPen(Qt::green, 1)); - painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3), - Qt::AlignCenter, val); + if (point2.x() >= 0 && point2.y() >= 0) + rgbValue = image2Draw_qt_resized.pixel(QPoint(point2.x(),point2.y())); + else + rgbValue = qRgb(0,0,0); - val = tr("%1").arg(qBlue(rgbValue)); - painter->setPen(QPen(Qt::blue, 1)); - painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3), - Qt::AlignCenter, val); + if (nbChannelOriginImage==CV_8UC3) + { + //for debug + /* + val = tr("%1 %2").arg(point2.x()).arg(point2.y()); + painter->setPen(QPen(Qt::black, 1)); + painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/2), + Qt::AlignCenter, val); + */ + + val = tr("%1").arg(qRed(rgbValue)); + painter->setPen(QPen(Qt::red, 1)); + painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3), + Qt::AlignCenter, val); + + val = tr("%1").arg(qGreen(rgbValue)); + painter->setPen(QPen(Qt::green, 1)); + painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3), + Qt::AlignCenter, val); + + val = tr("%1").arg(qBlue(rgbValue)); + painter->setPen(QPen(Qt::blue, 1)); + painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3), + Qt::AlignCenter, val); - } + } - if (nbChannelOriginImage==CV_8UC1) - { + if (nbChannelOriginImage==CV_8UC1) + { - val = tr("%1").arg(qRed(rgbValue)); - painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()), - Qt::AlignCenter, val); - } - } + val = tr("%1").arg(qRed(rgbValue)); + painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()), + Qt::AlignCenter, val); + } + } - painter->setPen(QPen(Qt::black, 1)); - painter->drawLines(linesX.data(), linesX.size()); - painter->drawLines(linesY.data(), linesY.size()); + painter->setPen(QPen(Qt::black, 1)); + painter->drawLines(linesX.data(), linesX.size()); + painter->drawLines(linesY.data(), linesY.size()); - //restore font size - f.setPointSize(original_font_size); - painter->setFont(f); + //restore font size + f.setPointSize(original_font_size); + painter->setFont(f); } void DefaultViewPort::drawViewOverview(QPainter *painter) { - QSize viewSize = size(); - viewSize.scale ( 100, 100,Qt::KeepAspectRatio ); + QSize viewSize = size(); + viewSize.scale ( 100, 100,Qt::KeepAspectRatio ); - const int margin = 5; + const int margin = 5; - //draw the image's location - painter->setBrush(QColor(0, 0, 0, 127)); - painter->setPen(Qt::darkGreen); - painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height())); + //draw the image's location + painter->setBrush(QColor(0, 0, 0, 127)); + painter->setPen(Qt::darkGreen); + painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height())); - //daw the view's location inside the image - qreal ratioSize = 1/param_matrixWorld.m11(); - qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height()); - painter->setPen(Qt::darkBlue); - painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin, - -positionCorners.top()*ratioSize*ratioWindow, - (viewSize.width()-1)*ratioSize, - (viewSize.height()-1)*ratioSize) - ); + //daw the view's location inside the image + qreal ratioSize = 1/param_matrixWorld.m11(); + qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height()); + painter->setPen(Qt::darkBlue); + painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin, + -positionCorners.top()*ratioSize*ratioWindow, + (viewSize.width()-1)*ratioSize, + (viewSize.height()-1)*ratioSize) + ); } void DefaultViewPort::drawInstructions(QPainter *painter) { - QFontMetrics metrics = QFontMetrics(font()); - int border = qMax(4, metrics.leading()); + QFontMetrics metrics = QFontMetrics(font()); + int border = qMax(4, metrics.leading()); - QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125), - Qt::AlignCenter | Qt::TextWordWrap, infoText); - painter->setRenderHint(QPainter::TextAntialiasing); - painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), - QColor(0, 0, 0, 127)); - painter->setPen(Qt::white); - painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), - QColor(0, 0, 0, 127)); + QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125), + Qt::AlignCenter | Qt::TextWordWrap, infoText); + painter->setRenderHint(QPainter::TextAntialiasing); + painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), + QColor(0, 0, 0, 127)); + painter->setPen(Qt::white); + painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), + QColor(0, 0, 0, 127)); - painter->drawText((width() - rect.width())/2, border, - rect.width(), rect.height(), - Qt::AlignCenter | Qt::TextWordWrap, infoText); + painter->drawText((width() - rect.width())/2, border, + rect.width(), rect.height(), + Qt::AlignCenter | Qt::TextWordWrap, infoText); } @@ -3202,7 +3202,7 @@ public: void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const; bool isGlContextInitialized() const; - + PFNGLGENBUFFERSPROC glGenBuffersExt; PFNGLDELETEBUFFERSPROC glDeleteBuffersExt; @@ -3422,100 +3422,100 @@ void OpenGlViewPort::paintGL() void OpenGlViewPort::mousePressEvent(QMouseEvent* event) { - int cv_event = -1, flags = 0; - QPoint pt = event->pos(); + int cv_event = -1, flags = 0; + QPoint pt = event->pos(); - icvmouseHandler(event, mouse_down, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + icvmouseHandler(event, mouse_down, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - QGLWidget::mousePressEvent(event); + QGLWidget::mousePressEvent(event); } void OpenGlViewPort::mouseReleaseEvent(QMouseEvent* event) { - int cv_event = -1, flags = 0; - QPoint pt = event->pos(); + int cv_event = -1, flags = 0; + QPoint pt = event->pos(); - icvmouseHandler(event, mouse_up, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + icvmouseHandler(event, mouse_up, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - QGLWidget::mouseReleaseEvent(event); + QGLWidget::mouseReleaseEvent(event); } void OpenGlViewPort::mouseDoubleClickEvent(QMouseEvent* event) { - int cv_event = -1, flags = 0; - QPoint pt = event->pos(); + int cv_event = -1, flags = 0; + QPoint pt = event->pos(); - icvmouseHandler(event, mouse_dbclick, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + icvmouseHandler(event, mouse_dbclick, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - QGLWidget::mouseDoubleClickEvent(event); + QGLWidget::mouseDoubleClickEvent(event); } void OpenGlViewPort::mouseMoveEvent(QMouseEvent* event) { - int cv_event = CV_EVENT_MOUSEMOVE, flags = 0; - QPoint pt = event->pos(); + int cv_event = CV_EVENT_MOUSEMOVE, flags = 0; + QPoint pt = event->pos(); - //icvmouseHandler: pass parameters for cv_event, flags - icvmouseHandler(event, mouse_move, cv_event, flags); - icvmouseProcessing(QPointF(pt), cv_event, flags); + //icvmouseHandler: pass parameters for cv_event, flags + icvmouseHandler(event, mouse_move, cv_event, flags); + icvmouseProcessing(QPointF(pt), cv_event, flags); - QGLWidget::mouseMoveEvent(event); + QGLWidget::mouseMoveEvent(event); } void OpenGlViewPort::icvmouseHandler(QMouseEvent* event, type_mouse_event category, int& cv_event, int& flags) { - Qt::KeyboardModifiers modifiers = event->modifiers(); + Qt::KeyboardModifiers modifiers = event->modifiers(); Qt::MouseButtons buttons = event->buttons(); - + flags = 0; if (modifiers & Qt::ShiftModifier) - flags |= CV_EVENT_FLAG_SHIFTKEY; - if (modifiers & Qt::ControlModifier) - flags |= CV_EVENT_FLAG_CTRLKEY; - if (modifiers & Qt::AltModifier) - flags |= CV_EVENT_FLAG_ALTKEY; + flags |= CV_EVENT_FLAG_SHIFTKEY; + if (modifiers & Qt::ControlModifier) + flags |= CV_EVENT_FLAG_CTRLKEY; + if (modifiers & Qt::AltModifier) + flags |= CV_EVENT_FLAG_ALTKEY; if (buttons & Qt::LeftButton) - flags |= CV_EVENT_FLAG_LBUTTON; - if (buttons & Qt::RightButton) - flags |= CV_EVENT_FLAG_RBUTTON; + flags |= CV_EVENT_FLAG_LBUTTON; + if (buttons & Qt::RightButton) + flags |= CV_EVENT_FLAG_RBUTTON; if (buttons & Qt::MidButton) - flags |= CV_EVENT_FLAG_MBUTTON; + flags |= CV_EVENT_FLAG_MBUTTON; cv_event = CV_EVENT_MOUSEMOVE; - switch (event->button()) - { - case Qt::LeftButton: - cv_event = tableMouseButtons[category][0]; - flags |= CV_EVENT_FLAG_LBUTTON; - break; - - case Qt::RightButton: - cv_event = tableMouseButtons[category][1]; - flags |= CV_EVENT_FLAG_RBUTTON; - break; - - case Qt::MidButton: - cv_event = tableMouseButtons[category][2]; - flags |= CV_EVENT_FLAG_MBUTTON; - break; - - default: + switch (event->button()) + { + case Qt::LeftButton: + cv_event = tableMouseButtons[category][0]; + flags |= CV_EVENT_FLAG_LBUTTON; + break; + + case Qt::RightButton: + cv_event = tableMouseButtons[category][1]; + flags |= CV_EVENT_FLAG_RBUTTON; + break; + + case Qt::MidButton: + cv_event = tableMouseButtons[category][2]; + flags |= CV_EVENT_FLAG_MBUTTON; + break; + + default: ; - } + } } void OpenGlViewPort::icvmouseProcessing(QPointF pt, int cv_event, int flags) { - if (mouseCallback) - mouseCallback(cv_event, pt.x(), pt.y(), flags, mouseData); + if (mouseCallback) + mouseCallback(cv_event, pt.x(), pt.y(), flags, mouseData); } diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 33cc72a..3f92562 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -1372,17 +1372,17 @@ cvDestroyAllWindows( void ) CV_UNLOCK_MUTEX(); } -CvSize icvCalcOptimalWindowSize( CvWindow * window, CvSize new_image_size){ - CvSize window_size; - GtkWidget * toplevel = gtk_widget_get_toplevel( window->frame ); - gdk_drawable_get_size( GDK_DRAWABLE(toplevel->window), - &window_size.width, &window_size.height ); +// CvSize icvCalcOptimalWindowSize( CvWindow * window, CvSize new_image_size){ +// CvSize window_size; +// GtkWidget * toplevel = gtk_widget_get_toplevel( window->frame ); +// gdk_drawable_get_size( GDK_DRAWABLE(toplevel->window), +// &window_size.width, &window_size.height ); - window_size.width = window_size.width + new_image_size.width - window->widget->allocation.width; - window_size.height = window_size.height + new_image_size.height - window->widget->allocation.height; +// window_size.width = window_size.width + new_image_size.width - window->widget->allocation.width; +// window_size.height = window_size.height + new_image_size.height - window->widget->allocation.height; - return window_size; -} +// return window_size; +// } CV_IMPL void cvShowImage( const char* name, const CvArr* arr ) diff --git a/modules/imgproc/perf/perf_precomp.hpp b/modules/imgproc/perf/perf_precomp.hpp index bc6d2be..3653f1f 100644 --- a/modules/imgproc/perf/perf_precomp.hpp +++ b/modules/imgproc/perf/perf_precomp.hpp @@ -5,7 +5,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/imgproc/src/_list.h b/modules/imgproc/src/_list.h index a19f7e2..29acdb4 100644 --- a/modules/imgproc/src/_list.h +++ b/modules/imgproc/src/_list.h @@ -98,6 +98,7 @@ typedef struct _list _CVLIST; _LIST_INLINE CVPOS prefix##get_tail_pos_##type(_CVLIST*);\ _LIST_INLINE type* prefix##get_next_##type(CVPOS*);\ _LIST_INLINE type* prefix##get_prev_##type(CVPOS*);\ + _LIST_INLINE int prefix##is_pos_##type(CVPOS pos);\ /* Modification functions*/\ _LIST_INLINE void prefix##clear_list_##type(_CVLIST*);\ _LIST_INLINE CVPOS prefix##add_head_##type(_CVLIST*, type*);\ @@ -151,8 +152,8 @@ typedef struct _list _CVLIST; }\ element->m_next = ((element_type*)l->m_head_free.m_pos);\ l->m_head_free.m_pos = element; - - + + /*#define GET_FIRST_FREE(l) ((ELEMENT_##type*)(l->m_head_free.m_pos))*/ #define IMPLEMENT_LIST(type, prefix)\ diff --git a/modules/imgproc/src/floodfill.cpp b/modules/imgproc/src/floodfill.cpp index c77640b..e970a31 100644 --- a/modules/imgproc/src/floodfill.cpp +++ b/modules/imgproc/src/floodfill.cpp @@ -233,7 +233,7 @@ typedef DiffC3 Diff32sC3; typedef DiffC1 Diff32fC1; typedef DiffC3 Diff32fC3; -cv::Vec3i& operator += (cv::Vec3i& a, const cv::Vec3b& b) +static cv::Vec3i& operator += (cv::Vec3i& a, const cv::Vec3b& b) { a[0] += b[0]; a[1] += b[1]; @@ -440,7 +440,7 @@ cvFloodFill( CvArr* arr, CvPoint seed_point, { cv::Ptr tempMask; cv::AutoBuffer buffer; - + if( comp ) memset( comp, 0, sizeof(*comp) ); @@ -491,16 +491,16 @@ cvFloodFill( CvArr* arr, CvPoint seed_point, { /*int elem_size = CV_ELEM_SIZE(type); const uchar* seed_ptr = img->data.ptr + img->step*seed_point.y + elem_size*seed_point.x; - + // check if the new value is different from the current value at the seed point. // if they are exactly the same, use the generic version with mask to avoid infinite loops. for( i = 0; i < elem_size; i++ ) if( seed_ptr[i] != ((uchar*)nv_buf)[i] ) break; - + if( i == elem_size ) return;*/ - + if( type == CV_8UC1 ) icvFloodFill_CnIR(img->data.ptr, img->step, size, seed_point, nv_buf.b[0], comp, flags, buffer, buffer_size); @@ -632,7 +632,7 @@ int cv::floodFill( InputOutputArray _image, Point seedPoint, } int cv::floodFill( InputOutputArray _image, InputOutputArray _mask, - Point seedPoint, Scalar newVal, Rect* rect, + Point seedPoint, Scalar newVal, Rect* rect, Scalar loDiff, Scalar upDiff, int flags ) { CvConnectedComp ccomp; diff --git a/modules/imgproc/src/grabcut.cpp b/modules/imgproc/src/grabcut.cpp index 27a535c..98dbf74 100644 --- a/modules/imgproc/src/grabcut.cpp +++ b/modules/imgproc/src/grabcut.cpp @@ -230,7 +230,7 @@ void GMM::calcInverseCovAndDeterm( int ci ) Calculate beta - parameter of GrabCut algorithm. beta = 1/(2*avg(sqr(||color[i] - color[j]||))) */ -double calcBeta( const Mat& img ) +static double calcBeta( const Mat& img ) { double beta = 0; for( int y = 0; y < img.rows; y++ ) @@ -272,7 +272,7 @@ double calcBeta( const Mat& img ) Calculate weights of noterminal vertices of graph. beta and gamma - parameters of GrabCut algorithm. */ -void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& uprightW, double beta, double gamma ) +static void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& uprightW, double beta, double gamma ) { const double gammaDivSqrt2 = gamma / std::sqrt(2.0f); leftW.create( img.rows, img.cols, CV_64FC1 ); @@ -319,7 +319,7 @@ void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& upri /* Check size, type and element values of mask matrix. */ -void checkMask( const Mat& img, const Mat& mask ) +static void checkMask( const Mat& img, const Mat& mask ) { if( mask.empty() ) CV_Error( CV_StsBadArg, "mask is empty" ); @@ -342,7 +342,7 @@ void checkMask( const Mat& img, const Mat& mask ) /* Initialize mask using rectangular. */ -void initMaskWithRect( Mat& mask, Size imgSize, Rect rect ) +static void initMaskWithRect( Mat& mask, Size imgSize, Rect rect ) { mask.create( imgSize, CV_8UC1 ); mask.setTo( GC_BGD ); @@ -358,7 +358,7 @@ void initMaskWithRect( Mat& mask, Size imgSize, Rect rect ) /* Initialize GMM background and foreground models using kmeans algorithm. */ -void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM ) +static void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM ) { const int kMeansItCount = 10; const int kMeansType = KMEANS_PP_CENTERS; @@ -398,7 +398,7 @@ void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM ) /* Assign GMMs components for each pixel. */ -void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, Mat& compIdxs ) +static void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, Mat& compIdxs ) { Point p; for( p.y = 0; p.y < img.rows; p.y++ ) @@ -415,7 +415,7 @@ void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, c /* Learn GMMs parameters. */ -void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGMM, GMM& fgdGMM ) +static void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGMM, GMM& fgdGMM ) { bgdGMM.initLearning(); fgdGMM.initLearning(); @@ -443,7 +443,7 @@ void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGM /* Construct GCGraph */ -void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, double lambda, +static void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, double lambda, const Mat& leftW, const Mat& upleftW, const Mat& upW, const Mat& uprightW, GCGraph& graph ) { @@ -506,7 +506,7 @@ void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const /* Estimate segmentation using MaxFlow algorithm */ -void estimateSegmentation( GCGraph& graph, Mat& mask ) +static void estimateSegmentation( GCGraph& graph, Mat& mask ) { graph.maxFlow(); Point p; @@ -533,7 +533,7 @@ void cv::grabCut( InputArray _img, InputOutputArray _mask, Rect rect, Mat& mask = _mask.getMatRef(); Mat& bgdModel = _bgdModel.getMatRef(); Mat& fgdModel = _fgdModel.getMatRef(); - + if( img.empty() ) CV_Error( CV_StsBadArg, "image is empty" ); if( img.type() != CV_8UC3 ) diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index a2ada39..462f712 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -114,7 +114,7 @@ icvHoughLinesStandard( const CvMat* img, float rho, float theta, _tabCos.allocate(numangle); int *accum = _accum, *sort_buf = _sort_buf; float *tabSin = _tabSin, *tabCos = _tabCos; - + memset( accum, 0, sizeof(accum[0]) * (numangle+2) * (numrho+2) ); for( ang = 0, n = 0; n < numangle; ang += theta, n++ ) @@ -249,7 +249,7 @@ icvHoughLinesSDiv( const CvMat* img, /* Precalculating sin */ _sinTable.resize( 5 * tn * stn ); sinTable = &_sinTable[0]; - + for( index = 0; index < 5 * tn * stn; index++ ) sinTable[index] = (float)cos( stheta * index * 0.2f ); @@ -449,7 +449,7 @@ icvHoughLinesSDiv( const CvMat* img, h_get_next__index( &pos ); } } - + h_destroy_list__index(list); } @@ -756,7 +756,7 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, } else CV_Error( CV_StsBadArg, "Destination is not CvMemStorage* nor CvMat*" ); - + iparam1 = cvRound(param1); iparam2 = cvRound(param2); @@ -842,7 +842,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, acols = accum->cols - 2; adata = accum->data.i; astep = accum->step/sizeof(adata[0]); - // Accumulate circle evidence for each edge pixel + // Accumulate circle evidence for each edge pixel for( y = 0; y < rows; y++ ) { const uchar* edges_row = edges->data.ptr + y*edges->step; @@ -868,7 +868,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, x0 = cvRound((x*idp)*ONE); y0 = cvRound((y*idp)*ONE); - // Step from min_radius to max_radius in both directions of the gradient + // Step from min_radius to max_radius in both directions of the gradient for( k = 0; k < 2; k++ ) { x1 = x0 + min_radius * sx; @@ -894,7 +894,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, nz_count = nz->total; if( !nz_count ) return; - //Find possible circle centers + //Find possible circle centers for( y = 1; y < arows - 1; y++ ) { for( x = 1; x < acols - 1; x++ ) @@ -924,19 +924,19 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, dr = dp; min_dist = MAX( min_dist, dp ); min_dist *= min_dist; - // For each found possible center - // Estimate radius and check support + // For each found possible center + // Estimate radius and check support for( i = 0; i < centers->total; i++ ) { int ofs = *(int*)cvGetSeqElem( centers, i ); y = ofs/(acols+2); x = ofs - (y)*(acols+2); - //Calculate circle's center in pixels + //Calculate circle's center in pixels float cx = (float)((x + 0.5f)*dp), cy = (float)(( y + 0.5f )*dp); float start_dist, dist_sum; float r_best = 0, c[3]; int max_count = 0; - // Check distance with previously detected circles + // Check distance with previously detected circles for( j = 0; j < circles->total; j++ ) { float* c = (float*)cvGetSeqElem( circles, j ); @@ -946,7 +946,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, if( j < circles->total ) continue; - // Estimate best radius + // Estimate best radius cvStartReadSeq( nz, &reader ); for( j = k = 0; j < nz_count; j++ ) { @@ -982,7 +982,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, { float r_cur = ddata[sort_buf[(j + start_idx)/2]]; if( (start_idx - j)*r_best >= max_count*r_cur || - (r_best < FLT_EPSILON && start_idx - j >= max_count) ) + (r_best < FLT_EPSILON && start_idx - j >= max_count) ) { r_best = r_cur; max_count = start_idx - j; @@ -993,7 +993,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist, } dist_sum += d; } - // Check if the circle has enough support + // Check if the circle has enough support if( max_count > acc_threshold ) { c[0] = cx; @@ -1103,9 +1103,9 @@ static void seqToMat(const CvSeq* seq, OutputArray _arr) else _arr.release(); } - + } - + void cv::HoughLines( InputArray _image, OutputArray _lines, double rho, double theta, int threshold, double srn, double stn ) diff --git a/modules/imgproc/src/phasecorr.cpp b/modules/imgproc/src/phasecorr.cpp index f78af82..71582cb 100644 --- a/modules/imgproc/src/phasecorr.cpp +++ b/modules/imgproc/src/phasecorr.cpp @@ -406,42 +406,42 @@ static void fftShift(InputOutputArray _out) merge(planes, out); } -Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize) +static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize) { Mat src = _src.getMat(); - + int type = src.type(); CV_Assert( type == CV_32FC1 || type == CV_64FC1 ); - + int minr = peakLocation.y - (weightBoxSize.height >> 1); int maxr = peakLocation.y + (weightBoxSize.height >> 1); int minc = peakLocation.x - (weightBoxSize.width >> 1); int maxc = peakLocation.x + (weightBoxSize.width >> 1); - + Point2d centroid; double sumIntensity = 0.0; - + // clamp the values to min and max if needed. if(minr < 0) { minr = 0; } - + if(minc < 0) { minc = 0; } - + if(maxr > src.rows - 1) { maxr = src.rows - 1; } - + if(maxc > src.cols - 1) { maxc = src.cols - 1; } - + if(type == CV_32FC1) { const float* dataIn = (const float*)src.data; @@ -454,7 +454,7 @@ Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weigh centroid.y += (double)y*dataIn[x]; sumIntensity += (double)dataIn[x]; } - + dataIn += src.cols; } } @@ -470,19 +470,19 @@ Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weigh centroid.y += (double)y*dataIn[x]; sumIntensity += dataIn[x]; } - + dataIn += src.cols; } } - + sumIntensity += DBL_EPSILON; // prevent div0 problems... - + centroid.x /= sumIntensity; centroid.y /= sumIntensity; - + return centroid; } - + } cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _window) diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index eda4c85..cfc171a 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -73,13 +73,13 @@ template struct RowSum : public BaseRowFilter ksize = _ksize; anchor = _anchor; } - + void operator()(const uchar* src, uchar* dst, int width, int cn) { const T* S = (const T*)src; ST* D = (ST*)dst; int i = 0, k, ksz_cn = ksize*cn; - + width = (width - 1)*cn; for( k = 0; k < cn; k++, S++, D++ ) { @@ -108,7 +108,7 @@ template struct ColumnSum : public BaseColumnFilter } void reset() { sumCount = 0; } - + void operator()(const uchar** src, uchar* dst, int dststep, int count, int width) { int i; @@ -198,7 +198,7 @@ template struct ColumnSum : public BaseColumnFilter } - + cv::Ptr cv::getRowSumFilter(int srcType, int sumType, int ksize, int anchor) { int sdepth = CV_MAT_DEPTH(srcType), ddepth = CV_MAT_DEPTH(sumType); @@ -325,7 +325,7 @@ void cv::blur( InputArray src, OutputArray dst, Size ksize, Point anchor, int borderType ) { boxFilter( src, dst, -1, ksize, anchor, true, borderType ); -} +} /****************************************************************************************\ Gaussian Blur @@ -422,7 +422,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, Mat src = _src.getMat(); _dst.create( src.size(), src.type() ); Mat dst = _dst.getMat(); - + if( borderType != BORDER_CONSTANT ) { if( src.rows == 1 ) @@ -454,7 +454,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, namespace cv { -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4244 ) #endif @@ -479,7 +479,7 @@ typedef struct #if CV_SSE2 #define MEDIAN_HAVE_SIMD 1 - + static inline void histogram_add_simd( const HT x[16], HT y[16] ) { const __m128i* rx = (const __m128i*)x; @@ -499,12 +499,12 @@ static inline void histogram_sub_simd( const HT x[16], HT y[16] ) _mm_store_si128(ry+0, r0); _mm_store_si128(ry+1, r1); } - + #else #define MEDIAN_HAVE_SIMD 0 #endif - + static inline void histogram_add( const HT x[16], HT y[16] ) { int i; @@ -667,14 +667,14 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) { for( j = 0; j < 2*r; ++j ) histogram_add( &h_coarse[16*(n*c+j)], H[c].coarse ); - + for( j = r; j < n-r; j++ ) { int t = 2*r*r + 2*r, b, sum = 0; HT* segment; - + histogram_add( &h_coarse[16*(n*c + std::min(j+r,n-1))], H[c].coarse ); - + // Find median at coarse level for ( k = 0; k < 16 ; ++k ) { @@ -686,14 +686,14 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) } } assert( k < 16 ); - + /* Update corresponding histogram segment */ if ( luc[c][k] <= j-r ) { memset( &H[c].fine[k], 0, 16 * sizeof(HT) ); for ( luc[c][k] = j-r; luc[c][k] < MIN(j+r+1,n); ++luc[c][k] ) histogram_add( &h_fine[16*(n*(16*c+k)+luc[c][k])], H[c].fine[k] ); - + if ( luc[c][k] < j+r+1 ) { histogram_muladd( j+r+1 - n, &h_fine[16*(n*(16*c+k)+(n-1))], &H[c].fine[k][0] ); @@ -708,9 +708,9 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) histogram_add( &h_fine[16*(n*(16*c+k)+MIN(luc[c][k],n-1))], H[c].fine[k] ); } } - + histogram_sub( &h_coarse[16*(n*c+MAX(j-r,0))], H[c].coarse ); - + /* Find median in segment */ segment = H[c].fine[k]; for ( b = 0; b < 16 ; b++ ) @@ -734,7 +734,7 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) } -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( default: 4244 ) #endif @@ -910,7 +910,7 @@ struct MinMax16u b = std::max(b, t); } }; - + struct MinMax16s { typedef short value_type; @@ -974,7 +974,7 @@ struct MinMaxVec16u } }; - + struct MinMaxVec16s { typedef short value_type; @@ -988,9 +988,9 @@ struct MinMaxVec16s a = _mm_min_epi16(a, b); b = _mm_max_epi16(b, t); } -}; +}; + - struct MinMaxVec32f { typedef float value_type; @@ -1033,7 +1033,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m ) Op op; VecOp vop; volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE2); - + if( m == 3 ) { if( size.width == 1 || size.height == 1 ) @@ -1055,7 +1055,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m ) } return; } - + size.width *= cn; for( i = 0; i < size.height; i++, dst += dstep ) { @@ -1155,7 +1155,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m ) p[k*5+2] = rowk[j]; p[k*5+3] = rowk[j3]; p[k*5+4] = rowk[j4]; } - + op(p[1], p[2]); op(p[0], p[1]); op(p[1], p[2]); op(p[4], p[5]); op(p[3], p[4]); op(p[4], p[5]); op(p[0], p[3]); op(p[2], p[5]); op(p[2], p[3]); op(p[1], p[4]); op(p[1], p[2]); op(p[3], p[4]); op(p[7], p[8]); op(p[6], p[7]); op(p[7], p[8]); @@ -1195,7 +1195,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m ) p[k*5+2] = vop.load(rowk+j); p[k*5+3] = vop.load(rowk+j+cn); p[k*5+4] = vop.load(rowk+j+cn*2); } - + vop(p[1], p[2]); vop(p[0], p[1]); vop(p[1], p[2]); vop(p[4], p[5]); vop(p[3], p[4]); vop(p[4], p[5]); vop(p[0], p[3]); vop(p[2], p[5]); vop(p[2], p[3]); vop(p[1], p[4]); vop(p[1], p[2]); vop(p[3], p[4]); vop(p[7], p[8]); vop(p[6], p[7]); vop(p[7], p[8]); @@ -1229,13 +1229,13 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m ) } } - + void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize ) { Mat src0 = _src0.getMat(); _dst.create( src0.size(), src0.type() ); Mat dst = _dst.getMat(); - + if( ksize <= 1 ) { src0.copyTo(dst); @@ -1248,13 +1248,13 @@ void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize ) if (tegra::medianBlur(src0, dst, ksize)) return; #endif - + bool useSortNet = ksize == 3 || (ksize == 5 #if !CV_SSE2 && src0.depth() > CV_8U #endif ); - + Mat src; if( useSortNet ) { @@ -1315,7 +1315,7 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d, sigma_color = 1; if( sigma_space <= 0 ) sigma_space = 1; - + double gauss_color_coeff = -0.5/(sigma_color*sigma_color); double gauss_space_coeff = -0.5/(sigma_space*sigma_space); @@ -1422,7 +1422,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, sigma_color = 1; if( sigma_space <= 0 ) sigma_space = 1; - + double gauss_color_coeff = -0.5/(sigma_color*sigma_color); double gauss_space_coeff = -0.5/(sigma_space*sigma_space); @@ -1433,9 +1433,9 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, radius = MAX(radius, 1); d = radius*2 + 1; // compute the min/max range for the input image (even if multichannel) - + minMaxLoc( src.reshape(1), &minValSrc, &maxValSrc ); - + // temporary copy of the image with borders for easy processing Mat temp; copyMakeBorder( src, temp, radius, radius, radius, radius, borderType ); @@ -1454,7 +1454,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, float* expLUT = &_expLUT[0]; scale_index = kExpNumBins/len; - + // initialize the exp LUT for( i = 0; i < kExpNumBins+2; i++ ) { @@ -1467,7 +1467,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, else expLUT[i] = 0.f; } - + // initialize space-related bilateral filter coefficients for( i = -radius, maxk = 0; i <= radius; i++ ) for( j = -radius; j <= radius; j++ ) @@ -1481,7 +1481,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, for( i = 0; i < size.height; i++ ) { - const float* sptr = (const float*)(temp.data + (i+radius)*temp.step) + radius*cn; + const float* sptr = (const float*)(temp.data + (i+radius)*temp.step) + radius*cn; float* dptr = (float*)(dst.data + i*dst.step); if( cn == 1 ) @@ -1493,11 +1493,11 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, for( k = 0; k < maxk; k++ ) { float val = sptr[j + space_ofs[k]]; - float alpha = (float)(std::abs(val - val0)*scale_index); + float alpha = (float)(std::abs(val - val0)*scale_index); int idx = cvFloor(alpha); alpha -= idx; float w = space_weight[k]*(expLUT[idx] + alpha*(expLUT[idx+1] - expLUT[idx])); - sum += val*w; + sum += val*w; wsum += w; } dptr[j] = (float)(sum/wsum); @@ -1514,7 +1514,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, { const float* sptr_k = sptr + j + space_ofs[k]; float b = sptr_k[0], g = sptr_k[1], r = sptr_k[2]; - float alpha = (float)((std::abs(b - b0) + + float alpha = (float)((std::abs(b - b0) + std::abs(g - g0) + std::abs(r - r0))*scale_index); int idx = cvFloor(alpha); alpha -= idx; @@ -1541,7 +1541,7 @@ void cv::bilateralFilter( InputArray _src, OutputArray _dst, int d, Mat src = _src.getMat(); _dst.create( src.size(), src.type() ); Mat dst = _dst.getMat(); - + if( src.depth() == CV_8U ) bilateralFilter_8u( src, dst, d, sigmaColor, sigmaSpace, borderType ); else if( src.depth() == CV_32F ) diff --git a/modules/imgproc/src/sumpixels.cpp b/modules/imgproc/src/sumpixels.cpp index 3a57a78..b441970 100644 --- a/modules/imgproc/src/sumpixels.cpp +++ b/modules/imgproc/src/sumpixels.cpp @@ -134,7 +134,7 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep, if( size.width == cn ) buf[cn] = 0; - + if( sqsum ) { sqsum[-cn] = 0; @@ -148,7 +148,7 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep, sum += sumstep - cn; tilted += tiltedstep - cn; buf += -cn; - + if( sqsum ) sqsum += sqsumstep - cn; @@ -197,7 +197,7 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep, tilted[x] = t0 + t1 + tilted[x - tiltedstep - cn]; buf[x] = t0; } - + if( sqsum ) sqsum++; } @@ -205,10 +205,10 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep, } } - + #define DEF_INTEGRAL_FUNC(suffix, T, ST, QT) \ -void integral_##suffix( T* src, size_t srcstep, ST* sum, size_t sumstep, QT* sqsum, size_t sqsumstep, \ - ST* tilted, size_t tiltedstep, Size size, int cn ) \ +static void integral_##suffix( T* src, size_t srcstep, ST* sum, size_t sumstep, QT* sqsum, size_t sqsumstep, \ + ST* tilted, size_t tiltedstep, Size size, int cn ) \ { integral_(src, srcstep, sum, sumstep, sqsum, sqsumstep, tilted, tiltedstep, size, cn); } DEF_INTEGRAL_FUNC(8u32s, uchar, int, double) @@ -217,7 +217,7 @@ DEF_INTEGRAL_FUNC(8u64f, uchar, double, double) DEF_INTEGRAL_FUNC(32f, float, float, double) DEF_INTEGRAL_FUNC(32f64f, float, double, double) DEF_INTEGRAL_FUNC(64f, double, double, double) - + typedef void (*IntegralFunc)(const uchar* src, size_t srcstep, uchar* sum, size_t sumstep, uchar* sqsum, size_t sqsumstep, uchar* tilted, size_t tstep, Size size, int cn ); @@ -236,19 +236,19 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output sdepth = CV_MAT_DEPTH(sdepth); _sum.create( isize, CV_MAKETYPE(sdepth, cn) ); sum = _sum.getMat(); - + if( _tilted.needed() ) { _tilted.create( isize, CV_MAKETYPE(sdepth, cn) ); tilted = _tilted.getMat(); } - + if( _sqsum.needed() ) { _sqsum.create( isize, CV_MAKETYPE(CV_64F, cn) ); sqsum = _sqsum.getMat(); } - + IntegralFunc func = 0; if( depth == CV_8U && sdepth == CV_32S ) @@ -269,7 +269,7 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output func( src.data, src.step, sum.data, sum.step, sqsum.data, sqsum.step, tilted.data, tilted.step, src.size(), cn ); } - + void cv::integral( InputArray src, OutputArray sum, int sdepth ) { integral( src, sum, noArray(), noArray(), sdepth ); diff --git a/modules/legacy/include/opencv2/legacy/blobtrack.hpp b/modules/legacy/include/opencv2/legacy/blobtrack.hpp index 3afce31..7a2695a 100644 --- a/modules/legacy/include/opencv2/legacy/blobtrack.hpp +++ b/modules/legacy/include/opencv2/legacy/blobtrack.hpp @@ -49,7 +49,7 @@ #include "opencv2/core/core_c.h" #include -#if _MSC_VER >= 1200 || defined __BORLANDC__ +#if (defined _MSC_VER && _MSC_VER >= 1200) || defined __BORLANDC__ #define cv_stricmp stricmp #define cv_strnicmp strnicmp #if defined WINCE diff --git a/modules/legacy/include/opencv2/legacy/legacy.hpp b/modules/legacy/include/opencv2/legacy/legacy.hpp index 6d2ca32..3911ebd 100644 --- a/modules/legacy/include/opencv2/legacy/legacy.hpp +++ b/modules/legacy/include/opencv2/legacy/legacy.hpp @@ -3478,7 +3478,7 @@ typedef struct CvBGCodeBookModel CvBGCodeBookElem* freeList; } CvBGCodeBookModel; -CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel(); +CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel( void ); CVAPI(void) cvReleaseBGCodeBookModel( CvBGCodeBookModel** model ); CVAPI(void) cvBGCodeBookUpdate( CvBGCodeBookModel* model, const CvArr* image, diff --git a/modules/legacy/src/3dtracker.cpp b/modules/legacy/src/3dtracker.cpp index e7dd622..ae4b9c1 100644 --- a/modules/legacy/src/3dtracker.cpp +++ b/modules/legacy/src/3dtracker.cpp @@ -41,7 +41,7 @@ #include "precomp.hpp" -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning(disable:4786) // Disable MSVC warnings in the standard library. #pragma warning(disable:4100) #pragma warning(disable:4512) @@ -49,7 +49,7 @@ #include #include #include -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning(default:4100) #pragma warning(default:4512) #endif @@ -148,7 +148,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras, cvReleaseImage(&gray_img); CV_CALL(gray_img = cvCreateImage(image_size, IPL_DEPTH_8U, 1)); } - + CV_CALL(cvCvtColor(samples[c], gray_img, CV_BGR2GRAY)); img = gray_img; @@ -172,7 +172,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras, etalon_size, points, &count) != 0; if (count == 0) continue; - + // If found is true, it means all the points were found (count = num_points). // If found is false but count is non-zero, it means that not all points were found. @@ -258,7 +258,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras, { 0.f, 1.f, 0.f, 0.f }, { 0.f, 0.f, 1.f, 0.f }, { transVect[0], transVect[1], transVect[2], 1.f } }; - + float rmat[4][4] = { { rotMatr[0], rotMatr[1], rotMatr[2], 0.f }, { rotMatr[3], rotMatr[4], rotMatr[5], 0.f }, { rotMatr[6], rotMatr[7], rotMatr[8], 0.f }, @@ -267,7 +267,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras, MultMatrix(camera_info[c].mat, tmat, rmat); - // change the transformation of the cameras to put them in the world coordinate + // change the transformation of the cameras to put them in the world coordinate // system we want to work with. // Start with an identity matrix; then fill in the values to accomplish diff --git a/modules/legacy/src/_kdtree.hpp b/modules/legacy/src/_kdtree.hpp index b46c995..635b862 100644 --- a/modules/legacy/src/_kdtree.hpp +++ b/modules/legacy/src/_kdtree.hpp @@ -53,13 +53,13 @@ #include "assert.h" #include "math.h" -#if _MSC_VER >= 1400 +#if defined _MSC_VER && _MSC_VER >= 1400 #pragma warning(disable: 4512) // suppress "assignment operator could not be generated" #endif -// J.S. Beis and D.G. Lowe. Shape indexing using approximate nearest-neighbor search -// in highdimensional spaces. In Proc. IEEE Conf. Comp. Vision Patt. Recog., -// pages 1000--1006, 1997. http://citeseer.ist.psu.edu/beis97shape.html +// J.S. Beis and D.G. Lowe. Shape indexing using approximate nearest-neighbor search +// in highdimensional spaces. In Proc. IEEE Conf. Comp. Vision Patt. Recog., +// pages 1000--1006, 1997. http://citeseer.ist.psu.edu/beis97shape.html #undef __deref #undef __valuetype @@ -72,23 +72,23 @@ public: private: struct node { - int dim; // split dimension; >=0 for nodes, -1 for leaves - __valuetype value; // if leaf, value of leaf - int left, right; // node indices of left and right branches - scalar_type boundary; // left if deref(value,dim)<=boundary, otherwise right + int dim; // split dimension; >=0 for nodes, -1 for leaves + __valuetype value; // if leaf, value of leaf + int left, right; // node indices of left and right branches + scalar_type boundary; // left if deref(value,dim)<=boundary, otherwise right }; typedef std::vector < node > node_array; - __deref deref; // requires operator() (__valuetype lhs,int dim) + __deref deref; // requires operator() (__valuetype lhs,int dim) - node_array nodes; // node storage - int point_dim; // dimension of points (the k in kd-tree) - int root_node; // index of root node, -1 if empty tree + node_array nodes; // node storage + int point_dim; // dimension of points (the k in kd-tree) + int root_node; // index of root node, -1 if empty tree // for given set of point indices, compute dimension of highest variance template < class __instype, class __valuector > int dimension_of_highest_variance(__instype * first, __instype * last, - __valuector ctor) { + __valuector ctor) { assert(last - first > 0); accum_type maxvar = -std::numeric_limits < accum_type >::max(); @@ -96,32 +96,32 @@ private: for (int j = 0; j < point_dim; ++j) { accum_type mean = 0; for (__instype * k = first; k < last; ++k) - mean += deref(ctor(*k), j); + mean += deref(ctor(*k), j); mean /= last - first; accum_type var = 0; for (__instype * k = first; k < last; ++k) { - accum_type diff = accum_type(deref(ctor(*k), j)) - mean; - var += diff * diff; + accum_type diff = accum_type(deref(ctor(*k), j)) - mean; + var += diff * diff; } var /= last - first; assert(maxj != -1 || var >= maxvar); if (var >= maxvar) { - maxvar = var; - maxj = j; + maxvar = var; + maxj = j; } } return maxj; } - // given point indices and dimension, find index of median; (almost) modifies [first,last) + // given point indices and dimension, find index of median; (almost) modifies [first,last) // such that points_in[first,median]<=point[median], points_in(median,last)>point[median]. // implemented as partial quicksort; expected linear perf. template < class __instype, class __valuector > __instype * median_partition(__instype * first, __instype * last, - int dim, __valuector ctor) { + int dim, __valuector ctor) { assert(last - first > 0); __instype *k = first + (last - first) / 2; median_partition(first, last, k, dim, ctor); @@ -143,14 +143,14 @@ private: }; template < class __instype, class __valuector > - void median_partition(__instype * first, __instype * last, - __instype * k, int dim, __valuector ctor) { + void median_partition(__instype * first, __instype * last, + __instype * k, int dim, __valuector ctor) { int pivot = (int)((last - first) / 2); std::swap(first[pivot], last[-1]); __instype *middle = std::partition(first, last - 1, - median_pr < __instype, __valuector > - (last[-1], dim, deref, ctor)); + median_pr < __instype, __valuector > + (last[-1], dim, deref, ctor)); std::swap(*middle, last[-1]); if (middle < k) @@ -170,36 +170,36 @@ private: __instype *median = median_partition(first, last, dim, ctor); __instype *split = median; - for (; split != last && deref(ctor(*split), dim) == - deref(ctor(*median), dim); ++split); + for (; split != last && deref(ctor(*split), dim) == + deref(ctor(*median), dim); ++split); if (split == last) { // leaf - int nexti = -1; - for (--split; split >= first; --split) { - int i = (int)nodes.size(); - node & n = *nodes.insert(nodes.end(), node()); - n.dim = -1; - n.value = ctor(*split); - n.left = -1; - n.right = nexti; - nexti = i; - } - - return nexti; + int nexti = -1; + for (--split; split >= first; --split) { + int i = (int)nodes.size(); + node & n = *nodes.insert(nodes.end(), node()); + n.dim = -1; + n.value = ctor(*split); + n.left = -1; + n.right = nexti; + nexti = i; + } + + return nexti; } else { // node - int i = (int)nodes.size(); - // note that recursive insert may invalidate this ref - node & n = *nodes.insert(nodes.end(), node()); + int i = (int)nodes.size(); + // note that recursive insert may invalidate this ref + node & n = *nodes.insert(nodes.end(), node()); - n.dim = dim; - n.boundary = deref(ctor(*median), dim); + n.dim = dim; + n.boundary = deref(ctor(*median), dim); - int left = insert(first, split, ctor); - nodes[i].left = left; - int right = insert(split, last, ctor); - nodes[i].right = right; + int left = insert(first, split, ctor); + nodes[i].left = left; + int right = insert(split, last, ctor); + nodes[i].right = right; - return i; + return i; } } } @@ -214,21 +214,21 @@ private: if (n.dim >= 0) { // node if (deref(p, n.dim) <= n.boundary) // left - r = remove(&n.left, p); + r = remove(&n.left, p); else // right - r = remove(&n.right, p); + r = remove(&n.right, p); // if terminal, remove this node if (n.left == -1 && n.right == -1) - *i = -1; + *i = -1; return r; } else { // leaf if (n.value == p) { - *i = n.right; - return true; + *i = n.right; + return true; } else - return remove(&n.right, p); + return remove(&n.right, p); } } @@ -245,14 +245,14 @@ public: } // given points, initialize a balanced tree CvKDTree(__valuetype * first, __valuetype * last, int _point_dim, - __deref _deref = __deref()) + __deref _deref = __deref()) : deref(_deref) { set_data(first, last, _point_dim, identity_ctor()); } // given points, initialize a balanced tree template < class __instype, class __valuector > CvKDTree(__instype * first, __instype * last, int _point_dim, - __valuector ctor, __deref _deref = __deref()) + __valuector ctor, __deref _deref = __deref()) : deref(_deref) { set_data(first, last, _point_dim, ctor); } @@ -266,7 +266,7 @@ public: } template < class __instype, class __valuector > void set_data(__instype * first, __instype * last, int _point_dim, - __valuector ctor) { + __valuector ctor) { point_dim = _point_dim; nodes.clear(); nodes.reserve(last - first); @@ -292,9 +292,9 @@ public: std::cout << " "; const node & n = nodes[i]; if (n.dim >= 0) { - std::cout << "node " << i << ", left " << nodes[i].left << ", right " << - nodes[i].right << ", dim " << nodes[i].dim << ", boundary " << - nodes[i].boundary << std::endl; + std::cout << "node " << i << ", left " << nodes[i].left << ", right " << + nodes[i].right << ", dim " << nodes[i].dim << ", boundary " << + nodes[i].boundary << std::endl; print(n.left, indent + 3); print(n.right, indent + 3); } else @@ -304,9 +304,9 @@ public: //////////////////////////////////////////////////////////////////////////////////////// // bbf search public: - struct bbf_nn { // info on found neighbors (approx k nearest) - const __valuetype *p; // nearest neighbor - accum_type dist; // distance from d to query point + struct bbf_nn { // info on found neighbors (approx k nearest) + const __valuetype *p; // nearest neighbor + accum_type dist; // distance from d to query point bbf_nn(const __valuetype & _p, accum_type _dist) : p(&_p), dist(_dist) { } @@ -316,9 +316,9 @@ public: }; typedef std::vector < bbf_nn > bbf_nn_pqueue; private: - struct bbf_node { // info on branches not taken - int node; // corresponding node - accum_type dist; // minimum distance from bounds to query point + struct bbf_node { // info on branches not taken + int node; // corresponding node + accum_type dist; // minimum distance from bounds to query point bbf_node(int _node, accum_type _dist) : node(_node), dist(_dist) { } @@ -346,10 +346,10 @@ private: int bbf_branch(int i, const __desctype * d, bbf_pqueue & pq) const { const node & n = nodes[i]; // push bbf_node with bounds of alternate branch, then branch - if (d[n.dim] <= n.boundary) { // left + if (d[n.dim] <= n.boundary) { // left pq_alternate(n.right, pq, n.boundary - d[n.dim]); return n.left; - } else { // right + } else { // right pq_alternate(n.left, pq, d[n.dim] - n.boundary); return n.right; } @@ -366,11 +366,11 @@ private: } // called per candidate nearest neighbor; constructs new bbf_nn for - // candidate and adds it to priority queue of all candidates; if + // candidate and adds it to priority queue of all candidates; if // queue len exceeds k, drops the point furthest from query point d. template < class __desctype > - void bbf_new_nn(bbf_nn_pqueue & nn_pq, int k, - const __desctype * d, const __valuetype & p) const { + void bbf_new_nn(bbf_nn_pqueue & nn_pq, int k, + const __desctype * d, const __valuetype & p) const { bbf_nn nn(p, distance(d, p)); if ((int) nn_pq.size() < k) { nn_pq.push_back(nn); @@ -384,14 +384,14 @@ private: } public: - // finds (with high probability) the k nearest neighbors of d, + // finds (with high probability) the k nearest neighbors of d, // searching at most emax leaves/bins. - // ret_nn_pq is an array containing the (at most) k nearest neighbors + // ret_nn_pq is an array containing the (at most) k nearest neighbors // (see bbf_nn structure def above). template < class __desctype > - int find_nn_bbf(const __desctype * d, - int k, int emax, - bbf_nn_pqueue & ret_nn_pq) const { + int find_nn_bbf(const __desctype * d, + int k, int emax, + bbf_nn_pqueue & ret_nn_pq) const { assert(k > 0); ret_nn_pq.clear(); @@ -411,17 +411,17 @@ public: int i; for (i = bbf.node; - i != -1 && nodes[i].dim >= 0; - i = bbf_branch(i, d, tmp_pq)); + i != -1 && nodes[i].dim >= 0; + i = bbf_branch(i, d, tmp_pq)); if (i != -1) { - // add points in leaf/bin to ret_nn_pq - do { - bbf_new_nn(ret_nn_pq, k, d, nodes[i].value); - } while (-1 != (i = nodes[i].right)); + // add points in leaf/bin to ret_nn_pq + do { + bbf_new_nn(ret_nn_pq, k, d, nodes[i].value); + } while (-1 != (i = nodes[i].right)); - --emax; + --emax; } } @@ -433,27 +433,27 @@ public: // orthogonal range search private: void find_ortho_range(int i, scalar_type * bounds_min, - scalar_type * bounds_max, - std::vector < __valuetype > &inbounds) const { + scalar_type * bounds_max, + std::vector < __valuetype > &inbounds) const { if (i == -1) return; const node & n = nodes[i]; if (n.dim >= 0) { // node if (bounds_min[n.dim] <= n.boundary) - find_ortho_range(n.left, bounds_min, bounds_max, inbounds); + find_ortho_range(n.left, bounds_min, bounds_max, inbounds); if (bounds_max[n.dim] > n.boundary) - find_ortho_range(n.right, bounds_min, bounds_max, inbounds); + find_ortho_range(n.right, bounds_min, bounds_max, inbounds); } else { // leaf do { - inbounds.push_back(nodes[i].value); + inbounds.push_back(nodes[i].value); } while (-1 != (i = nodes[i].right)); } } public: // return all points that lie within the given bounds; inbounds is cleared int find_ortho_range(scalar_type * bounds_min, - scalar_type * bounds_max, - std::vector < __valuetype > &inbounds) const { + scalar_type * bounds_max, + std::vector < __valuetype > &inbounds) const { inbounds.clear(); find_ortho_range(root_node, bounds_min, bounds_max, inbounds); return (int)inbounds.size(); diff --git a/modules/legacy/src/blobtrackanalysishist.cpp b/modules/legacy/src/blobtrackanalysishist.cpp index bc52422..e3aef57 100644 --- a/modules/legacy/src/blobtrackanalysishist.cpp +++ b/modules/legacy/src/blobtrackanalysishist.cpp @@ -237,9 +237,9 @@ public: virtual float* GetFVVar(){return m_FVVar;}; /* returned pointer to array of maximal values of FV, if return 0 then FVrange is not exist */ };/* CvBlobTrackFVGenN */ -CvBlobTrackFVGen* cvCreateFVGenP(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(2);} -CvBlobTrackFVGen* cvCreateFVGenPV(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(4);} -CvBlobTrackFVGen* cvCreateFVGenPVS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(5);} +inline CvBlobTrackFVGen* cvCreateFVGenP(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(2);} +inline CvBlobTrackFVGen* cvCreateFVGenPV(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(4);} +inline CvBlobTrackFVGen* cvCreateFVGenPVS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(5);} #undef MAX_FV_SIZE #define MAX_FV_SIZE 4 @@ -408,7 +408,7 @@ public: virtual float* GetFVVar(){return m_FVVar;}; /* returned pointer to array of maximal values of FV, if return 0 then FVrange is not exist */ };/* CvBlobTrackFVGenSS */ -CvBlobTrackFVGen* cvCreateFVGenSS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenSS;} +inline CvBlobTrackFVGen* cvCreateFVGenSS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenSS;} /*======================= TRAJECTORY ANALYZER MODULES =====================*/ /* Trajectory Analyser module */ @@ -1510,7 +1510,7 @@ public: }; /* CvBlobTrackAnalysisSVM. */ - +#if 0 CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP() {return (CvBlobTrackAnalysis*) new CvBlobTrackAnalysisSVM(cvCreateFVGenP);} @@ -1522,3 +1522,4 @@ CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS() CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS() {return (CvBlobTrackAnalysis*) new CvBlobTrackAnalysisSVM(cvCreateFVGenSS);} +#endif diff --git a/modules/legacy/src/blobtrackingkalman.cpp b/modules/legacy/src/blobtrackingkalman.cpp index 2e41ea1..3a0f03a 100644 --- a/modules/legacy/src/blobtrackingkalman.cpp +++ b/modules/legacy/src/blobtrackingkalman.cpp @@ -162,12 +162,15 @@ public: } }; /* class CvBlobTrackerOneKalman */ +#if 0 static CvBlobTrackerOne* cvCreateModuleBlobTrackerOneKalman() { return (CvBlobTrackerOne*) new CvBlobTrackerOneKalman; } + CvBlobTracker* cvCreateBlobTrackerKalman() { return cvCreateBlobTrackerList(cvCreateModuleBlobTrackerOneKalman); } +#endif diff --git a/modules/legacy/src/blobtrackingmsfg.cpp b/modules/legacy/src/blobtrackingmsfg.cpp index 2d1dafb..8444964 100644 --- a/modules/legacy/src/blobtrackingmsfg.cpp +++ b/modules/legacy/src/blobtrackingmsfg.cpp @@ -716,7 +716,7 @@ void CvBlobTrackerOneMSFG::CollectHist(IplImage* pImg, IplImage* pMask, CvBlob* }; /* CollectHist */ #endif -CvBlobTrackerOne* cvCreateBlobTrackerOneMSFG() +static CvBlobTrackerOne* cvCreateBlobTrackerOneMSFG() { return (CvBlobTrackerOne*) new CvBlobTrackerOneMSFG; } @@ -739,7 +739,7 @@ public: }; }; -CvBlobTrackerOne* cvCreateBlobTrackerOneMS() +static CvBlobTrackerOne* cvCreateBlobTrackerOneMS() { return (CvBlobTrackerOne*) new CvBlobTrackerOneMS; } @@ -1169,6 +1169,7 @@ public: }; /* CvBlobTrackerOneMSPF */ +CvBlobTrackerOne* cvCreateBlobTrackerOneMSPF(); CvBlobTrackerOne* cvCreateBlobTrackerOneMSPF() { return (CvBlobTrackerOne*) new CvBlobTrackerOneMSPF; diff --git a/modules/legacy/src/blobtrackingmsfgs.cpp b/modules/legacy/src/blobtrackingmsfgs.cpp index 9adf56a..65de3ef 100644 --- a/modules/legacy/src/blobtrackingmsfgs.cpp +++ b/modules/legacy/src/blobtrackingmsfgs.cpp @@ -47,7 +47,7 @@ typedef float DefHistType; #define DefHistTypeMat CV_32F #define HIST_INDEX(_pData) (((_pData)[0]>>m_ByteShift) + (((_pData)[1]>>(m_ByteShift))<>m_ByteShift)<<(m_BinBit*2))) -void calcKernelEpanechnikov(CvMat* pK) +static void calcKernelEpanechnikov(CvMat* pK) { /* Allocate kernel for histogramm creation: */ int x,y; int w = pK->width; @@ -445,7 +445,7 @@ public: virtual void Release(){delete this;}; }; /*CvBlobTrackerOneMSFGS*/ -CvBlobTrackerOne* cvCreateBlobTrackerOneMSFGS() +static CvBlobTrackerOne* cvCreateBlobTrackerOneMSFGS() { return (CvBlobTrackerOne*) new CvBlobTrackerOneMSFGS; } diff --git a/modules/legacy/src/blobtrackpostprockalman.cpp b/modules/legacy/src/blobtrackpostprockalman.cpp index 8eea2c6..debe89d 100644 --- a/modules/legacy/src/blobtrackpostprockalman.cpp +++ b/modules/legacy/src/blobtrackpostprockalman.cpp @@ -188,7 +188,7 @@ void CvBlobTrackPostProcKalman::Release() delete this; } -CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcKalmanOne() +static CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcKalmanOne() { return (CvBlobTrackPostProcOne*) new CvBlobTrackPostProcKalman; } diff --git a/modules/legacy/src/blobtrackpostproclinear.cpp b/modules/legacy/src/blobtrackpostproclinear.cpp index df50e0f..c18737c 100644 --- a/modules/legacy/src/blobtrackpostproclinear.cpp +++ b/modules/legacy/src/blobtrackpostproclinear.cpp @@ -106,12 +106,12 @@ public: } }; /* class CvBlobTrackPostProcTimeAver */ -CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverRectOne() +static CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverRectOne() { return (CvBlobTrackPostProcOne*) new CvBlobTrackPostProcTimeAver(0); } -CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverExpOne() +static CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverExpOne() { return (CvBlobTrackPostProcOne*) new CvBlobTrackPostProcTimeAver(1); } diff --git a/modules/legacy/src/calibfilter.cpp b/modules/legacy/src/calibfilter.cpp index 4d608bb..0462590 100644 --- a/modules/legacy/src/calibfilter.cpp +++ b/modules/legacy/src/calibfilter.cpp @@ -44,7 +44,7 @@ #undef quad -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4701 ) #endif @@ -99,18 +99,18 @@ bool CvCalibFilter::SetEtalon( CvCalibEtalonType type, double* params, Stop(); - if (latestPoints != NULL) - { - for( i = 0; i < MAX_CAMERAS; i++ ) - cvFree( latestPoints + i ); - } + if (latestPoints != NULL) + { + for( i = 0; i < MAX_CAMERAS; i++ ) + cvFree( latestPoints + i ); + } if( type == CV_CALIB_ETALON_USER || type != etalonType ) { - if (etalonParams != NULL) - { - cvFree( &etalonParams ); - } + if (etalonParams != NULL) + { + cvFree( &etalonParams ); + } } etalonType = type; @@ -154,10 +154,10 @@ bool CvCalibFilter::SetEtalon( CvCalibEtalonType type, double* params, if( etalonPointCount != pointCount ) { - if (etalonPoints != NULL) - { - cvFree( &etalonPoints ); - } + if (etalonPoints != NULL) + { + cvFree( &etalonPoints ); + } etalonPointCount = pointCount; etalonPoints = (CvPoint2D32f*)cvAlloc( arrSize ); } @@ -184,15 +184,15 @@ bool CvCalibFilter::SetEtalon( CvCalibEtalonType type, double* params, break; case CV_CALIB_ETALON_USER: - if (params != NULL) - { - memcpy( etalonParams, params, arrSize ); - } - if (points != NULL) - { - memcpy( etalonPoints, points, arrSize ); - } - break; + if (params != NULL) + { + memcpy( etalonParams, params, arrSize ); + } + if (points != NULL) + { + memcpy( etalonPoints, points, arrSize ); + } + break; default: assert(0); @@ -226,7 +226,7 @@ CvCalibFilter::GetEtalon( int* paramCount, const double** params, void CvCalibFilter::SetCameraCount( int count ) { Stop(); - + if( count != cameraCount ) { for( int i = 0; i < cameraCount; i++ ) @@ -245,7 +245,7 @@ void CvCalibFilter::SetCameraCount( int count ) } } - + bool CvCalibFilter::SetFrames( int frames ) { if( frames < 5 ) @@ -253,7 +253,7 @@ bool CvCalibFilter::SetFrames( int frames ) assert(0); return false; } - + framesTotal = frames; return true; } @@ -304,7 +304,7 @@ void CvCalibFilter::Stop( bool calibrate ) cameraParams[i].imgSize[0] = (float)imgSize.width; cameraParams[i].imgSize[1] = (float)imgSize.height; - + // cameraParams[i].focalLength[0] = cameraParams[i].matrix[0]; // cameraParams[i].focalLength[1] = cameraParams[i].matrix[4]; @@ -315,7 +315,7 @@ void CvCalibFilter::Stop( bool calibrate ) memcpy( cameraParams[i].transVect, transVect, 3 * sizeof(transVect[0])); mat.data.ptr = (uchar*)(cameraParams + i); - + /* check resultant camera parameters: if there are some INF's or NAN's, stop and reset results */ if( !cvCheckArr( &mat, CV_CHECK_RANGE | CV_CHECK_QUIET, -10000, 10000 )) @@ -342,7 +342,7 @@ void CvCalibFilter::Stop( bool calibrate ) { stereo.fundMatr[i] = stereo.fundMatr[i]; } - + } } @@ -499,16 +499,16 @@ bool CvCalibFilter::GetLatestPoints( int idx, CvPoint2D32f** pts, int* count, bool* found ) { int n; - + if( (unsigned)idx >= (unsigned)cameraCount || !pts || !count || !found ) { assert(0); return false; } - + n = latestCounts[idx]; - + *found = n > 0; *count = abs(n); *pts = latestPoints[idx]; @@ -616,7 +616,7 @@ const CvCamera* CvCalibFilter::GetCameraParams( int idx ) const assert(0); return 0; } - + return isCalibrated ? cameraParams + idx : 0; } @@ -630,7 +630,7 @@ const CvStereoCamera* CvCalibFilter::GetStereoParams() const assert(0); return 0; } - + return &stereo; } @@ -640,9 +640,9 @@ bool CvCalibFilter::SetCameraParams( CvCamera* params ) { CvMat mat; int arrSize; - + Stop(); - + if( !params ) { assert(0); @@ -667,7 +667,7 @@ bool CvCalibFilter::SaveCameraParams( const char* filename ) if( isCalibrated ) { int i, j; - + FILE* f = fopen( filename, "w" ); if( !f ) return false; @@ -729,7 +729,7 @@ bool CvCalibFilter::LoadCameraParams( const char* filename ) return false; SetCameraCount( d ); - + for( i = 0; i < cameraCount; i++ ) { for( j = 0; j < (int)(sizeof(cameraParams[i])/sizeof(float)); j++ ) @@ -763,16 +763,16 @@ bool CvCalibFilter::LoadCameraParams( const char* filename ) CV_Assert(values_read == 1); } } - - - - + + + + fclose(f); stereo.warpSize = cvSize( cvRound(cameraParams[0].imgSize[0]), cvRound(cameraParams[0].imgSize[1])); isCalibrated = true; - + return true; } @@ -924,4 +924,4 @@ bool CvCalibFilter::Undistort( CvMat** srcarr, CvMat** dstarr ) return true; } - + diff --git a/modules/legacy/src/corrimages.cpp b/modules/legacy/src/corrimages.cpp index c271664..027dc6e 100644 --- a/modules/legacy/src/corrimages.cpp +++ b/modules/legacy/src/corrimages.cpp @@ -45,7 +45,7 @@ //#include //#include "cv.h" //#include "highgui.h" - +#if 0 #include /* Valery Mosyagin */ @@ -53,7 +53,7 @@ /* ===== Function for find corresponding between images ===== */ /* Create feature points on image and return number of them. Array points fills by found points */ -int icvCreateFeaturePoints(IplImage *image, CvMat *points, CvMat *status) +static int icvCreateFeaturePoints(IplImage *image, CvMat *points, CvMat *status) { int foundFeaturePoints = 0; IplImage *grayImage = 0; @@ -175,9 +175,9 @@ int icvCreateFeaturePoints(IplImage *image, CvMat *points, CvMat *status) /* For given points1 (with pntStatus) on image1 finds corresponding points2 on image2 and set pntStatus2 for them */ /* Returns number of corresponding points */ -int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ +static int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ IplImage *image2,/* Image 2 */ - CvMat *points1, + CvMat *points1, CvMat *pntStatus1, CvMat *points2, CvMat *pntStatus2, @@ -203,7 +203,7 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ /* Test input data for errors */ /* Test for null pointers */ - if( image1 == 0 || image2 == 0 || + if( image1 == 0 || image2 == 0 || points1 == 0 || points2 == 0 || pntStatus1 == 0 || pntStatus2 == 0) { @@ -226,7 +226,7 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ } /* Test for matrices */ - if( !CV_IS_MAT(points1) || !CV_IS_MAT(points2) || + if( !CV_IS_MAT(points1) || !CV_IS_MAT(points2) || !CV_IS_MAT(pntStatus1) || !CV_IS_MAT(pntStatus2) ) { CV_ERROR( CV_StsUnsupportedFormat, "Input parameters (points and status) must be a matrices" ); @@ -333,11 +333,11 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ pyrImage1, pyrImage2, cornerPoints1, cornerPoints2, numVisPoints, cvSize(10,10), 3, - status, errors, + status, errors, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), 0/*CV_LKFLOW_PYR_A_READY*/ ); - + memset(stat2,0,sizeof(uchar)*numPoints); int currVis = 0; @@ -393,7 +393,7 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ CvMat fundMatr; double fundMatr_dat[9]; fundMatr = cvMat(3,3,CV_64F,fundMatr_dat); - + CV_CALL( pStatus = cvCreateMat(1,totalCorns,CV_32F) ); int num = cvFindFundamentalMat(tmpPoints1,tmpPoints2,&fundMatr,CV_FM_RANSAC,threshold,0.99,pStatus); @@ -435,8 +435,9 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */ return resNumCorrPoints; } + /*-------------------------------------------------------------------------------------*/ -int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints,CvMat *addStatus,int addCreateNum) +static int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints,CvMat *addStatus,int addCreateNum) { /* Add to existing points and status arrays new points or just grow */ CvMat *newOldPoint = 0; @@ -445,7 +446,7 @@ int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints, CV_FUNCNAME( "icvGrowPointsAndStatus" ); __BEGIN__; - + /* Test for errors */ if( oldPoints == 0 || oldStatus == 0 ) { @@ -546,8 +547,9 @@ int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints, return newTotalNumber; } + /*-------------------------------------------------------------------------------------*/ -int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ +static int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ CvMat *newPoints,/* New points */ CvMat *oldStatus,/* Status for old points */ CvMat *newStatus, @@ -560,7 +562,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ CvSeq* seq = 0; int originalPoints = 0; - + CV_FUNCNAME( "icvRemoveDoublePoins" ); __BEGIN__; @@ -624,7 +626,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ { CV_ERROR( CV_StsOutOfRange, "Statuses must have 1 row" ); } - + /* we have points on image and wants add new points */ /* use subdivision for find nearest points */ @@ -731,7 +733,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ /* Point is double. Turn it off */ /* Set status */ //newStatus->data.ptr[i] = 0; - + /* No this is a double point */ //originalPoints--; flag = 0; @@ -745,7 +747,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ __END__; cvReleaseMemStorage( &storage ); - + return originalPoints; @@ -755,11 +757,11 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */ void icvComputeProjectMatrix(CvMat* objPoints,CvMat* projPoints,CvMat* projMatr); /*-------------------------------------------------------------------------------------*/ -void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *status, CvMat *projMatr) +static void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *status, CvMat *projMatr) { /* Compute number of good points */ int num = cvCountNonZero(status); - + /* Create arrays */ CvMat *objPoints = 0; objPoints = cvCreateMat(4,num,CV_64F); @@ -802,7 +804,7 @@ void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *stat currVis++; } - + fprintf(file,"\n"); } @@ -820,17 +822,16 @@ void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *stat /*-------------------------------------------------------------------------------------*/ -/* For given N images +/* For given N images we have corresponding points on N images computed projection matrices reconstructed 4D points - we must to compute - + we must to compute -*/ -void icvAddNewImageToPrevious____( +*/ +static void icvAddNewImageToPrevious____( IplImage *newImage,//Image to add IplImage *oldImage,//Previous image CvMat *oldPoints,// previous 2D points on prev image (some points may be not visible) @@ -868,7 +869,7 @@ void icvAddNewImageToPrevious____( int corrNum; corrNum = icvFindCorrForGivenPoints( oldImage,/* Image 1 */ newImage,/* Image 2 */ - oldPoints, + oldPoints, oldPntStatus, points2, status, @@ -887,10 +888,10 @@ void icvAddNewImageToPrevious____( // icvComputeProjectMatrix(objPoints4D,points2,&projMatr); icvComputeProjectMatrixStatus(objPoints4D,points2,status,&projMatr); cvCopy(&projMatr,newProjMatr); - + /* Create new points and find correspondence */ icvCreateFeaturePoints(newImage, newFPoints2D2,newFPointsStatus); - + /* Good if we test new points before find corr points */ /* Find correspondence for new found points */ @@ -947,7 +948,7 @@ void icvAddNewImageToPrevious____( //CreateGood /*-------------------------------------------------------------------------------------*/ -int icvDeleteSparsInPoints( int numImages, +static int icvDeleteSparsInPoints( int numImages, CvMat **points, CvMat **status, CvMat *wasStatus)/* status of previous configuration */ @@ -979,7 +980,7 @@ int icvDeleteSparsInPoints( int numImages, int numCoord; numCoord = points[0]->rows;// !!! may be number of coordinates is not correct !!! - + int i; int currExistPoint; currExistPoint = 0; @@ -1041,7 +1042,7 @@ int icvDeleteSparsInPoints( int numImages, return comNumber; } -#if 0 + /*-------------------------------------------------------------------------------------*/ void icvGrowPointsArray(CvMat **points) { @@ -1089,7 +1090,7 @@ int AddImageToStruct( IplImage *newImage,//Image to add cvConvert(pntStatus,status); int corrNum = FindCorrForGivenPoints(oldImage,newImage,oldPoints,newPoints,status); - + /* Status has new status of points */ CvMat projMatr; diff --git a/modules/legacy/src/dpstereo.cpp b/modules/legacy/src/dpstereo.cpp index 93e735f..798bd99 100644 --- a/modules/legacy/src/dpstereo.cpp +++ b/modules/legacy/src/dpstereo.cpp @@ -48,7 +48,7 @@ Stan Birchfield and Carlo Tomasi International Journal of Computer Vision, 35(3): 269-293, December 1999. - + This implementation uses different cost function that results in O(pixPerRow*maxDisparity) complexity of dynamic programming stage versus O(pixPerRow*log(pixPerRow)*maxDisparity) in the above paper. @@ -68,7 +68,7 @@ typedef struct _CvDPCell { uchar step; //local-optimal step - int sum; //current sum + int sum; //current sum }_CvDPCell; typedef struct _CvRightImData @@ -79,17 +79,17 @@ typedef struct _CvRightImData #define CV_IMAX3(a,b,c) ((temp3 = (a) >= (b) ? (a) : (b)),(temp3 >= (c) ? temp3 : (c))) #define CV_IMIN3(a,b,c) ((temp3 = (a) <= (b) ? (a) : (b)),(temp3 <= (c) ? temp3 : (c))) -void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, +static void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, uchar* disparities, CvSize size, int widthStep, - int maxDisparity, - float _param1, float _param2, + int maxDisparity, + float _param1, float _param2, float _param3, float _param4, float _param5 ) { int x, y, i, j, temp3; int d, s; - int dispH = maxDisparity + 3; + int dispH = maxDisparity + 3; uchar *dispdata; int imgW = size.width; int imgH = size.height; @@ -103,22 +103,22 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, int param5 = cvRound(_param5); #define CELL(d,x) cells[(d)+(x)*dispH] - + uchar* dsi = (uchar*)cvAlloc(sizeof(uchar)*imgW*dispH); uchar* edges = (uchar*)cvAlloc(sizeof(uchar)*imgW*imgH); _CvDPCell* cells = (_CvDPCell*)cvAlloc(sizeof(_CvDPCell)*imgW*MAX(dispH,(imgH+1)/2)); _CvRightImData* rData = (_CvRightImData*)cvAlloc(sizeof(_CvRightImData)*imgW); int* reliabilities = (int*)cells; - - for( y = 0; y < imgH; y++ ) - { + + for( y = 0; y < imgH; y++ ) + { uchar* srcdata1 = src1 + widthStep * y; - uchar* srcdata2 = src2 + widthStep * y; + uchar* srcdata2 = src2 + widthStep * y; //init rData prevval = prev = srcdata2[0]; for( j = 1; j < imgW; j++ ) - { + { curr = srcdata2[j]; val = (uchar)((curr + prev)>>1); rData[j-1].max_val = (uchar)CV_IMAX3( val, prevval, prev ); @@ -130,12 +130,12 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, // fill dissimularity space image for( i = 1; i <= maxDisparity + 1; i++ ) - { + { dsi += imgW; rData--; for( j = i - 1; j < imgW - 1; j++ ) - { - int t; + { + int t; if( (t = srcdata1[j] - rData[j+1].max_val) >= 0 ) { dsi[j] = (uchar)t; @@ -160,36 +160,36 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, for( j = 3; j < imgW-4; j++ ) { edges[y*imgW+j] = 0; - - if( ( CV_IMAX3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) - + + if( ( CV_IMAX3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) - CV_IMIN3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) ) >= ICV_BIRCH_DIFF_LUM ) { edges[y*imgW+j] |= 1; } - if( ( CV_IMAX3( srcdata2[j+3], srcdata2[j+2], srcdata2[j+1] ) - + if( ( CV_IMAX3( srcdata2[j+3], srcdata2[j+2], srcdata2[j+1] ) - CV_IMIN3( srcdata2[j+3], srcdata2[j+2], srcdata2[j+1] ) ) >= ICV_BIRCH_DIFF_LUM ) { edges[y*imgW+j] |= 2; - } - } + } + } //find correspondence using dynamical programming //init DP table - for( x = 0; x < imgW; x++ ) + for( x = 0; x < imgW; x++ ) { CELL(0,x).sum = CELL(dispH-1,x).sum = ICV_MAX_DP_SUM_VAL; CELL(0,x).step = CELL(dispH-1,x).step = ICV_DP_STEP_LEFT; } - for( d = 2; d < dispH; d++ ) + for( d = 2; d < dispH; d++ ) { CELL(d,d-2).sum = ICV_MAX_DP_SUM_VAL; CELL(d,d-2).step = ICV_DP_STEP_UP; - } + } CELL(1,0).sum = 0; CELL(1,0).step = ICV_DP_STEP_LEFT; for( x = 1; x < imgW; x++ ) - { + { int d = MIN( x + 1, maxDisparity + 1); uchar* _edges = edges + y*imgW + x; int e0 = _edges[0] & 1; @@ -201,17 +201,17 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, int sum[3]; //check left step - sum[0] = _cell[d-dispH].sum - param2; + sum[0] = _cell[d-dispH].sum - param2; //check up step if( _cell[d+1].step != ICV_DP_STEP_DIAG && e0 ) { sum[1] = _cell[d+1].sum + param1; - if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) ) + if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) ) { int t; - + sum[2] = _cell[d-1-dispH].sum + param1; t = sum[1] < sum[0]; @@ -223,7 +223,7 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, _cell[d].sum = sum[t] + s; } else - { + { _cell[d].step = ICV_DP_STEP_DIAG; _cell[d].sum = sum[2] + s; } @@ -242,7 +242,7 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, } } } - else if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) ) + else if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) ) { sum[2] = _cell[d-1-dispH].sum + param1; if( sum[0] <= sum[2] ) @@ -278,25 +278,25 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, min_val = CELL(i,imgW-1).sum; } } - + //track optimal pass for( x = imgW - 1; x > 0; x-- ) - { + { dispdata[x] = (uchar)(d - 1); while( CELL(d,x).step == ICV_DP_STEP_UP ) d++; if ( CELL(d,x).step == ICV_DP_STEP_DIAG ) { s = x; - while( CELL(d,x).step == ICV_DP_STEP_DIAG ) + while( CELL(d,x).step == ICV_DP_STEP_DIAG ) { - d--; - x--; + d--; + x--; } for( i = x; i < s; i++ ) { dispdata[i] = (uchar)(d-1); - } - } + } + } }//for x }// for y @@ -319,9 +319,9 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, { for( y = 1; y < imgH - 1; y++ ) { - if( ( CV_IMAX3( src1[(y-1)*widthStep+x], src1[y*widthStep+x], - src1[(y+1)*widthStep+x] ) - - CV_IMIN3( src1[(y-1)*widthStep+x], src1[y*widthStep+x], + if( ( CV_IMAX3( src1[(y-1)*widthStep+x], src1[y*widthStep+x], + src1[(y+1)*widthStep+x] ) - + CV_IMIN3( src1[(y-1)*widthStep+x], src1[y*widthStep+x], src1[(y+1)*widthStep+x] ) ) >= ICV_BIRCH_DIFF_LUM ) { edges[y*imgW+x] |= 4; @@ -332,14 +332,14 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, } } - //remove along any particular row, every gradient + //remove along any particular row, every gradient //for which two adjacent columns do not agree. for( y = 0; y < imgH; y++ ) { prev = edges[y*imgW]; for( x = 1; x < imgW - 1; x++ ) { - curr = edges[y*imgW+x]; + curr = edges[y*imgW+x]; if( (curr & 4) && ( !( prev & 4 ) || !( edges[y*imgW+x+1] & 4 ) ) ) @@ -360,41 +360,41 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, ; s = y - i; for( ; i < y; i++ ) - { + { reliabilities[i*imgW+x] = s; - } + } } - } - - //Y - propagate reliable regions + } + + //Y - propagate reliable regions for( x = 0; x < imgW; x++ ) - { + { for( y = 0; y < imgH; y++ ) - { + { d = dest[y*widthStep+x]; if( reliabilities[y*imgW+x] >= param4 && !(edges[y*imgW+x] & 4) && d > 0 )//highly || moderately - { + { disparities[y*widthStep+x] = (uchar)d; //up propagation for( i = y - 1; i >= 0; i-- ) { if( ( edges[i*imgW+x] & 4 ) || - ( dest[i*widthStep+x] < d && + ( dest[i*widthStep+x] < d && reliabilities[i*imgW+x] >= param3 ) || - ( reliabilities[y*imgW+x] < param5 && + ( reliabilities[y*imgW+x] < param5 && dest[i*widthStep+x] - 1 == d ) ) break; - disparities[i*widthStep+x] = (uchar)d; - } - + disparities[i*widthStep+x] = (uchar)d; + } + //down propagation for( i = y + 1; i < imgH; i++ ) { if( ( edges[i*imgW+x] & 4 ) || - ( dest[i*widthStep+x] < d && + ( dest[i*widthStep+x] < d && reliabilities[i*imgW+x] >= param3 ) || - ( reliabilities[y*imgW+x] < param5 && + ( reliabilities[y*imgW+x] < param5 && dest[i*widthStep+x] - 1 == d ) ) break; disparities[i*widthStep+x] = (uchar)d; @@ -417,41 +417,41 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, for( ; x < imgW && dest[y*widthStep+x] == dest[y*widthStep+x-1]; x++ ); s = x - i; for( ; i < x; i++ ) - { + { reliabilities[y*imgW+i] = s; - } + } } - } - - //X - propagate reliable regions - for( y = 0; y < imgH; y++ ) - { + } + + //X - propagate reliable regions + for( y = 0; y < imgH; y++ ) + { for( x = 0; x < imgW; x++ ) - { + { d = dest[y*widthStep+x]; if( reliabilities[y*imgW+x] >= param4 && !(edges[y*imgW+x] & 1) && d > 0 )//highly || moderately - { + { disparities[y*widthStep+x] = (uchar)d; //up propagation for( i = x - 1; i >= 0; i-- ) { if( (edges[y*imgW+i] & 1) || - ( dest[y*widthStep+i] < d && + ( dest[y*widthStep+i] < d && reliabilities[y*imgW+i] >= param3 ) || - ( reliabilities[y*imgW+x] < param5 && + ( reliabilities[y*imgW+x] < param5 && dest[y*widthStep+i] - 1 == d ) ) break; disparities[y*widthStep+i] = (uchar)d; - } - + } + //down propagation for( i = x + 1; i < imgW; i++ ) { if( (edges[y*imgW+i] & 1) || - ( dest[y*widthStep+i] < d && + ( dest[y*widthStep+i] < d && reliabilities[y*imgW+i] >= param3 ) || - ( reliabilities[y*imgW+x] < param5 && + ( reliabilities[y*imgW+x] < param5 && dest[y*widthStep+i] - 1 == d ) ) break; disparities[y*widthStep+i] = (uchar)d; @@ -466,10 +466,10 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, } //release resources - cvFree( &dsi ); - cvFree( &edges ); - cvFree( &cells ); - cvFree( &rData ); + cvFree( &dsi ); + cvFree( &edges ); + cvFree( &cells ); + cvFree( &rData ); } @@ -483,7 +483,7 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, // rightImage - right image of stereo-pair (format 8uC1). // mode -mode of correspondance retrieval (now CV_RETR_DP_BIRCHFIELD only) // dispImage - destination disparity image -// maxDisparity - maximal disparity +// maxDisparity - maximal disparity // param1, param2, param3, param4, param5 - parameters of algorithm // Returns: // Notes: @@ -491,43 +491,43 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2, // All images must have format 8uC1. //F*/ CV_IMPL void -cvFindStereoCorrespondence( +cvFindStereoCorrespondence( const CvArr* leftImage, const CvArr* rightImage, int mode, CvArr* depthImage, - int maxDisparity, - double param1, double param2, double param3, + int maxDisparity, + double param1, double param2, double param3, double param4, double param5 ) -{ +{ CV_FUNCNAME( "cvFindStereoCorrespondence" ); __BEGIN__; - CvMat *src1, *src2; + CvMat *src1, *src2; CvMat *dst; CvMat src1_stub, src2_stub, dst_stub; - int coi; + int coi; CV_CALL( src1 = cvGetMat( leftImage, &src1_stub, &coi )); if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" ); CV_CALL( src2 = cvGetMat( rightImage, &src2_stub, &coi )); - if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" ); + if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" ); CV_CALL( dst = cvGetMat( depthImage, &dst_stub, &coi )); if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" ); - // check args - if( CV_MAT_TYPE( src1->type ) != CV_8UC1 || - CV_MAT_TYPE( src2->type ) != CV_8UC1 || + // check args + if( CV_MAT_TYPE( src1->type ) != CV_8UC1 || + CV_MAT_TYPE( src2->type ) != CV_8UC1 || CV_MAT_TYPE( dst->type ) != CV_8UC1) CV_ERROR(CV_StsUnsupportedFormat, - "All images must be single-channel and have 8u" ); + "All images must be single-channel and have 8u" ); if( !CV_ARE_SIZES_EQ( src1, src2 ) || !CV_ARE_SIZES_EQ( src1, dst ) ) CV_ERROR( CV_StsUnmatchedSizes, "" ); - + if( maxDisparity <= 0 || maxDisparity >= src1->width || maxDisparity > 255 ) - CV_ERROR(CV_StsOutOfRange, + CV_ERROR(CV_StsOutOfRange, "parameter /maxDisparity/ is out of range"); - + if( mode == CV_DISPARITY_BIRCHFIELD ) { if( param1 == CV_UNDEF_SC_PARAM ) param1 = CV_IDP_BIRCHFIELD_PARAM1; @@ -536,10 +536,10 @@ cvFindStereoCorrespondence( if( param4 == CV_UNDEF_SC_PARAM ) param4 = CV_IDP_BIRCHFIELD_PARAM4; if( param5 == CV_UNDEF_SC_PARAM ) param5 = CV_IDP_BIRCHFIELD_PARAM5; - CV_CALL( icvFindStereoCorrespondenceByBirchfieldDP( src1->data.ptr, - src2->data.ptr, dst->data.ptr, + CV_CALL( icvFindStereoCorrespondenceByBirchfieldDP( src1->data.ptr, + src2->data.ptr, dst->data.ptr, cvGetMatSize( src1 ), src1->step, - maxDisparity, (float)param1, (float)param2, (float)param3, + maxDisparity, (float)param1, (float)param2, (float)param3, (float)param4, (float)param5 ) ); } else @@ -547,7 +547,7 @@ cvFindStereoCorrespondence( CV_ERROR( CV_StsBadArg, "Unsupported mode of function" ); } - __END__; + __END__; } /* End of file. */ diff --git a/modules/legacy/src/eigenobjects.cpp b/modules/legacy/src/eigenobjects.cpp index 1276627..9025119 100644 --- a/modules/legacy/src/eigenobjects.cpp +++ b/modules/legacy/src/eigenobjects.cpp @@ -41,7 +41,7 @@ #include "precomp.hpp" -CvStatus CV_STDCALL +static CvStatus icvJacobiEigens_32f(float *A, float *V, float *E, int n, float eps) { int i, j, k, ind; diff --git a/modules/legacy/src/enteringblobdetection.cpp b/modules/legacy/src/enteringblobdetection.cpp index f39485f..24bc30d 100644 --- a/modules/legacy/src/enteringblobdetection.cpp +++ b/modules/legacy/src/enteringblobdetection.cpp @@ -83,7 +83,7 @@ static int CompareContour(const void* a, const void* b, void* ) return (dx < wt && dy < ht); } -void cvFindBlobsByCCClasters(IplImage* pFG, CvBlobSeq* pBlobs, CvMemStorage* storage) +static void cvFindBlobsByCCClasters(IplImage* pFG, CvBlobSeq* pBlobs, CvMemStorage* storage) { /* Create contours: */ IplImage* pIB = NULL; CvSeq* cnt = NULL; diff --git a/modules/legacy/src/enteringblobdetectionreal.cpp b/modules/legacy/src/enteringblobdetectionreal.cpp index c8a55f6..b0ec792 100644 --- a/modules/legacy/src/enteringblobdetectionreal.cpp +++ b/modules/legacy/src/enteringblobdetectionreal.cpp @@ -160,9 +160,5 @@ public: }; /* Blob detector constructor: */ -CvBlobDetector* cvCreateBlobDetectorReal(CvTestSeq* pTestSeq){return new CvBlobDetectorReal(pTestSeq);} - - - - +//CvBlobDetector* cvCreateBlobDetectorReal(CvTestSeq* pTestSeq){return new CvBlobDetectorReal(pTestSeq);} diff --git a/modules/legacy/src/epilines.cpp b/modules/legacy/src/epilines.cpp index 0f5b24e..fa6e7ce 100644 --- a/modules/legacy/src/epilines.cpp +++ b/modules/legacy/src/epilines.cpp @@ -106,7 +106,7 @@ int icvCompute3DPoint( double alpha,double betta, double invPartAll; double alphabetta = alpha*betta; - + partAll = alpha - betta; if( fabs(partAll) > 0.00001 ) /* alpha must be > betta */ { @@ -116,7 +116,7 @@ int icvCompute3DPoint( double alpha,double betta, partY = coeffs->Ycoef + coeffs->YcoefA *alpha + coeffs->YcoefB*betta + coeffs->YcoefAB*alphabetta; - + partZ = coeffs->Zcoef + coeffs->ZcoefA *alpha + coeffs->ZcoefB*betta + coeffs->ZcoefAB*alphabetta; @@ -159,12 +159,12 @@ int icvCreateConvertMatrVect( CvMatr64d rotMatr1, icvMulMatrix_64d( convRotMatr, 3,3, transVect2, - 1,3, + 1,3, tmpVect); - + icvSubVector_64d(transVect1,tmpVect,convTransVect,3); - + return CV_NO_ERR; } @@ -182,15 +182,15 @@ int icvConvertPointSystem(CvPoint3D64d M2, icvMulMatrix_64d( rotMatr, 3,3, (double*)&M2, - 1,3, + 1,3, tmpVect); icvAddVector_64d(tmpVect,transVect,(double*)M1,3); - + return CV_NO_ERR; } /*--------------------------------------------------------------------------------------*/ -int icvComputeCoeffForStereoV3( double quad1[4][2], +static int icvComputeCoeffForStereoV3( double quad1[4][2], double quad2[4][2], int numScanlines, CvMatr64d camMatr1, @@ -222,7 +222,7 @@ int icvComputeCoeffForStereoV3( double quad1[4][2], point2.x = (1.0 - alpha) * quad1[1][0] + alpha * quad1[2][0]; point2.y = (1.0 - alpha) * quad1[1][1] + alpha * quad1[2][1]; - + point3.x = (1.0 - alpha) * quad2[0][0] + alpha * quad2[3][0]; point3.y = (1.0 - alpha) * quad2[0][1] + alpha * quad2[3][1]; @@ -243,10 +243,10 @@ int icvComputeCoeffForStereoV3( double quad1[4][2], &startCoeffs[currLine], needSwapCamera); } - return CV_NO_ERR; + return CV_NO_ERR; } /*--------------------------------------------------------------------------------------*/ -int icvComputeCoeffForStereoNew( double quad1[4][2], +static int icvComputeCoeffForStereoNew( double quad1[4][2], double quad2[4][2], int numScanlines, CvMatr32f camMatr1, @@ -260,10 +260,10 @@ int icvComputeCoeffForStereoNew( double quad1[4][2], double camMatr1_64d[9]; double camMatr2_64d[9]; - + double rotMatr1_64d[9]; double transVect1_64d[3]; - + double rotMatr2_64d[9]; double transVect2_64d[3]; @@ -348,21 +348,21 @@ int icvComCoeffForLine( CvPoint2D64d point1, { /* Get direction for all points */ /* Direction for camera 1 */ - + CvPoint3D64f direct1; CvPoint3D64f direct2; CvPoint3D64f camPoint1; - + CvPoint3D64f directS3; CvPoint3D64f directS4; CvPoint3D64f direct3; CvPoint3D64f direct4; CvPoint3D64f camPoint2; - + icvGetDirectionForPoint( point1, camMatr1, &direct1); - + icvGetDirectionForPoint( point2, camMatr1, &direct2); @@ -372,13 +372,13 @@ int icvComCoeffForLine( CvPoint2D64d point1, icvGetDirectionForPoint( point3, camMatr2, &directS3); - + icvGetDirectionForPoint( point4, camMatr2, &directS4); /* Create convertion for camera 2: two direction and camera point */ - + double convRotMatr[9]; double convTransVect[3]; @@ -392,15 +392,15 @@ int icvComCoeffForLine( CvPoint2D64d point1, CvPoint3D64f zeroVect; zeroVect.x = zeroVect.y = zeroVect.z = 0.0; camPoint1.x = camPoint1.y = camPoint1.z = 0.0; - + icvConvertPointSystem(directS3,&direct3,convRotMatr,convTransVect); icvConvertPointSystem(directS4,&direct4,convRotMatr,convTransVect); icvConvertPointSystem(zeroVect,&camPoint2,convRotMatr,convTransVect); CvPoint3D64f pointB; - + int postype = 0; - + /* Changed order */ /* Compute point B: xB,yB,zB */ icvGetCrossLines(camPoint1,direct2, @@ -449,7 +449,7 @@ int icvComCoeffForLine( CvPoint2D64d point1, double gamma; - + double xA,yA,zA; double xB,yB,zB; double xC,yC,zC; @@ -476,7 +476,7 @@ int icvComCoeffForLine( CvPoint2D64d point1, camPoint1, gamma, coeffs); - + return CV_NO_ERR; } @@ -489,7 +489,7 @@ int icvGetDirectionForPoint( CvPoint2D64d point, { /* */ double invMatr[9]; - + /* Invert matrix */ icvInvertMatrix_64d(camMatr,3,invMatr); @@ -504,10 +504,10 @@ int icvGetDirectionForPoint( CvPoint2D64d point, icvMulMatrix_64d( invMatr, 3,3, vect, - 1,3, + 1,3, (double*)direct); - return CV_NO_ERR; + return CV_NO_ERR; } /*--------------------------------------------------------------------------------------*/ @@ -556,7 +556,7 @@ int icvGetCrossLines(CvPoint3D64d point11,CvPoint3D64d point12, double alpha,betta; delta = a11*a22-a12*a21; - + if( fabs(delta) < EPS64D ) { /*return ERROR;*/ @@ -662,7 +662,7 @@ int icvGetAngleLine( CvPoint2D64d startPoint, CvSize imageSize,CvPoint2D64d *poi /* Find four lines */ CvPoint2D64d pa,pb,pc,pd; - + pa.x = 0; pa.y = 0; @@ -674,10 +674,10 @@ int icvGetAngleLine( CvPoint2D64d startPoint, CvSize imageSize,CvPoint2D64d *poi pc.x = 0; pc.y = imageSize.height-1; - + /* We can compute points for angle */ /* Test for place section */ - + if( startPoint.x < 0 ) {/* 1,4,7 */ if( startPoint.y < 0) @@ -782,7 +782,7 @@ void icvGetCoefForPiece( CvPoint2D64d p_start,CvPoint2D64d p_end, /*---------------------------------------------------------------------------------------*/ /* Get common area of rectifying */ -void icvGetCommonArea( CvSize imageSize, +static void icvGetCommonArea( CvSize imageSize, CvPoint3D64d epipole1,CvPoint3D64d epipole2, CvMatr64d fundMatr, CvVect64d coeff11,CvVect64d coeff12, @@ -808,10 +808,10 @@ void icvGetCommonArea( CvSize imageSize, double transFundMatr[3*3]; /* Compute transpose of fundamental matrix */ icvTransposeMatrix_64d( fundMatr, 3, 3, transFundMatr ); - + CvPoint2D64d epipole1_2d; CvPoint2D64d epipole2_2d; - + if( fabs(epipole1.z) < 1e-8 ) {/* epipole1 in infinity */ *result = 0; @@ -853,7 +853,7 @@ void icvGetCommonArea( CvSize imageSize, pointW11[2] = 1.0; icvTransformVector_64d( transFundMatr, /* !!! Modified from not transposed */ - pointW11, + pointW11, corr21, 3,3); @@ -864,7 +864,7 @@ void icvGetCommonArea( CvSize imageSize, corr21[0],corr21[1],corr21[2], &start,&end, &res); - + if( res == 0 ) {/* We have not cross */ /* We must define new angle */ @@ -879,7 +879,7 @@ void icvGetCommonArea( CvSize imageSize, /* corr11 = Fund * p21 */ icvTransformVector_64d( fundMatr, /* !!! Modified */ - pointW21, + pointW21, corr11, 3,3); @@ -889,7 +889,7 @@ void icvGetCommonArea( CvSize imageSize, coeff11[0] = corr11[0]; coeff11[1] = corr11[1]; coeff11[2] = corr11[2]; - + /* Set coefs for line 1 image 2 */ icvGetCoefForPiece( epipole2_2d,point21, &coeff21[0],&coeff21[1],&coeff21[2], @@ -911,12 +911,12 @@ void icvGetCommonArea( CvSize imageSize, *result = 0; return;/* Error */ } - + /* Set coefs for line 1 image 2 */ coeff21[0] = corr21[0]; coeff21[1] = corr21[1]; coeff21[2] = corr21[2]; - + } /* ============= Computation for line 2 ================ */ @@ -928,7 +928,7 @@ void icvGetCommonArea( CvSize imageSize, pointW12[2] = 1.0; icvTransformVector_64d( transFundMatr, - pointW12, + pointW12, corr22, 3,3); @@ -937,7 +937,7 @@ void icvGetCommonArea( CvSize imageSize, corr22[0],corr22[1],corr22[2], &start,&end, &res); - + if( res == 0 ) {/* We have not cross */ /* We must define new angle */ @@ -952,18 +952,18 @@ void icvGetCommonArea( CvSize imageSize, /* corr2 = Fund' * p1 */ icvTransformVector_64d( fundMatr, - pointW22, + pointW22, corr12, 3,3); - + /* We have cross. And it's result cross for down line. Set result coefs */ /* Set coefs for line 2 image 1 */ coeff12[0] = corr12[0]; coeff12[1] = corr12[1]; coeff12[2] = corr12[2]; - + /* Set coefs for line 1 image 2 */ icvGetCoefForPiece( epipole2_2d,point22, &coeff22[0],&coeff22[1],&coeff22[2], @@ -985,12 +985,12 @@ void icvGetCommonArea( CvSize imageSize, *result = 0; return;/* Error */ } - + /* Set coefs for line 1 image 2 */ coeff22[0] = corr22[0]; coeff22[1] = corr22[1]; coeff22[2] = corr22[2]; - + } /* Now we know common area */ @@ -1050,9 +1050,9 @@ void icvGetCrossPieceDirect( CvPoint2D64d p_start,CvPoint2D64d p_end, {/* Have cross */ double det; double detxc,detyc; - + det = a * (p_end.x - p_start.x) + b * (p_end.y - p_start.y); - + if( fabs(det) < EPS64D ) {/* lines are parallel and may be equal or line is point */ if( fabs(a*p_start.x + b*p_start.y + c) < EPS64D ) @@ -1062,7 +1062,7 @@ void icvGetCrossPieceDirect( CvPoint2D64d p_start,CvPoint2D64d p_end, } else { - *result = 2; + *result = 2; } return; } @@ -1131,7 +1131,7 @@ void icvGetCrossPiecePiece( CvPoint2D64d p1_start,CvPoint2D64d p1_end, cross->x = delX / del; cross->y = delY / del; - + *result = 1; return; } @@ -1171,7 +1171,7 @@ void icvGetCrossRectDirect( CvSize imageSize, CvPoint2D64d frameEnd; CvPoint2D64d cross[4]; int haveCross[4]; - + haveCross[0] = 0; haveCross[1] = 0; haveCross[2] = 0; @@ -1182,25 +1182,25 @@ void icvGetCrossRectDirect( CvSize imageSize, frameEnd.x = imageSize.width; frameEnd.y = 0; - icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[0],&haveCross[0]); - + icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[0],&haveCross[0]); + frameBeg.x = imageSize.width; frameBeg.y = 0; frameEnd.x = imageSize.width; frameEnd.y = imageSize.height; - icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[1],&haveCross[1]); + icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[1],&haveCross[1]); frameBeg.x = imageSize.width; frameBeg.y = imageSize.height; frameEnd.x = 0; frameEnd.y = imageSize.height; - icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[2],&haveCross[2]); + icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[2],&haveCross[2]); frameBeg.x = 0; frameBeg.y = imageSize.height; frameEnd.x = 0; frameEnd.y = 0; - icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[3],&haveCross[3]); + icvGetCrossPieceDirect(frameBeg,frameEnd,a,b,c,&cross[3],&haveCross[3]); double maxDist; @@ -1210,7 +1210,7 @@ void icvGetCrossRectDirect( CvSize imageSize, int i,j; maxDist = -1.0; - + double distance; for( i = 0; i < 3; i++ ) @@ -1259,7 +1259,7 @@ void icvProjectPointToImage( CvPoint3D64d point, double tmpVect1[3]; double tmpVect2[3]; - + icvMulMatrix_64d ( rotMatr, 3,3, (double*)&point, @@ -1276,13 +1276,13 @@ void icvProjectPointToImage( CvPoint3D64d point, projPoint->x = tmpVect1[0] / tmpVect1[2]; projPoint->y = tmpVect1[1] / tmpVect1[2]; - + return; } /*---------------------------------------------------------------------------------------*/ /* Get quads for transform images */ -void icvGetQuadsTransform( +void icvGetQuadsTransform( CvSize imageSize, CvMatr64d camMatr1, CvMatr64d rotMatr1, @@ -1338,10 +1338,10 @@ void icvGetQuadsTransform( fundMatr_32f, camMatr1_32f, camMatr2_32f); - + CvPoint3D32f epipole1_32f; CvPoint3D32f epipole2_32f; - + cvComputeEpipolesFromFundMatrix( fundMatr_32f, &epipole1_32f, &epipole2_32f); @@ -1353,7 +1353,7 @@ void icvGetQuadsTransform( epipole2->x = epipole2_32f.x; epipole2->y = epipole2_32f.y; epipole2->z = epipole2_32f.z; - + /* Convert fundamental matrix */ icvCvt_32f_64d(fundMatr_32f,fundMatr,9); } @@ -1466,7 +1466,7 @@ void icvGetQuadsTransform( /* -------------Compute for first image-------------- */ CvPoint2D32f pointb1; CvPoint2D32f pointe1; - + CvPoint2D32f pointb2; CvPoint2D32f pointe2; @@ -1494,11 +1494,11 @@ void icvGetQuadsTransform( double dxOld,dyOld; double dxNew,dyNew; double distOld,distNew; - + dxOld = quad2[1][0] - quad2[0][0]; dyOld = quad2[1][1] - quad2[0][1]; distOld = dxOld*dxOld + dyOld*dyOld; - + dxNew = quad2[1][0] - pointb2.x; dyNew = quad2[1][1] - pointb2.y; distNew = dxNew*dxNew + dyNew*dyNew; @@ -1542,7 +1542,7 @@ void icvGetQuadsTransform( newQuad2[0][1] = quad2[0][1]; newQuad2[3][0] = quad2[3][0]; newQuad2[3][1] = quad2[3][1]; - + newQuad1[0][0] = pointb1.x; newQuad1[0][1] = pointb1.y; newQuad1[3][0] = pointe1.x; @@ -1569,11 +1569,11 @@ void icvGetQuadsTransform( &pointe2); /* Compute distances */ - + dxOld = quad2[0][0] - quad2[1][0]; dyOld = quad2[0][1] - quad2[1][1]; distOld = dxOld*dxOld + dyOld*dyOld; - + dxNew = quad2[0][0] - pointb2.x; dyNew = quad2[0][1] - pointb2.y; distNew = dxNew*dxNew + dyNew*dyNew; @@ -1614,7 +1614,7 @@ void icvGetQuadsTransform( newQuad2[1][1] = quad2[1][1]; newQuad2[2][0] = quad2[2][0]; newQuad2[2][1] = quad2[2][1]; - + newQuad1[1][0] = pointb1.x; newQuad1[1][1] = pointb1.y; newQuad1[2][0] = pointe1.x; @@ -1660,7 +1660,7 @@ void icvGetQuadsTransform( /*---------------------------------------------------------------------------------------*/ -void icvGetQuadsTransformNew( CvSize imageSize, +static void icvGetQuadsTransformNew( CvSize imageSize, CvMatr32f camMatr1, CvMatr32f camMatr2, CvMatr32f rotMatr1, @@ -1732,7 +1732,7 @@ void icvGetQuadsTransformNew( CvSize imageSize, /* Convert fundamental matrix */ icvCvt_64d_32f(fundMatr_64d,fundMatr,9); - + return; } @@ -1771,7 +1771,7 @@ void icvGetQuadsTransformStruct( CvStereoCamera* stereoCamera) /*---------------------------------------------------------------------------------------*/ void icvComputeStereoParamsForCameras(CvStereoCamera* stereoCamera) { - /* For given intrinsic and extrinsic parameters computes rest parameters + /* For given intrinsic and extrinsic parameters computes rest parameters ** such as fundamental matrix. warping coeffs, epipoles, ... */ @@ -1792,14 +1792,14 @@ void icvComputeStereoParamsForCameras(CvStereoCamera* stereoCamera) icvCvt_32f_64d(stereoCamera->camera[0]->transVect,transVect1,3); icvCvt_32f_64d(stereoCamera->camera[1]->transVect,transVect2,3); - + icvCreateConvertMatrVect( rotMatr1, transVect1, rotMatr2, transVect2, convRotMatr, convTransVect); - + /* copy to stereo camera params */ icvCvt_64d_32f(convRotMatr,stereoCamera->rotMatrix,9); icvCvt_64d_32f(convTransVect,stereoCamera->transVector,3); @@ -1837,7 +1837,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, /* Find middle line of sector */ double midLine[3]={0,0,0}; - + /* Different way */ CvPoint2D64d pointOnLine1; pointOnLine1.x = pointOnLine1.y = 0; CvPoint2D64d pointOnLine2; pointOnLine2.x = pointOnLine2.y = 0; @@ -1885,7 +1885,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, candPoints[numPoints] = cornerPoint; numPoints++; } - + cornerPoint.x = imageSize.width; cornerPoint.y = imageSize.height; icvTestPoint( cornerPoint, areaLineCoef1, areaLineCoef2, epipole, &res); @@ -1919,7 +1919,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, areaLineCoef2[0],areaLineCoef2[1],areaLineCoef2[2], &tmpPoints[0], &tmpPoints[1], &res); - + for( i = 0; i < res; i++ ) { candPoints[numPoints++] = tmpPoints[i]; @@ -1941,7 +1941,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, double maxDist = 0; double minDist = 10000000; - + for( i = 0; i < numPoints; i++ ) { icvProjectPointToDirect(candPoints[i], midLine, &projPoint); @@ -1960,7 +1960,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, } /* We know maximum and minimum points. Now we can compute cut lines */ - + icvGetNormalDirect(midLine,minPoint,cutLine1); icvGetNormalDirect(midLine,maxPoint,cutLine2); @@ -1993,7 +1993,7 @@ void icvGetMiddleAnglePoint( CvPoint2D64d basePoint, CvPoint2D64d point1,CvPoint2D64d point2, CvPoint2D64d* midPoint) {/* !!! May be need to return error */ - + double dist1; double dist2; icvGetPieceLength(basePoint,point1,&dist1); @@ -2020,7 +2020,7 @@ void icvGetNormalDirect(CvVect64d direct,CvPoint2D64d point,CvVect64d normDirect { normDirect[0] = direct[1]; normDirect[1] = - direct[0]; - normDirect[2] = -(normDirect[0]*point.x + normDirect[1]*point.y); + normDirect[2] = -(normDirect[0]*point.x + normDirect[1]*point.y); return; } @@ -2063,7 +2063,7 @@ void icvTestPoint( CvPoint2D64d testPoint, { *result = 0; } - + return; } @@ -2074,7 +2074,7 @@ void icvProjectPointToDirect( CvPoint2D64d point,CvVect64d lineCoeff, { double a = lineCoeff[0]; double b = lineCoeff[1]; - + double det = 1.0 / ( a*a + b*b ); double delta = a*point.y - b*point.x; @@ -2103,7 +2103,7 @@ CV_IMPL IplImage* icvCreateIsometricImage( IplImage* src, IplImage* dst, CvSize src_size ; src_size.width = src->width; src_size.height = src->height; - + CvSize dst_size = src_size; if( dst ) @@ -2127,7 +2127,7 @@ CV_IMPL IplImage* icvCreateIsometricImage( IplImage* src, IplImage* dst, return dst; } -int +static int icvCvt_32f_64d( float *src, double *dst, int size ) { int t; @@ -2147,7 +2147,7 @@ icvCvt_32f_64d( float *src, double *dst, int size ) /*======================================================================================*/ /* Type conversion double -> float */ -int +static int icvCvt_64d_32f( double *src, float *dst, int size ) { int t; @@ -2167,9 +2167,9 @@ icvCvt_64d_32f( double *src, float *dst, int size ) /*----------------------------------------------------------------------------------*/ - +#if 0 /* Find line which cross frame by line(a,b,c) */ -void FindLineForEpiline( CvSize imageSize, +static void FindLineForEpiline( CvSize imageSize, float a,float b,float c, CvPoint2D32f *start,CvPoint2D32f *end, int*) @@ -2191,7 +2191,7 @@ void FindLineForEpiline( CvSize imageSize, frameEnd.x = (float)(imageSize.width); frameEnd.y = 0; haveCross[0] = icvGetCrossLineDirect(frameBeg,frameEnd,a,b,c,&cross[0]); - + frameBeg.x = (float)(imageSize.width); frameBeg.y = 0; frameEnd.x = (float)(imageSize.width); @@ -2203,7 +2203,7 @@ void FindLineForEpiline( CvSize imageSize, frameEnd.x = 0; frameEnd.y = (float)(imageSize.height); haveCross[2] = icvGetCrossLineDirect(frameBeg,frameEnd,a,b,c,&cross[2]); - + frameBeg.x = 0; frameBeg.y = (float)(imageSize.height); frameEnd.x = 0; @@ -2255,13 +2255,12 @@ void FindLineForEpiline( CvSize imageSize, } return; - + } /*----------------------------------------------------------------------------------*/ - -int GetAngleLinee( CvPoint2D32f epipole, CvSize imageSize,CvPoint2D32f point1,CvPoint2D32f point2) +static int GetAngleLinee( CvPoint2D32f epipole, CvSize imageSize,CvPoint2D32f point1,CvPoint2D32f point2) { float width = (float)(imageSize.width); float height = (float)(imageSize.height); @@ -2271,7 +2270,7 @@ int GetAngleLinee( CvPoint2D32f epipole, CvSize imageSize,CvPoint2D32f point1,Cv /* Find four lines */ CvPoint2D32f pa,pb,pc,pd; - + pa.x = 0; pa.y = 0; @@ -2290,7 +2289,7 @@ int GetAngleLinee( CvPoint2D32f epipole, CvSize imageSize,CvPoint2D32f point1,Cv float x,y; x = epipole.x; y = epipole.y; - + if( x < 0 ) {/* 1,4,7 */ if( y < 0) @@ -2344,15 +2343,15 @@ int GetAngleLinee( CvPoint2D32f epipole, CvSize imageSize,CvPoint2D32f point1,Cv return 2; } - + } - + return 0; } /*--------------------------------------------------------------------------------------*/ -void icvComputePerspectiveCoeffs(const CvPoint2D32f srcQuad[4],const CvPoint2D32f dstQuad[4],double coeffs[3][3]) +static void icvComputePerspectiveCoeffs(const CvPoint2D32f srcQuad[4],const CvPoint2D32f dstQuad[4],double coeffs[3][3]) {/* Computes perspective coeffs for transformation from src to dst quad */ @@ -2385,7 +2384,7 @@ void icvComputePerspectiveCoeffs(const CvPoint2D32f srcQuad[4],const CvPoint2D32 double Y = dstQuad[i].y; #endif double* a = A + i*16; - + a[0] = x; a[1] = y; a[2] = 1; @@ -2420,7 +2419,7 @@ void icvComputePerspectiveCoeffs(const CvPoint2D32f srcQuad[4],const CvPoint2D32 CV_CALL( cvPseudoInverse( &matA, &matInvA )); CV_CALL( cvMatMulAdd( &matInvA, &matB, 0, &matX )); } - + coeffs[0][0] = c[0]; coeffs[0][1] = c[1]; coeffs[0][2] = c[2]; @@ -2435,6 +2434,7 @@ void icvComputePerspectiveCoeffs(const CvPoint2D32f srcQuad[4],const CvPoint2D32 return; } +#endif /*--------------------------------------------------------------------------------------*/ @@ -2457,7 +2457,7 @@ CV_IMPL void cvComputePerspectiveMap(const double c[3][3], CvArr* rectMapX, CvAr size = cvGetMatSize(mapx); assert( fabs(c[2][2] - 1.) < FLT_EPSILON ); - + for( i = 0; i < size.height; i++ ) { float* mx = (float*)(mapx->data.ptr + mapx->step*i); @@ -2525,7 +2525,7 @@ CV_IMPL void cvInitPerspectiveTransform( CvSize size, const CvPoint2D32f quad[4] double Y = quad[i].y; #endif double* a = A + i*16; - + a[0] = x; a[1] = y; a[2] = 1; @@ -2560,7 +2560,7 @@ CV_IMPL void cvInitPerspectiveTransform( CvSize size, const CvPoint2D32f quad[4] CV_CALL( cvPseudoInverse( &matA, &matInvA )); CV_CALL( cvMatMulAdd( &matInvA, &matB, 0, &matX )); } - + matrix[0][0] = c[0]; matrix[0][1] = c[1]; matrix[0][2] = c[2]; @@ -2613,7 +2613,7 @@ void icvComputeeInfiniteProject1( CvMatr64d rotMatr, icvMulMatrix_64d( invMatr1, 3,3, p1, - 1,3, + 1,3, P1); double invR[9]; @@ -2624,7 +2624,7 @@ void icvComputeeInfiniteProject1( CvMatr64d rotMatr, icvMulMatrix_64d( invR, 3,3, P1, - 1,3, + 1,3, P2); /* Now we can project this point to image 2 */ @@ -2633,7 +2633,7 @@ void icvComputeeInfiniteProject1( CvMatr64d rotMatr, icvMulMatrix_64d( camMatr2, 3,3, P2, - 1,3, + 1,3, projP); point2->x = (float)(projP[0] / projP[2]); @@ -2661,7 +2661,7 @@ void icvComputeeInfiniteProject2( CvMatr64d rotMatr, icvMulMatrix_64d( invMatr2, 3,3, p2, - 1,3, + 1,3, P2); /* Change system 1 to system 2 */ @@ -2670,7 +2670,7 @@ void icvComputeeInfiniteProject2( CvMatr64d rotMatr, icvMulMatrix_64d( rotMatr, 3,3, P2, - 1,3, + 1,3, P1); /* Now we can project this point to image 2 */ @@ -2679,7 +2679,7 @@ void icvComputeeInfiniteProject2( CvMatr64d rotMatr, icvMulMatrix_64d( camMatr1, 3,3, P1, - 1,3, + 1,3, projP); point1->x = (float)(projP[0] / projP[2]); @@ -2690,7 +2690,7 @@ void icvComputeeInfiniteProject2( CvMatr64d rotMatr, /* Select best R and t for given cameras, points, ... */ /* For both cameras */ -int icvSelectBestRt( int numImages, +static int icvSelectBestRt( int numImages, int* numPoints, CvPoint2D32f* imagePoints1, CvPoint2D32f* imagePoints2, @@ -2713,7 +2713,7 @@ int icvSelectBestRt( int numImages, /* Need to convert input data 32 -> 64 */ CvPoint3D64d* objectPoints_64d; - + double* rotMatrs1_64d; double* rotMatrs2_64d; @@ -2736,7 +2736,7 @@ int icvSelectBestRt( int numImages, } objectPoints_64d = (CvPoint3D64d*)calloc(totalNum,sizeof(CvPoint3D64d)); - + rotMatrs1_64d = (double*)calloc(numImages,sizeof(double)*9); rotMatrs2_64d = (double*)calloc(numImages,sizeof(double)*9); @@ -2744,7 +2744,7 @@ int icvSelectBestRt( int numImages, transVects2_64d = (double*)calloc(numImages,sizeof(double)*3); /* Convert input data to 64d */ - + icvCvt_32f_64d((float*)objectPoints, (double*)objectPoints_64d, totalNum*3); icvCvt_32f_64d(rotMatrs1, rotMatrs1_64d, numImages*9); @@ -2774,14 +2774,14 @@ int icvSelectBestRt( int numImages, int currRt; for( currRt = 0; currRt < numImages; currRt++ ) { - int begPoint = 0; + int begPoint = 0; for(currImagePair = 0; currImagePair < numImages; currImagePair++ ) { /* For current R,t R,t compute relative position of cameras */ double convRotMatr[9]; double convTransVect[3]; - + icvCreateConvertMatrVect( rotMatrs1_64d + currRt*9, transVects1_64d + currRt*3, rotMatrs2_64d + currRt*9, @@ -2836,7 +2836,7 @@ int icvSelectBestRt( int numImages, tmpPoint.x = (double)(objectPoints[i].x); tmpPoint.y = (double)(objectPoints[i].y); tmpPoint.z = (double)(objectPoints[i].z); - + icvConvertPointSystem( tmpPoint, points2+i, rotMatrs2_64d + currImagePair*9, @@ -2862,7 +2862,7 @@ int icvSelectBestRt( int numImages, } - + #if 0 cvProjectPointsSimple( numPoints[currImagePair], objectPoints_64d + begPoint, @@ -2901,7 +2901,7 @@ int icvSelectBestRt( int numImages, cameraMatrix2_64d, nodist, projImagePoints2); - + } #endif @@ -2929,7 +2929,7 @@ int icvSelectBestRt( int numImages, double err; for( currPoint = 0; currPoint < numberPnt; currPoint++ ) { - double len1,len2; + double len1,len2; double dx1,dy1; dx1 = imagePoints1[begPoint+currPoint].x - projImagePoints1[currPoint].x; dy1 = imagePoints1[begPoint+currPoint].y - projImagePoints1[currPoint].y; @@ -3030,12 +3030,12 @@ int icvConvertWarpCoordinates(double coeffs[3][3], int direction) { double x,y; - double det; + double det; if( direction == CV_WARP_TO_CAMERA ) {/* convert from camera image to warped image coordinates */ x = warpPoint->x; y = warpPoint->y; - + det = (coeffs[2][0] * x + coeffs[2][1] * y + coeffs[2][2]); if( fabs(det) > 1e-8 ) { @@ -3058,7 +3058,7 @@ int icvConvertWarpCoordinates(double coeffs[3][3], return CV_OK; } } - + return CV_BADFACTOR_ERR; } @@ -3233,8 +3233,9 @@ int icvStereoCalibration( int numImages, return CV_NO_ERR; } +#if 0 /* Find line from epipole */ -void FindLine(CvPoint2D32f epipole,CvSize imageSize,CvPoint2D32f point,CvPoint2D32f *start,CvPoint2D32f *end) +static void FindLine(CvPoint2D32f epipole,CvSize imageSize,CvPoint2D32f point,CvPoint2D32f *start,CvPoint2D32f *end) { CvPoint2D32f frameBeg; CvPoint2D32f frameEnd; @@ -3252,7 +3253,7 @@ void FindLine(CvPoint2D32f epipole,CvSize imageSize,CvPoint2D32f point,CvPoint2D frameEnd.x = (float)(imageSize.width); frameEnd.y = 0; haveCross[0] = icvGetCrossPieceVector(frameBeg,frameEnd,epipole,point,&cross[0]); - + frameBeg.x = (float)(imageSize.width); frameBeg.y = 0; frameEnd.x = (float)(imageSize.width); @@ -3264,7 +3265,7 @@ void FindLine(CvPoint2D32f epipole,CvSize imageSize,CvPoint2D32f point,CvPoint2D frameEnd.x = 0; frameEnd.y = (float)(imageSize.height); haveCross[2] = icvGetCrossPieceVector(frameBeg,frameEnd,epipole,point,&cross[2]); - + frameBeg.x = 0; frameBeg.y = (float)(imageSize.height); frameEnd.x = 0; @@ -3277,7 +3278,7 @@ void FindLine(CvPoint2D32f epipole,CvSize imageSize,CvPoint2D32f point,CvPoint2D int maxN = -1; int minN = -1; - + for( n = 0; n < 4; n++ ) { if( haveCross[n] > 0 ) @@ -3315,9 +3316,8 @@ void FindLine(CvPoint2D32f epipole,CvSize imageSize,CvPoint2D32f point,CvPoint2D return; } - /* Find line which cross frame by line(a,b,c) */ -void FindLineForEpiline(CvSize imageSize,float a,float b,float c,CvPoint2D32f *start,CvPoint2D32f *end) +static void FindLineForEpiline(CvSize imageSize,float a,float b,float c,CvPoint2D32f *start,CvPoint2D32f *end) { CvPoint2D32f frameBeg; CvPoint2D32f frameEnd; @@ -3335,7 +3335,7 @@ void FindLineForEpiline(CvSize imageSize,float a,float b,float c,CvPoint2D32f *s frameEnd.x = (float)(imageSize.width); frameEnd.y = 0; haveCross[0] = icvGetCrossLineDirect(frameBeg,frameEnd,a,b,c,&cross[0]); - + frameBeg.x = (float)(imageSize.width); frameBeg.y = 0; frameEnd.x = (float)(imageSize.width); @@ -3347,7 +3347,7 @@ void FindLineForEpiline(CvSize imageSize,float a,float b,float c,CvPoint2D32f *s frameEnd.x = 0; frameEnd.y = (float)(imageSize.height); haveCross[2] = icvGetCrossLineDirect(frameBeg,frameEnd,a,b,c,&cross[2]); - + frameBeg.x = 0; frameBeg.y = (float)(imageSize.height); frameEnd.x = 0; @@ -3399,11 +3399,11 @@ void FindLineForEpiline(CvSize imageSize,float a,float b,float c,CvPoint2D32f *s } return; - + } /* Cross lines */ -int GetCrossLines(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f p2_start,CvPoint2D32f p2_end,CvPoint2D32f *cross) +static int GetCrossLines(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f p2_start,CvPoint2D32f p2_end,CvPoint2D32f *cross) { double ex1,ey1,ex2,ey2; double px1,py1,px2,py2; @@ -3448,7 +3448,7 @@ int GetCrossLines(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f p2_star cross->y = (float)(-delY / del); return 1; } - +#endif int icvGetCrossPieceVector(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f v2_start,CvPoint2D32f v2_end,CvPoint2D32f *cross) { @@ -3527,11 +3527,12 @@ int icvGetCrossLineDirect(CvPoint2D32f p1,CvPoint2D32f p2,float a,float b,float cross->x = (float)X; cross->y = (float)Y; - + return 1; } -int cvComputeEpipoles( CvMatr32f camMatr1, CvMatr32f camMatr2, +#if 0 +static int cvComputeEpipoles( CvMatr32f camMatr1, CvMatr32f camMatr2, CvMatr32f rotMatr1, CvMatr32f rotMatr2, CvVect32f transVect1,CvVect32f transVect2, CvVect32f epipole1, @@ -3571,7 +3572,7 @@ int cvComputeEpipoles( CvMatr32f camMatr1, CvMatr32f camMatr2, cvmMul( &ccamMatr1, &crotMatr1, &cmatrP1); cvmInvert( &cmatrP1,&cinvP1 ); cvmMul( &ccamMatr1, &ctransVect1, &cvectp1 ); - + /* Compute second */ cvmMul( &ccamMatr2, &crotMatr2, &cmatrP2 ); cvmInvert( &cmatrP2,&cinvP2 ); @@ -3610,7 +3611,7 @@ int cvComputeEpipoles( CvMatr32f camMatr1, CvMatr32f camMatr2, return CV_NO_ERR; }/* cvComputeEpipoles */ - +#endif /* Compute epipoles for fundamental matrix */ int cvComputeEpipolesFromFundMatrix(CvMatr32f fundMatr, @@ -3632,7 +3633,7 @@ int cvComputeEpipolesFromFundMatrix(CvMatr32f fundMatr, epipole1->x = matrU->data.fl[6]; epipole1->y = matrU->data.fl[7]; epipole1->z = matrU->data.fl[8]; - + /* Get last row from V' and compute epipole2 */ epipole2->x = matrV->data.fl[6]; epipole2->y = matrV->data.fl[7]; @@ -3640,7 +3641,7 @@ int cvComputeEpipolesFromFundMatrix(CvMatr32f fundMatr, cvReleaseMat(&matrW); cvReleaseMat(&matrU); - cvReleaseMat(&matrV); + cvReleaseMat(&matrV); return CV_OK; } @@ -3660,7 +3661,7 @@ int cvConvertEssential2Fundamental( CvMatr32f essMatr, CvMat* invCM1T = cvCreateMat(3,3,CV_MAT32F); cvTranspose(&cameraMatr1C,tmpMatr); - cvInvert(tmpMatr,invCM1T); + cvInvert(tmpMatr,invCM1T); cvmMul(invCM1T,&essMatrC,tmpMatr); cvInvert(&cameraMatr2C,invCM2); cvmMul(tmpMatr,invCM2,&fundMatrC); @@ -3673,7 +3674,7 @@ int cvConvertEssential2Fundamental( CvMatr32f essMatr, cvReleaseMat(&invCM2); cvReleaseMat(&tmpMatr); cvReleaseMat(&invCM1T); - + return CV_OK; } @@ -3689,11 +3690,11 @@ int cvComputeEssentialMatrix( CvMatr32f rotMatr, transMatr[0] = 0; transMatr[1] = - transVect[2]; transMatr[2] = transVect[1]; - + transMatr[3] = transVect[2]; transMatr[4] = 0; transMatr[5] = - transVect[0]; - + transMatr[6] = - transVect[1]; transMatr[7] = transVect[0]; transMatr[8] = 0; diff --git a/modules/legacy/src/kdtree.cpp b/modules/legacy/src/kdtree.cpp index 2cfed90..1e9abf7 100644 --- a/modules/legacy/src/kdtree.cpp +++ b/modules/legacy/src/kdtree.cpp @@ -48,7 +48,7 @@ #include "_kdtree.hpp" #include "_featuretree.h" -#if _MSC_VER >= 1400 +#if defined _MSC_VER && _MSC_VER >= 1400 #pragma warning(disable:4996) // suppress "function call with parameters may be unsafe" in std::copy #endif @@ -95,7 +95,7 @@ class CvKDTreeWrap : public CvFeatureTree { for (int j = 0; j < d->rows; ++j) { const typename __treetype::scalar_type* dj = - (const typename __treetype::scalar_type*) dptr; + (const typename __treetype::scalar_type*) dptr; int* resultsj = (int*) resultsptr; double* distj = (double*) distptr; @@ -103,8 +103,8 @@ class CvKDTreeWrap : public CvFeatureTree { assert((int)nn.size() <= k); for (unsigned int j = 0; j < nn.size(); ++j) { - *resultsj++ = *nn[j].p; - *distj++ = nn[j].dist; + *resultsj++ = *nn[j].p; + *distj++ = nn[j].dist; } std::fill(resultsj, resultsj + k - nn.size(), -1); std::fill(distj, distj + k - nn.size(), 0); @@ -117,16 +117,16 @@ class CvKDTreeWrap : public CvFeatureTree { template int find_ortho_range(CvMat* bounds_min, CvMat* bounds_max, - CvMat* results) { + CvMat* results) { int rn = results->rows * results->cols; std::vector inbounds; dispatch_cvtype(mat, ((__treetype*)data)-> - find_ortho_range((typename __treetype::scalar_type*)bounds_min->data.ptr, - (typename __treetype::scalar_type*)bounds_max->data.ptr, - inbounds)); + find_ortho_range((typename __treetype::scalar_type*)bounds_min->data.ptr, + (typename __treetype::scalar_type*)bounds_max->data.ptr, + inbounds)); std::copy(inbounds.begin(), - inbounds.begin() + std::min((int)inbounds.size(), rn), - (int*) results->data.ptr); + inbounds.begin() + std::min((int)inbounds.size(), rn), + (int*) results->data.ptr); return (int)inbounds.size(); } @@ -135,7 +135,7 @@ class CvKDTreeWrap : public CvFeatureTree { public: CvKDTreeWrap(CvMat* _mat) : mat(_mat) { // * a flag parameter should tell us whether - // * (a) user ensures *mat outlives *this and is unchanged, + // * (a) user ensures *mat outlives *this and is unchanged, // * (b) we take reference and user ensures mat is unchanged, // * (c) we copy data, (d) we own and release data. @@ -144,8 +144,8 @@ public: tmp[j] = j; dispatch_cvtype(mat, data = new tree_type - (&tmp[0], &tmp[0] + tmp.size(), mat->cols, - tree_type::deref_type(mat))); + (&tmp[0], &tmp[0] + tmp.size(), mat->cols, + tree_type::deref_type(mat))); } ~CvKDTreeWrap() { dispatch_cvtype(mat, delete (tree_type*) data); @@ -185,15 +185,15 @@ public: assert(CV_MAT_TYPE(results->type) == CV_32SC1); dispatch_cvtype(mat, find_nn - (desc, k, emax, results, dist)); + (desc, k, emax, results, dist)); } int FindOrthoRange(CvMat* bounds_min, CvMat* bounds_max, - CvMat* results) { + CvMat* results) { bool free_bounds = false; int count = -1; if (bounds_min->cols * bounds_min->rows != dims() || - bounds_max->cols * bounds_max->rows != dims()) + bounds_max->cols * bounds_max->rows != dims()) CV_Error(CV_StsUnmatchedSizes, "bounds_{min,max} must 1 x dims or dims x 1"); if (CV_MAT_TYPE(bounds_min->type) != CV_MAT_TYPE(bounds_max->type)) CV_Error(CV_StsUnmatchedFormats, "bounds_{min,max} must have same type"); @@ -218,7 +218,7 @@ public: assert(bounds_max->rows * bounds_max->cols == dims()); dispatch_cvtype(mat, count = find_ortho_range - (bounds_min, bounds_max,results)); + (bounds_min, bounds_max,results)); if (free_bounds) { cvReleaseMat(&bounds_min); diff --git a/modules/legacy/src/lee.cpp b/modules/legacy/src/lee.cpp index 518ec77..9a20fa5 100644 --- a/modules/legacy/src/lee.cpp +++ b/modules/legacy/src/lee.cpp @@ -1247,7 +1247,7 @@ int _cvSolveEqu1th(T c1, T c0, T* X); vertices_number: in, number of vertices in polygon Return : --------------------------------------------------------------------------*/ -void _cvSetSeqBlockSize(CvVoronoiDiagramInt* pVoronoiDiagramInt,int vertices_number) +static void _cvSetSeqBlockSize(CvVoronoiDiagramInt* pVoronoiDiagramInt,int vertices_number) { int N = 2*vertices_number; cvSetSeqBlockSize(pVoronoiDiagramInt->SiteSeq,N*pVoronoiDiagramInt->SiteSeq->elem_size); diff --git a/modules/legacy/src/levmar.cpp b/modules/legacy/src/levmar.cpp index 976f6f4..aa2514e 100644 --- a/modules/legacy/src/levmar.cpp +++ b/modules/legacy/src/levmar.cpp @@ -50,6 +50,7 @@ typedef void (*pointer_LMJac)( const CvMat* src, CvMat* dst ); typedef void (*pointer_LMFunc)( const CvMat* src, CvMat* dst ); +#if 0 /* Optimization using Levenberg-Marquardt */ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction, pointer_LMFunc function, @@ -75,7 +76,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction, CvMat *matrJtJN = 0; CvMat *matrJt = 0; CvMat *vectB = 0; - + CV_FUNCNAME( "cvLevenbegrMarquardtOptimization" ); __BEGIN__; @@ -104,7 +105,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction, { CV_ERROR( CV_StsUnmatchedSizes, "Number of colomn of vector X0 must be 1" ); } - + if( observRes->cols != 1 ) { CV_ERROR( CV_StsUnmatchedSizes, "Number of colomn of vector observed rusult must be 1" ); @@ -157,8 +158,8 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction, /* Print result of function to file */ /* Compute error */ - cvSub(observRes,resFunc,error); - + cvSub(observRes,resFunc,error); + //valError = error_function(observRes,resFunc); /* Need to use new version of computing error (norm) */ valError = cvNorm(observRes,resFunc); @@ -169,7 +170,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction, /* Define optimal delta for J'*J*delta=J'*error */ /* compute J'J */ cvMulTransposed(Jac,matrJtJ,1); - + cvCopy(matrJtJ,matrJtJN); /* compute J'*error */ @@ -244,6 +245,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction, return; } +#endif /*------------------------------------------------------------------------------*/ #if 0 diff --git a/modules/legacy/src/levmarprojbandle.cpp b/modules/legacy/src/levmarprojbandle.cpp index 1581896..467c5d2 100644 --- a/modules/legacy/src/levmarprojbandle.cpp +++ b/modules/legacy/src/levmarprojbandle.cpp @@ -65,9 +65,13 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** */ #define TRACK_BUNDLE_FILE "d:\\test\\bundle.txt" +void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPoints, + CvMat** pointsPres, int numImages, + CvMat** resultProjMatrs, CvMat* resultPoints4D,int maxIter,double epsilon ); + /* ============== Bundle adjustment optimization ================= */ -void icvComputeDerivateProj(CvMat *points4D,CvMat *projMatr, CvMat *status, CvMat *derivProj) +static void icvComputeDerivateProj(CvMat *points4D,CvMat *projMatr, CvMat *status, CvMat *derivProj) { /* Compute derivate for given projection matrix points and status of points */ @@ -201,7 +205,7 @@ void icvComputeDerivateProj(CvMat *points4D,CvMat *projMatr, CvMat *status, CvMa } /*======================================================================================*/ -void icvComputeDerivateProjAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **projDerives) +static void icvComputeDerivateProjAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **projDerives) { CV_FUNCNAME( "icvComputeDerivateProjAll" ); __BEGIN__; @@ -228,7 +232,7 @@ void icvComputeDerivateProjAll(CvMat *points4D, CvMat **projMatrs, CvMat **point } /*======================================================================================*/ -void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints, CvMat *derivPoint) +static void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints, CvMat *derivPoint) { CV_FUNCNAME( "icvComputeDerivatePoints" ); @@ -267,7 +271,7 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints { CV_ERROR( CV_StsOutOfRange, "Size of projection matrix (projMatr) must be 3x4" ); } - + if( !CV_IS_MAT(presPoints) ) { CV_ERROR( CV_StsUnsupportedFormat, "Status must be a matrix 1xN" ); @@ -282,10 +286,10 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints { CV_ERROR( CV_StsUnsupportedFormat, "derivPoint must be a matrix 2 x 4VisNum" ); } - /* ----- End test ----- */ - + /* ----- End test ----- */ + /* Compute derivates by points */ - + double p[12]; int i; for( i = 0; i < 12; i++ ) @@ -311,16 +315,16 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints piX[0] = X[0]*p[0] + X[1]*p[1] + X[2]*p[2] + X[3]*p[3]; piX[1] = X[0]*p[4] + X[1]*p[5] + X[2]*p[6] + X[3]*p[7]; piX[2] = X[0]*p[8] + X[1]*p[9] + X[2]*p[10] + X[3]*p[11]; - + int i,j; double tmp3 = 1/(piX[2]*piX[2]); - + for( j = 0; j < 2; j++ )//for x and y { for( i = 0; i < 4; i++ )// for X,Y,Z,W { - cvmSet( derivPoint, + cvmSet( derivPoint, j, currVisPoint*4+i, (p[j*4+i]*piX[2]-p[8+i]*piX[j]) * tmp3 ); } @@ -337,8 +341,9 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints __END__; return; } + /*======================================================================================*/ -void icvComputeDerivatePointsAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **pointDerives) +static void icvComputeDerivatePointsAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **pointDerives) { CV_FUNCNAME( "icvComputeDerivatePointsAll" ); __BEGIN__; @@ -364,7 +369,7 @@ void icvComputeDerivatePointsAll(CvMat *points4D, CvMat **projMatrs, CvMat **poi return; } /*======================================================================================*/ -void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, CvMat **matrV) +static void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, CvMat **matrV) { int *shifts = 0; @@ -404,10 +409,10 @@ void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, C { if( cvmGet(presPoints[currImage],0,currPoint) > 0 ) { - sum += cvmGet(pointDeriv[currImage],0,shifts[currImage]*4+i) * + sum += cvmGet(pointDeriv[currImage],0,shifts[currImage]*4+i) * cvmGet(pointDeriv[currImage],0,shifts[currImage]*4+j); - sum += cvmGet(pointDeriv[currImage],1,shifts[currImage]*4+i) * + sum += cvmGet(pointDeriv[currImage],1,shifts[currImage]*4+i) * cvmGet(pointDeriv[currImage],1,shifts[currImage]*4+j); } } @@ -429,11 +434,11 @@ void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, C __END__; cvFree( &shifts); - + return; } /*======================================================================================*/ -void icvComputeMatrixUAll(int numImages,CvMat **projDeriv,CvMat** matrU) +static void icvComputeMatrixUAll(int numImages,CvMat **projDeriv,CvMat** matrU) { CV_FUNCNAME( "icvComputeMatrixVAll" ); __BEGIN__; @@ -460,7 +465,7 @@ void icvComputeMatrixUAll(int numImages,CvMat **projDeriv,CvMat** matrU) return; } /*======================================================================================*/ -void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvMat **presPoints, CvMat *matrW) +static void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvMat **presPoints, CvMat *matrW) { CV_FUNCNAME( "icvComputeMatrixW" ); __BEGIN__; @@ -509,10 +514,10 @@ void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvM for( int currCol = 0; currCol < 4; currCol++ ) { double sum; - sum = cvmGet(projDeriv[currImage],currVis*2+0,currLine) * + sum = cvmGet(projDeriv[currImage],currVis*2+0,currLine) * cvmGet(pointDeriv[currImage],0,currVis*4+currCol); - sum += cvmGet(projDeriv[currImage],currVis*2+1,currLine) * + sum += cvmGet(projDeriv[currImage],currVis*2+1,currLine) * cvmGet(pointDeriv[currImage],1,currVis*4+currCol); cvmSet(matrW,currImage*12+currLine,currPoint*4+currCol,sum); @@ -529,7 +534,7 @@ void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvM } } } - + #ifdef TRACK_BUNDLE { FILE *file; @@ -560,9 +565,10 @@ void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvM __END__; return; } + /*======================================================================================*/ /* Compute jacobian mult projection matrices error */ -void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,CvMat *jacProjErr ) +static void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,CvMat *jacProjErr ) { CV_FUNCNAME( "icvComputeJacErrorProj" ); __BEGIN__; @@ -596,7 +602,7 @@ void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,C double sum = 0; for( int i = 0; i < num; i++ ) { - sum += cvmGet(projDeriv[currImage],i,currCol) * + sum += cvmGet(projDeriv[currImage],i,currCol) * cvmGet(projErrors[currImage],i%2,i/2); } cvmSet(jacProjErr,currImage*12+currCol,0,sum); @@ -627,9 +633,10 @@ void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,C __END__; return; } + /*======================================================================================*/ /* Compute jacobian mult points error */ -void icvComputeJacErrorPoint(int numImages,CvMat **pointDeriv,CvMat **projErrors, CvMat **presPoints,CvMat *jacPointErr ) +static void icvComputeJacErrorPoint(int numImages,CvMat **pointDeriv,CvMat **projErrors, CvMat **presPoints,CvMat *jacPointErr ) { int *shifts = 0; @@ -734,6 +741,7 @@ void icvComputeJacErrorPoint(int numImages,CvMat **pointDeriv,CvMat **projErrors } /*======================================================================================*/ + /* Reconstruct 4D points using status */ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** presPoints, CvMat *points4D,int numImages,CvMat **projError) @@ -797,7 +805,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** numVisProj++; } } - + if( numVisProj < 2 ) { /* This point can't be reconstructed */ @@ -821,7 +829,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** y = cvmGet(projPoints[currImage],1,currPoint); for( int k = 0; k < 4; k++ ) { - matrA_dat[currVisProj*12 + k] = + matrA_dat[currVisProj*12 + k] = x * cvmGet(projMatrs[currImage],2,k) - cvmGet(projMatrs[currImage],0,k); matrA_dat[currVisProj*12+4 + k] = @@ -854,7 +862,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** CvMat point3D; double point3D_dat[3]; point3D = cvMat(3,1,CV_64F,point3D_dat); - + int currPoint; int numVis = 0; double totalError = 0; @@ -897,7 +905,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** /*======================================================================================*/ -void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, CvMat **pointsPres, CvMat **projPoints) +static void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, CvMat **pointsPres, CvMat **projPoints) { CV_FUNCNAME( "icvProjPointsStatusFunc" ); __BEGIN__; @@ -943,7 +951,7 @@ void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, fclose(file); } #endif - + int currImage; for( currImage = 0; currImage < numImages; currImage++ ) { @@ -969,7 +977,7 @@ void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, fclose(file); } #endif - + cvmMul(projMatrs[currImage],&point4D,&point3D); double w = point3D_dat[2]; cvmSet(projPoints[currImage],0,currVisPoint,point3D_dat[0]/w); @@ -998,11 +1006,11 @@ void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, } /*======================================================================================*/ -void icvFreeMatrixArray(CvMat ***matrArray,int numMatr) +static void icvFreeMatrixArray(CvMat ***matrArray,int numMatr) { /* Free each matrix */ int currMatr; - + if( *matrArray != 0 ) {/* Need delete */ for( currMatr = 0; currMatr < numMatr; currMatr++ ) @@ -1015,7 +1023,7 @@ void icvFreeMatrixArray(CvMat ***matrArray,int numMatr) } /*======================================================================================*/ -void *icvClearAlloc(int size) +static void *icvClearAlloc(int size) { void *ptr = 0; @@ -1047,6 +1055,7 @@ int icvDeleteSparsInPoints( int numImages, } #endif + /*======================================================================================*/ /* !!! may be useful to return norm of error */ /* !!! may be does not work correct with not all visible 4D points */ @@ -1054,15 +1063,15 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo CvMat** pointsPres, int numImages, CvMat** resultProjMatrs, CvMat* resultPoints4D,int maxIter,double epsilon ) { - + CvMat *vectorX_points4D = 0; - CvMat **vectorX_projMatrs = 0; + CvMat **vectorX_projMatrs = 0; CvMat *newVectorX_points4D = 0; CvMat **newVectorX_projMatrs = 0; CvMat *changeVectorX_points4D = 0; - CvMat *changeVectorX_projMatrs = 0; + CvMat *changeVectorX_projMatrs = 0; CvMat **observVisPoints = 0; CvMat **projVisPoints = 0; @@ -1097,17 +1106,17 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo { CV_ERROR( CV_StsOutOfRange, "Number of images must be more than zero" ); } - + if( maxIter < 1 || maxIter > 2000 ) { CV_ERROR( CV_StsOutOfRange, "Maximum number of iteration must be in [1..1000]" ); } - + if( epsilon < 0 ) { CV_ERROR( CV_StsOutOfRange, "Epsilon parameter must be >= 0" ); } - + if( !CV_IS_MAT(resultPoints4D) ) { CV_ERROR( CV_StsUnsupportedFormat, "resultPoints4D must be a matrix 4 x NumPnt" ); @@ -1139,7 +1148,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo CV_CALL( changeVectorX_projMatrs = cvCreateMat(3,4,CV_64F)); int currImage; - + /* ----- Test input params ----- */ for( currImage = 0; currImage < numImages; currImage++ ) { @@ -1355,7 +1364,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo double norm = cvNorm(vectorX_projMatrs[i]); fprintf(file," test 6.01 prev normProj=%lf\n",norm); } - + fclose(file); } #endif @@ -1384,7 +1393,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo double norm = cvNorm(matrsUk[i]); fprintf(file," test 6.01 prev matrsUk=%lf\n",norm); } - + for( i = 0; i < numPoints; i++ ) { double norm = cvNorm(matrsVi[i]); @@ -1427,7 +1436,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo double norm = cvNorm(matrsUk[i]); fprintf(file," test 6.01 post1 matrsUk=%lf\n",norm); } - + for( i = 0; i < numPoints; i++ ) { double norm = cvNorm(matrsVi[i]); @@ -1612,7 +1621,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo newError += currNorm * currNorm; } newError = sqrt(newError); - + currIter++; @@ -1732,7 +1741,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo } while( change > epsilon && currIter < maxIter ); - + /*--------------------------------------------*/ /* Optimization complete copy computed params */ /* Copy projection matrices */ diff --git a/modules/legacy/src/levmartrif.cpp b/modules/legacy/src/levmartrif.cpp index e8a7ad5..e86b52f 100644 --- a/modules/legacy/src/levmartrif.cpp +++ b/modules/legacy/src/levmartrif.cpp @@ -46,6 +46,8 @@ /* Valery Mosyagin */ +#if 0 + typedef void (*pointer_LMJac)( const CvMat* src, CvMat* dst ); typedef void (*pointer_LMFunc)( const CvMat* src, CvMat* dst ); @@ -61,7 +63,7 @@ void icvReconstructPointsFor3View( CvMat* projMatr1,CvMat* projMatr2,CvMat* proj /* Jacobian computation for trifocal case */ -void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian) +static void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian) { CV_FUNCNAME( "icvJacobianFunction_ProjTrifocal" ); __BEGIN__; @@ -101,7 +103,7 @@ void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian) /* Fill Jacobian matrix */ int currProjPoint; int currMatr; - + cvZero(Jacobian); for( currMatr = 0; currMatr < 3; currMatr++ ) { @@ -137,7 +139,7 @@ void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian) { for( i = 0; i < 4; i++ )// for X,Y,Z,W { - cvmSet( Jacobian, + cvmSet( Jacobian, currMatr*numPoints*2+currProjPoint*2+j, 36+currProjPoint*4+i, (p[j*4+i]*piX[2]-p[8+i]*piX[j]) * tmp3 ); } @@ -161,7 +163,7 @@ void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian) return; } -void icvFunc_ProjTrifocal(const CvMat *vectX, CvMat *resFunc) +static void icvFunc_ProjTrifocal(const CvMat *vectX, CvMat *resFunc) { /* Computes function in a given point */ /* Computers project points using 3 projection matrices and points 3D */ @@ -264,7 +266,7 @@ void icvFunc_ProjTrifocal(const CvMat *vectX, CvMat *resFunc) /*----------------------------------------------------------------------------------------*/ -void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints, +static void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints, CvMat **resultProjMatrs, CvMat *resultPoints4D) { @@ -312,7 +314,7 @@ void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints, { CV_ERROR( CV_StsNullPtr, "Some of projPoints is a NULL pointer" ); } - + if( resultProjMatrs[i] == 0 ) { CV_ERROR( CV_StsNullPtr, "Some of resultProjMatrs is a NULL pointer" ); @@ -402,7 +404,7 @@ void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints, cvmSet(vectorX0,36 + currPoint*4 + 3,0,cvmGet(points4D,3,currPoint)); } - + /* Allocate memory for result */ cvLevenbergMarquardtOptimization( icvJacobianFunction_ProjTrifocal, icvFunc_ProjTrifocal, vectorX0,observRes,optimX,100,1e-6); @@ -441,7 +443,7 @@ void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints, /*------------------------------------------------------------------------------*/ /* Create good points using status information */ -void icvCreateGoodPoints(CvMat *points,CvMat **goodPoints, CvMat *status) +static void icvCreateGoodPoints(CvMat *points,CvMat **goodPoints, CvMat *status) { *goodPoints = 0; @@ -493,3 +495,4 @@ void icvCreateGoodPoints(CvMat *points,CvMat **goodPoints, CvMat *status) return; } +#endif diff --git a/modules/legacy/src/morphcontours.cpp b/modules/legacy/src/morphcontours.cpp index fbc5696..851b00b 100644 --- a/modules/legacy/src/morphcontours.cpp +++ b/modules/legacy/src/morphcontours.cpp @@ -87,7 +87,7 @@ double _cvStretchingWork(CvPoint2D32f* P1, L1 = sqrt( (double)P1->x*P1->x + P1->y*P1->y); L2 = sqrt( (double)P2->x*P2->x + P2->y*P2->y); - + L_min = MIN(L1, L2); dL = fabs( L1 - L2 ); @@ -96,15 +96,15 @@ double _cvStretchingWork(CvPoint2D32f* P1, //////////////////////////////////////////////////////////////////////////////////// +CvPoint2D32f Q( CvPoint2D32f q0, CvPoint2D32f q1, CvPoint2D32f q2, double t ); +double angle( CvPoint2D32f A, CvPoint2D32f B ); + double _cvBendingWork( CvPoint2D32f* B0, CvPoint2D32f* F0, CvPoint2D32f* B1, CvPoint2D32f* F1/*, CvPoint* K*/) { - CvPoint2D32f Q( CvPoint2D32f q0, CvPoint2D32f q1, CvPoint2D32f q2, double t ); - double angle( CvPoint2D32f A, CvPoint2D32f B ); - CvPoint2D32f Q0, Q1, Q2; CvPoint2D32f Q1_nm = { 0, 0 }, Q2_nm = { 0, 0 }; double d0, d1, d2, des, t_zero; @@ -140,7 +140,7 @@ double _cvBendingWork( CvPoint2D32f* B0, d_angle = d_angle - CV_PI*0.5; d_angle = fabs(d_angle); - + K->x = -K->x; K->y = -K->y; B1->x = -B1->x; @@ -427,7 +427,7 @@ void _cvWorkSouthEast(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D small_edge.y = NULL_EDGE*edges1[i-2].y; w1 = W[i-1][j-1].w_east + _cvBendingWork(&edges1[i-2], - &edges1[i-1], + &edges1[i-1], /*&null_edge*/&small_edge, &edges2[j-1]/*, &edges2[j-2]*/); @@ -442,7 +442,7 @@ void _cvWorkSouthEast(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D small_edge.y = NULL_EDGE*edges2[j-2].y; w3 = W[i-1][j-1].w_south + _cvBendingWork( /*&null_edge*/&small_edge, - &edges1[i-1], + &edges1[i-1], &edges2[j-2], &edges2[j-1]/*, &edges1[i-2]*/); @@ -511,6 +511,7 @@ void _cvWorkSouth(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D32f* } } + //=================================================== CvPoint2D32f Q(CvPoint2D32f q0,CvPoint2D32f q1,CvPoint2D32f q2,double t) { @@ -519,14 +520,14 @@ CvPoint2D32f Q(CvPoint2D32f q0,CvPoint2D32f q1,CvPoint2D32f q2,double t) q.x = (float)(q0.x*(1-t)*(1-t) + 2*q1.x*t*(1-t) + q2.x*t*t); q.y = (float)(q0.y*(1-t)*(1-t) + 2*q1.y*t*(1-t) + q2.y*t*t); - return q; + return q; } double angle(CvPoint2D32f A, CvPoint2D32f B) { return acos( (A.x*B.x + A.y*B.y)/sqrt( (double)(A.x*A.x + A.y*A.y)*(B.x*B.x + B.y*B.y) ) ); } - +#if 0 /***************************************************************************************\ * * This function compute intermediate polygon between contour1 and contour2 @@ -536,14 +537,14 @@ double angle(CvPoint2D32f A, CvPoint2D32f B) * param = [0,1]; 0 correspondence to contour1, 1 - contour2 * \***************************************************************************************/ -CvSeq* icvBlendContours(CvSeq* contour1, +static CvSeq* icvBlendContours(CvSeq* contour1, CvSeq* contour2, CvSeq* corr, double param, CvMemStorage* storage) { int j; - + CvSeqWriter writer01; CvSeqReader reader01; @@ -558,7 +559,7 @@ CvSeq* icvBlendContours(CvSeq* contour1, int corr_point; // Create output sequence. - CvSeq* output = cvCreateSeq(0, + CvSeq* output = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint), storage ); @@ -570,7 +571,7 @@ CvSeq* icvBlendContours(CvSeq* contour1, point1 = (CvPoint* )malloc( Ni*sizeof(CvPoint) ); point2 = (CvPoint* )malloc( Nj*sizeof(CvPoint) ); - // Initialize arrays of point + // Initialize arrays of point cvCvtSeqToArray( contour1, point1, CV_WHOLE_SEQ ); cvCvtSeqToArray( contour2, point2, CV_WHOLE_SEQ ); @@ -583,7 +584,7 @@ CvSeq* icvBlendContours(CvSeq* contour1, i = Ni-1; //correspondence to points of contour1 for( ; corr; corr = corr->h_next ) - { + { //Initializes process of sequential reading from sequence cvStartReadSeq( corr, &reader01, 0 ); @@ -595,7 +596,7 @@ CvSeq* icvBlendContours(CvSeq* contour1, // Compute point of intermediate polygon. point_output.x = cvRound(point1[i].x + param*( point2[corr_point].x - point1[i].x )); point_output.y = cvRound(point1[i].y + param*( point2[corr_point].y - point1[i].y )); - + // Write element to sequence. CV_WRITE_SEQ_ELEM( point_output, writer01 ); } @@ -603,7 +604,7 @@ CvSeq* icvBlendContours(CvSeq* contour1, } // Updates sequence header. cvFlushSeqWriter( &writer01 ); - + return output; } @@ -621,9 +622,9 @@ CvSeq* icvBlendContours(CvSeq* contour1, **************************************************************************************************/ -void icvCalcContoursCorrespondence(CvSeq* contour1, - CvSeq* contour2, - CvSeq** corr, +static void icvCalcContoursCorrespondence(CvSeq* contour1, + CvSeq* contour2, + CvSeq** corr, CvMemStorage* storage) { int i,j; // counter of cycles @@ -660,7 +661,7 @@ void icvCalcContoursCorrespondence(CvSeq* contour1, edges1 = (CvPoint2D32f* )malloc( (Ni-1)*sizeof(CvPoint2D32f) ); edges2 = (CvPoint2D32f* )malloc( (Nj-1)*sizeof(CvPoint2D32f) ); - // Initialize arrays of point + // Initialize arrays of point cvCvtSeqToArray( contour1, point1, CV_WHOLE_SEQ ); cvCvtSeqToArray( contour2, point2, CV_WHOLE_SEQ ); @@ -679,7 +680,7 @@ void icvCalcContoursCorrespondence(CvSeq* contour1, edges2[i].y = (float)( point2[i+1].y - point2[i].y ); }; - // Find infinity constant + // Find infinity constant //inf=1; ///////////// @@ -716,11 +717,11 @@ void icvCalcContoursCorrespondence(CvSeq* contour1, { j=0;///////// W[i][j].w_east = W[i-1][j].w_east; - W[i][j].w_east = W[i][j].w_east /*+ + W[i][j].w_east = W[i][j].w_east /*+ _cvBendingWork( &edges1[i-2], &edges1[i-1], &null_edge, &null_edge, NULL )*/; W[i][j].w_east = W[i][j].w_east + _cvStretchingWork( &edges2[i-1], &null_edge ); W[i][j].path_e = PATH_TO_E; - + j=1;////////// W[i][j].w_south = inf; @@ -732,18 +733,18 @@ void icvCalcContoursCorrespondence(CvSeq* contour1, small_edge.x = NULL_EDGE*edges1[i-2].x; small_edge.y = NULL_EDGE*edges1[i-2].y; - W[i][j].w_southeast = W[i][j].w_southeast + + W[i][j].w_southeast = W[i][j].w_southeast + _cvBendingWork( &edges1[i-2], &edges1[i-1], /*&null_edge*/&small_edge, &edges2[j-1]/*, &edges2[Nj-2]*/); W[i][j].path_se = PATH_TO_E; } for(j=2; jh_next = cvCreateSeq( 0, - sizeof(CvSeq), + corr01->h_next = cvCreateSeq( 0, + sizeof(CvSeq), sizeof(int), storage ); corr01 = corr01->h_next; cvStartAppendToSeq( corr01, &writer ); break; - + case PATH_TO_SE: path = W[i][j].path_se; j--; i--; cvFlushSeqWriter( &writer ); - corr01->h_next = cvCreateSeq( 0, - sizeof(CvSeq), + corr01->h_next = cvCreateSeq( 0, + sizeof(CvSeq), sizeof(int), storage ); corr01 = corr01->h_next; @@ -852,4 +853,4 @@ void icvCalcContoursCorrespondence(CvSeq* contour1, free(edges1); free(edges2); } - +#endif diff --git a/modules/legacy/src/oneway.cpp b/modules/legacy/src/oneway.cpp index 737cecf..8bdafbb 100644 --- a/modules/legacy/src/oneway.cpp +++ b/modules/legacy/src/oneway.cpp @@ -12,7 +12,7 @@ #include namespace cv{ - + inline int round(float value) { if(value > 0) @@ -24,15 +24,15 @@ namespace cv{ return int(value - 0.5f); } } - + inline CvRect resize_rect(CvRect rect, float alpha) { return cvRect(rect.x + round((float)(0.5*(1 - alpha)*rect.width)), rect.y + round((float)(0.5*(1 - alpha)*rect.height)), round(rect.width*alpha), round(rect.height*alpha)); } - + CvMat* ConvertImageToMatrix(IplImage* patch); - + class CvCameraPose { public: @@ -41,104 +41,104 @@ namespace cv{ m_rotation = cvCreateMat(1, 3, CV_32FC1); m_translation = cvCreateMat(1, 3, CV_32FC1); }; - + ~CvCameraPose() { cvReleaseMat(&m_rotation); cvReleaseMat(&m_translation); }; - + void SetPose(CvMat* rotation, CvMat* translation) { cvCopy(rotation, m_rotation); cvCopy(translation, m_translation); }; - + CvMat* GetRotation() {return m_rotation;}; CvMat* GetTranslation() {return m_translation;}; - + protected: CvMat* m_rotation; CvMat* m_translation; }; - + // AffineTransformPatch: generates an affine transformed image patch. // - src: source image (roi is supported) // - dst: output image. ROI of dst image should be 2 times smaller than ROI of src. // - pose: parameters of an affine transformation void AffineTransformPatch(IplImage* src, IplImage* dst, CvAffinePose pose); - + // GenerateAffineTransformFromPose: generates an affine transformation matrix from CvAffinePose instance // - size: the size of image patch // - pose: affine transformation // - transform: 2x3 transformation matrix void GenerateAffineTransformFromPose(CvSize size, CvAffinePose pose, CvMat* transform); - + // Generates a random affine pose CvAffinePose GenRandomAffinePose(); - - + + const static int num_mean_components = 500; const static float noise_intensity = 0.15f; - - + + static inline CvPoint rect_center(CvRect rect) { return cvPoint(rect.x + rect.width/2, rect.y + rect.height/2); } - - void homography_transform(IplImage* frontal, IplImage* result, CvMat* homography) - { - cvWarpPerspective(frontal, result, homography); - } - - CvAffinePose perturbate_pose(CvAffinePose pose, float noise) + + // static void homography_transform(IplImage* frontal, IplImage* result, CvMat* homography) + // { + // cvWarpPerspective(frontal, result, homography); + // } + + static CvAffinePose perturbate_pose(CvAffinePose pose, float noise) { // perturbate the matrix float noise_mult_factor = 1 + (0.5f - float(rand())/RAND_MAX)*noise; float noise_add_factor = noise_mult_factor - 1; - + CvAffinePose pose_pert = pose; pose_pert.phi += noise_add_factor; pose_pert.theta += noise_mult_factor; pose_pert.lambda1 *= noise_mult_factor; pose_pert.lambda2 *= noise_mult_factor; - + return pose_pert; } - - void generate_mean_patch(IplImage* frontal, IplImage* result, CvAffinePose pose, int pose_count, float noise) + + static void generate_mean_patch(IplImage* frontal, IplImage* result, CvAffinePose pose, int pose_count, float noise) { IplImage* sum = cvCreateImage(cvSize(result->width, result->height), IPL_DEPTH_32F, 1); IplImage* workspace = cvCloneImage(result); IplImage* workspace_float = cvCloneImage(sum); - + cvSetZero(sum); for(int i = 0; i < pose_count; i++) { CvAffinePose pose_pert = perturbate_pose(pose, noise); - + AffineTransformPatch(frontal, workspace, pose_pert); cvConvertScale(workspace, workspace_float); cvAdd(sum, workspace_float, sum); } - + cvConvertScale(sum, result, 1.0f/pose_count); - + cvReleaseImage(&workspace); cvReleaseImage(&sum); cvReleaseImage(&workspace_float); } - - void generate_mean_patch_fast(IplImage* /*frontal*/, IplImage* /*result*/, CvAffinePose /*pose*/, - CvMat* /*pca_hr_avg*/, CvMat* /*pca_hr_eigenvectors*/, const OneWayDescriptor* /*pca_descriptors*/) - { - /*for(int i = 0; i < pca_hr_eigenvectors->cols; i++) - { - - }*/ - } - + + // static void generate_mean_patch_fast(IplImage* /*frontal*/, IplImage* /*result*/, CvAffinePose /*pose*/, + // CvMat* /*pca_hr_avg*/, CvMat* /*pca_hr_eigenvectors*/, const OneWayDescriptor* /*pca_descriptors*/) + // { + // /*for(int i = 0; i < pca_hr_eigenvectors->cols; i++) + // { + + // }*/ + // } + void readPCAFeatures(const char *filename, CvMat** avg, CvMat** eigenvectors, const char *postfix = ""); void readPCAFeatures(const FileNode &fn, CvMat** avg, CvMat** eigenvectors, const char* postfix = ""); void savePCAFeatures(FileStorage &fs, const char* postfix, CvMat* avg, CvMat* eigenvectors); @@ -147,35 +147,35 @@ namespace cv{ void loadPCAFeatures(const char* path, const char* images_list, vector& patches, CvSize patch_size); void generatePCAFeatures(const char* path, const char* img_filename, FileStorage& fs, const char* postfix, CvSize patch_size, CvMat** avg, CvMat** eigenvectors); - + void eigenvector2image(CvMat* eigenvector, IplImage* img); void FindOneWayDescriptor(int desc_count, const OneWayDescriptor* descriptors, IplImage* patch, int& desc_idx, int& pose_idx, float& distance, CvMat* avg = 0, CvMat* eigenvalues = 0); - + void FindOneWayDescriptor(int desc_count, const OneWayDescriptor* descriptors, IplImage* patch, int n, std::vector& desc_idxs, std::vector& pose_idxs, std::vector& distances, CvMat* avg = 0, CvMat* eigenvalues = 0); - + void FindOneWayDescriptor(cv::flann::Index* m_pca_descriptors_tree, CvSize patch_size, int m_pca_dim_low, int m_pose_count, IplImage* patch, int& desc_idx, int& pose_idx, float& distance, CvMat* avg = 0, CvMat* eigenvalues = 0); - + void FindOneWayDescriptorEx(int desc_count, const OneWayDescriptor* descriptors, IplImage* patch, float scale_min, float scale_max, float scale_step, int& desc_idx, int& pose_idx, float& distance, float& scale, CvMat* avg, CvMat* eigenvectors); - + void FindOneWayDescriptorEx(int desc_count, const OneWayDescriptor* descriptors, IplImage* patch, float scale_min, float scale_max, float scale_step, int n, std::vector& desc_idxs, std::vector& pose_idxs, std::vector& distances, std::vector& scales, CvMat* avg, CvMat* eigenvectors); - + void FindOneWayDescriptorEx(cv::flann::Index* m_pca_descriptors_tree, CvSize patch_size, int m_pca_dim_low, int m_pose_count, IplImage* patch, float scale_min, float scale_max, float scale_step, int& desc_idx, int& pose_idx, float& distance, float& scale, CvMat* avg, CvMat* eigenvectors); - + inline CvRect fit_rect_roi_fixedsize(CvRect rect, CvRect roi) { CvRect fit = rect; @@ -185,13 +185,13 @@ namespace cv{ fit.y = MIN(fit.y, roi.y + roi.height - fit.height - 1); return(fit); } - + inline CvRect fit_rect_fixedsize(CvRect rect, IplImage* img) { CvRect roi = cvGetImageROI(img); return fit_rect_roi_fixedsize(rect, roi); } - + OneWayDescriptor::OneWayDescriptor() { m_pose_count = 0; @@ -204,7 +204,7 @@ namespace cv{ m_pca_dim_low = 100; m_pca_dim_high = 100; } - + OneWayDescriptor::~OneWayDescriptor() { if(m_pose_count) @@ -218,50 +218,50 @@ namespace cv{ cvReleaseImage(&m_train_patch); delete []m_samples; delete []m_pca_coeffs; - + if(!m_transforms) { delete []m_affine_poses; } } } - + void OneWayDescriptor::Allocate(int pose_count, CvSize size, int nChannels) { m_pose_count = pose_count; m_samples = new IplImage* [m_pose_count]; m_pca_coeffs = new CvMat* [m_pose_count]; m_patch_size = cvSize(size.width/2, size.height/2); - + if(!m_transforms) { m_affine_poses = new CvAffinePose[m_pose_count]; } - + int length = m_pca_dim_low;//roi.width*roi.height; for(int i = 0; i < m_pose_count; i++) { m_samples[i] = cvCreateImage(cvSize(size.width/2, size.height/2), IPL_DEPTH_32F, nChannels); m_pca_coeffs[i] = cvCreateMat(1, length, CV_32FC1); } - + m_input_patch = cvCreateImage(GetPatchSize(), IPL_DEPTH_8U, 1); m_train_patch = cvCreateImage(GetInputPatchSize(), IPL_DEPTH_8U, 1); } - - void cvmSet2DPoint(CvMat* matrix, int row, int col, CvPoint2D32f point) - { - cvmSet(matrix, row, col, point.x); - cvmSet(matrix, row, col + 1, point.y); - } - - void cvmSet3DPoint(CvMat* matrix, int row, int col, CvPoint3D32f point) - { - cvmSet(matrix, row, col, point.x); - cvmSet(matrix, row, col + 1, point.y); - cvmSet(matrix, row, col + 2, point.z); - } - + + // static void cvmSet2DPoint(CvMat* matrix, int row, int col, CvPoint2D32f point) + // { + // cvmSet(matrix, row, col, point.x); + // cvmSet(matrix, row, col + 1, point.y); + // } + + // static void cvmSet3DPoint(CvMat* matrix, int row, int col, CvPoint3D32f point) + // { + // cvmSet(matrix, row, col, point.x); + // cvmSet(matrix, row, col + 1, point.y); + // cvmSet(matrix, row, col + 2, point.z); + // } + CvAffinePose GenRandomAffinePose() { const float scale_min = 0.8f; @@ -271,10 +271,10 @@ namespace cv{ pose.phi = float(rand())/RAND_MAX*360; pose.lambda1 = scale_min + float(rand())/RAND_MAX*(scale_max - scale_min); pose.lambda2 = scale_min + float(rand())/RAND_MAX*(scale_max - scale_min); - + return pose; } - + void GenerateAffineTransformFromPose(CvSize size, CvAffinePose pose, CvMat* transform) { CvMat* temp = cvCreateMat(3, 3, CV_32FC1); @@ -282,13 +282,13 @@ namespace cv{ cvmSet(temp, 2, 0, 0.0f); cvmSet(temp, 2, 1, 0.0f); cvmSet(temp, 2, 2, 1.0f); - + CvMat rotation; cvGetSubRect(temp, &rotation, cvRect(0, 0, 3, 2)); - + cv2DRotationMatrix(cvPoint2D32f(size.width/2, size.height/2), pose.phi, 1.0, &rotation); cvCopy(temp, final); - + cvmSet(temp, 0, 0, pose.lambda1); cvmSet(temp, 0, 1, 0.0f); cvmSet(temp, 1, 0, 0.0f); @@ -296,53 +296,53 @@ namespace cv{ cvmSet(temp, 0, 2, size.width/2*(1 - pose.lambda1)); cvmSet(temp, 1, 2, size.height/2*(1 - pose.lambda2)); cvMatMul(temp, final, final); - + cv2DRotationMatrix(cvPoint2D32f(size.width/2, size.height/2), pose.theta - pose.phi, 1.0, &rotation); cvMatMul(temp, final, final); - + cvGetSubRect(final, &rotation, cvRect(0, 0, 3, 2)); cvCopy(&rotation, transform); - + cvReleaseMat(&temp); cvReleaseMat(&final); } - + void AffineTransformPatch(IplImage* src, IplImage* dst, CvAffinePose pose) { CvRect src_large_roi = cvGetImageROI(src); - + IplImage* temp = cvCreateImage(cvSize(src_large_roi.width, src_large_roi.height), IPL_DEPTH_32F, src->nChannels); cvSetZero(temp); IplImage* temp2 = cvCloneImage(temp); CvMat* rotation_phi = cvCreateMat(2, 3, CV_32FC1); - + CvSize new_size = cvSize(cvRound(temp->width*pose.lambda1), cvRound(temp->height*pose.lambda2)); IplImage* temp3 = cvCreateImage(new_size, IPL_DEPTH_32F, src->nChannels); - + cvConvertScale(src, temp); cvResetImageROI(temp); - - + + cv2DRotationMatrix(cvPoint2D32f(temp->width/2, temp->height/2), pose.phi, 1.0, rotation_phi); cvWarpAffine(temp, temp2, rotation_phi); - + cvSetZero(temp); - + cvResize(temp2, temp3); - + cv2DRotationMatrix(cvPoint2D32f(temp3->width/2, temp3->height/2), pose.theta - pose.phi, 1.0, rotation_phi); cvWarpAffine(temp3, temp, rotation_phi); - + cvSetImageROI(temp, cvRect(temp->width/2 - src_large_roi.width/4, temp->height/2 - src_large_roi.height/4, src_large_roi.width/2, src_large_roi.height/2)); cvConvertScale(temp, dst); cvReleaseMat(&rotation_phi); - + cvReleaseImage(&temp3); cvReleaseImage(&temp2); cvReleaseImage(&temp); } - + void OneWayDescriptor::GenerateSamples(int pose_count, IplImage* frontal, int norm) { /* if(m_transforms) @@ -361,7 +361,7 @@ namespace cv{ } //AffineTransformPatch(frontal, patch_8u, m_affine_poses[i]); generate_mean_patch(frontal, patch_8u, m_affine_poses[i], num_mean_components, noise_intensity); - + double scale = 1.0f; if(norm) { @@ -369,7 +369,7 @@ namespace cv{ scale = 1/sum; } cvConvertScale(patch_8u, m_samples[i], scale); - + #if 0 double maxval; cvMinMaxLoc(m_samples[i], 0, &maxval); @@ -382,7 +382,7 @@ namespace cv{ } cvReleaseImage(&patch_8u); } - + void OneWayDescriptor::GenerateSamplesFast(IplImage* frontal, CvMat* pca_hr_avg, CvMat* pca_hr_eigenvectors, OneWayDescriptor* pca_descriptors) { @@ -392,12 +392,12 @@ namespace cv{ cvResize(frontal, m_train_patch); frontal = m_train_patch; } - + CvMat* pca_coeffs = cvCreateMat(1, pca_hr_eigenvectors->cols, CV_32FC1); double maxval; cvMinMaxLoc(frontal, 0, &maxval); CvMat* frontal_data = ConvertImageToMatrix(frontal); - + double sum = cvSum(frontal_data).val[0]; cvConvertScale(frontal_data, frontal_data, 1.0f/sum); cvProjectPCA(frontal_data, pca_hr_avg, pca_hr_eigenvectors, pca_coeffs); @@ -409,7 +409,7 @@ namespace cv{ double coeff = cvmGet(pca_coeffs, 0, j); IplImage* patch = pca_descriptors[j + 1].GetPatch(i); cvAddWeighted(m_samples[i], 1.0, patch, coeff, 0, m_samples[i]); - + #if 0 printf("coeff%d = %f\n", j, coeff); IplImage* test = cvCreateImage(cvSize(12, 12), IPL_DEPTH_8U, 1); @@ -421,11 +421,11 @@ namespace cv{ cvWaitKey(0); #endif } - + cvAdd(pca_descriptors[0].GetPatch(i), m_samples[i], m_samples[i]); double sum = cvSum(m_samples[i]).val[0]; cvConvertScale(m_samples[i], m_samples[i], 1.0/sum); - + #if 0 IplImage* test = cvCreateImage(cvSize(12, 12), IPL_DEPTH_8U, 1); /* IplImage* temp1 = cvCreateImage(cvSize(12, 12), IPL_DEPTH_32F, 1); @@ -436,7 +436,7 @@ namespace cv{ cvConvertScale(temp1, test, 255.0/maxval);*/ cvMinMaxLoc(m_samples[i], 0, &maxval); cvConvertScale(m_samples[i], test, 255.0/maxval); - + cvNamedWindow("1", 1); cvShowImage("1", frontal); cvNamedWindow("2", 1); @@ -444,33 +444,33 @@ namespace cv{ cvWaitKey(0); #endif } - + cvReleaseMat(&pca_coeffs); cvReleaseMat(&frontal_data); } - + void OneWayDescriptor::SetTransforms(CvAffinePose* poses, CvMat** transforms) { if(m_affine_poses) { delete []m_affine_poses; } - + m_affine_poses = poses; m_transforms = transforms; } - + void OneWayDescriptor::Initialize(int pose_count, IplImage* frontal, const char* feature_name, int norm) { m_feature_name = std::string(feature_name); CvRect roi = cvGetImageROI(frontal); m_center = rect_center(roi); - + Allocate(pose_count, cvSize(roi.width, roi.height), frontal->nChannels); - + GenerateSamples(pose_count, frontal, norm); } - + void OneWayDescriptor::InitializeFast(int pose_count, IplImage* frontal, const char* feature_name, CvMat* pca_hr_avg, CvMat* pca_hr_eigenvectors, OneWayDescriptor* pca_descriptors) { @@ -482,12 +482,12 @@ namespace cv{ m_feature_name = std::string(feature_name); CvRect roi = cvGetImageROI(frontal); m_center = rect_center(roi); - + Allocate(pose_count, cvSize(roi.width, roi.height), frontal->nChannels); - + GenerateSamplesFast(frontal, pca_hr_avg, pca_hr_eigenvectors, pca_descriptors); } - + void OneWayDescriptor::InitializePCACoeffs(CvMat* avg, CvMat* eigenvectors) { for(int i = 0; i < m_pose_count; i++) @@ -495,7 +495,7 @@ namespace cv{ ProjectPCASample(m_samples[i], avg, eigenvectors, m_pca_coeffs[i]); } } - + void OneWayDescriptor::ProjectPCASample(IplImage* patch, CvMat* avg, CvMat* eigenvectors, CvMat* pca_coeffs) const { CvMat* patch_mat = ConvertImageToMatrix(patch); @@ -506,11 +506,11 @@ namespace cv{ CvMat temp1; cvGetSubRect(temp, &temp1, cvRect(0, 0, pca_coeffs->cols, 1)); cvCopy(&temp1, pca_coeffs); - + cvReleaseMat(&temp); cvReleaseMat(&patch_mat); } - + void OneWayDescriptor::EstimatePosePCA(CvArr* patch, int& pose_idx, float& distance, CvMat* avg, CvMat* eigenvectors) const { if(avg == 0) @@ -522,7 +522,7 @@ namespace cv{ } else { - + } return; } @@ -537,9 +537,9 @@ namespace cv{ roi = cvGetImageROI((IplImage*)patch); } } - + CvMat* pca_coeffs = cvCreateMat(1, m_pca_dim_low, CV_32FC1); - + if (CV_IS_MAT(patch)) { cvCopy((CvMat*)patch, pca_coeffs); @@ -552,41 +552,41 @@ namespace cv{ ProjectPCASample(patch_32f, avg, eigenvectors, pca_coeffs); cvReleaseImage(&patch_32f); } - - + + distance = 1e10; pose_idx = -1; - + for(int i = 0; i < m_pose_count; i++) { double dist = cvNorm(m_pca_coeffs[i], pca_coeffs); - // float dist = 0; - // float data1, data2; - // //CvMat* pose_pca_coeffs = m_pca_coeffs[i]; - // for (int x=0; x < pca_coeffs->width; x++) - // for (int y =0 ; y < pca_coeffs->height; y++) - // { - // data1 = ((float*)(pca_coeffs->data.ptr + pca_coeffs->step*x))[y]; - // data2 = ((float*)(m_pca_coeffs[i]->data.ptr + m_pca_coeffs[i]->step*x))[y]; - // dist+=(data1-data2)*(data1-data2); - // } + // float dist = 0; + // float data1, data2; + // //CvMat* pose_pca_coeffs = m_pca_coeffs[i]; + // for (int x=0; x < pca_coeffs->width; x++) + // for (int y =0 ; y < pca_coeffs->height; y++) + // { + // data1 = ((float*)(pca_coeffs->data.ptr + pca_coeffs->step*x))[y]; + // data2 = ((float*)(m_pca_coeffs[i]->data.ptr + m_pca_coeffs[i]->step*x))[y]; + // dist+=(data1-data2)*(data1-data2); + // } ////#if 1 - // for (int j = 0; j < m_pca_dim_low; j++) - // { - // dist += (pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j])*(pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j]); - // } + // for (int j = 0; j < m_pca_dim_low; j++) + // { + // dist += (pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j])*(pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j]); + // } //#else - // for (int j = 0; j <= m_pca_dim_low - 4; j += 4) - // { - // dist += (pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j])* - // (pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j]); - // dist += (pose_pca_coeffs->data.fl[j+1]- pca_coeffs->data.fl[j+1])* - // (pose_pca_coeffs->data.fl[j+1]- pca_coeffs->data.fl[j+1]); - // dist += (pose_pca_coeffs->data.fl[j+2]- pca_coeffs->data.fl[j+2])* - // (pose_pca_coeffs->data.fl[j+2]- pca_coeffs->data.fl[j+2]); - // dist += (pose_pca_coeffs->data.fl[j+3]- pca_coeffs->data.fl[j+3])* - // (pose_pca_coeffs->data.fl[j+3]- pca_coeffs->data.fl[j+3]); - // } + // for (int j = 0; j <= m_pca_dim_low - 4; j += 4) + // { + // dist += (pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j])* + // (pose_pca_coeffs->data.fl[j]- pca_coeffs->data.fl[j]); + // dist += (pose_pca_coeffs->data.fl[j+1]- pca_coeffs->data.fl[j+1])* + // (pose_pca_coeffs->data.fl[j+1]- pca_coeffs->data.fl[j+1]); + // dist += (pose_pca_coeffs->data.fl[j+2]- pca_coeffs->data.fl[j+2])* + // (pose_pca_coeffs->data.fl[j+2]- pca_coeffs->data.fl[j+2]); + // dist += (pose_pca_coeffs->data.fl[j+3]- pca_coeffs->data.fl[j+3])* + // (pose_pca_coeffs->data.fl[j+3]- pca_coeffs->data.fl[j+3]); + // } //#endif if(dist < distance) { @@ -594,20 +594,20 @@ namespace cv{ pose_idx = i; } } - + cvReleaseMat(&pca_coeffs); } - + void OneWayDescriptor::EstimatePose(IplImage* patch, int& pose_idx, float& distance) const { distance = 1e10; pose_idx = -1; - + CvRect roi = cvGetImageROI(patch); IplImage* patch_32f = cvCreateImage(cvSize(roi.width, roi.height), IPL_DEPTH_32F, patch->nChannels); double sum = cvSum(patch).val[0]; cvConvertScale(patch, patch_32f, 1/sum); - + for(int i = 0; i < m_pose_count; i++) { if(m_samples[i]->width != patch_32f->width || m_samples[i]->height != patch_32f->height) @@ -617,21 +617,21 @@ namespace cv{ double dist = cvNorm(m_samples[i], patch_32f); //float dist = 0.0f; //float i1,i2; - + //for (int y = 0; yheight; y++) - // for (int x = 0; x< patch_32f->width; x++) - // { - // i1 = ((float*)(m_samples[i]->imageData + m_samples[i]->widthStep*y))[x]; - // i2 = ((float*)(patch_32f->imageData + patch_32f->widthStep*y))[x]; - // dist+= (i1-i2)*(i1-i2); - // } - + // for (int x = 0; x< patch_32f->width; x++) + // { + // i1 = ((float*)(m_samples[i]->imageData + m_samples[i]->widthStep*y))[x]; + // i2 = ((float*)(patch_32f->imageData + patch_32f->widthStep*y))[x]; + // dist+= (i1-i2)*(i1-i2); + // } + if(dist < distance) { distance = (float)dist; pose_idx = i; } - + #if 0 IplImage* img1 = cvCreateImage(cvSize(roi.width, roi.height), IPL_DEPTH_8U, 1); IplImage* img2 = cvCreateImage(cvSize(roi.width, roi.height), IPL_DEPTH_8U, 1); @@ -640,7 +640,7 @@ namespace cv{ cvConvertScale(m_samples[i], img1, 255.0/maxval); cvMinMaxLoc(patch_32f, 0, &maxval); cvConvertScale(patch_32f, img2, 255.0/maxval); - + cvNamedWindow("1", 1); cvShowImage("1", img1); cvNamedWindow("2", 1); @@ -649,10 +649,10 @@ namespace cv{ cvWaitKey(0); #endif } - + cvReleaseImage(&patch_32f); } - + void OneWayDescriptor::Save(const char* path) { for(int i = 0; i < m_pose_count; i++) @@ -660,21 +660,21 @@ namespace cv{ char buf[1024]; sprintf(buf, "%s/patch_%04d.jpg", path, i); IplImage* patch = cvCreateImage(cvSize(m_samples[i]->width, m_samples[i]->height), IPL_DEPTH_8U, m_samples[i]->nChannels); - + double maxval; cvMinMaxLoc(m_samples[i], 0, &maxval); cvConvertScale(m_samples[i], patch, 255/maxval); - + cvSaveImage(buf, patch); - + cvReleaseImage(&patch); } } - + void OneWayDescriptor::Write(CvFileStorage* fs, const char* name) { CvMat* mat = cvCreateMat(m_pose_count, m_samples[0]->width*m_samples[0]->height, CV_32FC1); - + // prepare data to write as a single matrix for(int i = 0; i < m_pose_count; i++) { @@ -687,12 +687,12 @@ namespace cv{ } } } - + cvWrite(fs, name, mat); - + cvReleaseMat(&mat); } - + int OneWayDescriptor::ReadByName(const FileNode &parent, const char* name) { CvMat* mat = reinterpret_cast (parent[name].readObj ()); @@ -700,8 +700,8 @@ namespace cv{ { return 0; } - - + + for(int i = 0; i < m_pose_count; i++) { for(int y = 0; y < m_samples[i]->height; y++) @@ -713,7 +713,7 @@ namespace cv{ } } } - + cvReleaseMat(&mat); return 1; } @@ -722,17 +722,17 @@ namespace cv{ { return ReadByName (FileNode (fs, parent), name); } - + IplImage* OneWayDescriptor::GetPatch(int index) { return m_samples[index]; } - + CvAffinePose OneWayDescriptor::GetPose(int index) const { return m_affine_poses[index]; } - + void FindOneWayDescriptor(int desc_count, const OneWayDescriptor* descriptors, IplImage* patch, int& desc_idx, int& pose_idx, float& distance, CvMat* avg, CvMat* eigenvectors) { @@ -751,7 +751,7 @@ namespace cv{ IplImage* test_img = cvCreateImage(cvSize(patch_width,patch_height), IPL_DEPTH_8U, 1); if(_roi.width != patch_width|| _roi.height != patch_height) { - + cvResize(patch, test_img); _roi = cvGetImageROI(test_img); } @@ -762,7 +762,7 @@ namespace cv{ IplImage* patch_32f = cvCreateImage(cvSize(_roi.width, _roi.height), IPL_DEPTH_32F, 1); double sum = cvSum(test_img).val[0]; cvConvertScale(test_img, patch_32f, 1.0f/sum); - + //ProjectPCASample(patch_32f, avg, eigenvectors, pca_coeffs); //Projecting PCA CvMat* patch_mat = ConvertImageToMatrix(patch_32f); @@ -774,20 +774,20 @@ namespace cv{ cvReleaseMat(&temp); cvReleaseMat(&patch_mat); //End of projecting - + cvReleaseImage(&patch_32f); cvReleaseImage(&test_img); } - + //-------- - - - + + + for(int i = 0; i < desc_count; i++) { int _pose_idx = -1; float _distance = 0; - + #if 0 descriptors[i].EstimatePose(patch, _pose_idx, _distance); #else @@ -800,7 +800,7 @@ namespace cv{ descriptors[i].EstimatePosePCA(pca_coeffs, _pose_idx, _distance, avg, eigenvectors); } #endif - + if(_distance < distance) { desc_idx = i; @@ -810,9 +810,9 @@ namespace cv{ } cvReleaseMat(&pca_coeffs); } - + #if defined(_KDTREE) - + void FindOneWayDescriptor(cv::flann::Index* m_pca_descriptors_tree, CvSize patch_size, int m_pca_dim_low, int m_pose_count, IplImage* patch, int& desc_idx, int& pose_idx, float& distance, CvMat* avg, CvMat* eigenvectors) { @@ -826,77 +826,77 @@ namespace cv{ int patch_height = patch_size.height; //if (avg) //{ - CvRect _roi = cvGetImageROI((IplImage*)patch); - IplImage* test_img = cvCreateImage(cvSize(patch_width,patch_height), IPL_DEPTH_8U, 1); - if(_roi.width != patch_width|| _roi.height != patch_height) - { - - cvResize(patch, test_img); - _roi = cvGetImageROI(test_img); - } - else - { - cvCopy(patch,test_img); - } - IplImage* patch_32f = cvCreateImage(cvSize(_roi.width, _roi.height), IPL_DEPTH_32F, 1); - float sum = cvSum(test_img).val[0]; - cvConvertScale(test_img, patch_32f, 1.0f/sum); - - //ProjectPCASample(patch_32f, avg, eigenvectors, pca_coeffs); - //Projecting PCA - CvMat* patch_mat = ConvertImageToMatrix(patch_32f); - CvMat* temp = cvCreateMat(1, eigenvectors->cols, CV_32FC1); - cvProjectPCA(patch_mat, avg, eigenvectors, temp); - CvMat temp1; - cvGetSubRect(temp, &temp1, cvRect(0, 0, pca_coeffs->cols, 1)); - cvCopy(&temp1, pca_coeffs); - cvReleaseMat(&temp); - cvReleaseMat(&patch_mat); - //End of projecting - - cvReleaseImage(&patch_32f); - cvReleaseImage(&test_img); - // } - + CvRect _roi = cvGetImageROI((IplImage*)patch); + IplImage* test_img = cvCreateImage(cvSize(patch_width,patch_height), IPL_DEPTH_8U, 1); + if(_roi.width != patch_width|| _roi.height != patch_height) + { + + cvResize(patch, test_img); + _roi = cvGetImageROI(test_img); + } + else + { + cvCopy(patch,test_img); + } + IplImage* patch_32f = cvCreateImage(cvSize(_roi.width, _roi.height), IPL_DEPTH_32F, 1); + float sum = cvSum(test_img).val[0]; + cvConvertScale(test_img, patch_32f, 1.0f/sum); + + //ProjectPCASample(patch_32f, avg, eigenvectors, pca_coeffs); + //Projecting PCA + CvMat* patch_mat = ConvertImageToMatrix(patch_32f); + CvMat* temp = cvCreateMat(1, eigenvectors->cols, CV_32FC1); + cvProjectPCA(patch_mat, avg, eigenvectors, temp); + CvMat temp1; + cvGetSubRect(temp, &temp1, cvRect(0, 0, pca_coeffs->cols, 1)); + cvCopy(&temp1, pca_coeffs); + cvReleaseMat(&temp); + cvReleaseMat(&patch_mat); + //End of projecting + + cvReleaseImage(&patch_32f); + cvReleaseImage(&test_img); + // } + //-------- - - //float* target = new float[m_pca_dim_low]; - //::cvflann::KNNResultSet res(1,pca_coeffs->data.fl,m_pca_dim_low); - //::cvflann::SearchParams params; - //params.checks = -1; - - //int maxDepth = 1000000; - //int neighbors_count = 1; - //int* neighborsIdx = new int[neighbors_count]; - //float* distances = new float[neighbors_count]; - //if (m_pca_descriptors_tree->findNearest(pca_coeffs->data.fl,neighbors_count,maxDepth,neighborsIdx,0,distances) > 0) - //{ - // desc_idx = neighborsIdx[0] / m_pose_count; - // pose_idx = neighborsIdx[0] % m_pose_count; - // distance = distances[0]; - //} - //delete[] neighborsIdx; - //delete[] distances; - - cv::Mat m_object(1, m_pca_dim_low, CV_32F); - cv::Mat m_indices(1, 1, CV_32S); - cv::Mat m_dists(1, 1, CV_32F); - - float* object_ptr = m_object.ptr(0); - for (int i=0;idata.fl[i]; - } - - m_pca_descriptors_tree->knnSearch(m_object, m_indices, m_dists, 1, cv::flann::SearchParams(-1) ); - - desc_idx = ((int*)(m_indices.ptr(0)))[0] / m_pose_count; - pose_idx = ((int*)(m_indices.ptr(0)))[0] % m_pose_count; - distance = ((float*)(m_dists.ptr(0)))[0]; - - // delete[] target; - - + + //float* target = new float[m_pca_dim_low]; + //::cvflann::KNNResultSet res(1,pca_coeffs->data.fl,m_pca_dim_low); + //::cvflann::SearchParams params; + //params.checks = -1; + + //int maxDepth = 1000000; + //int neighbors_count = 1; + //int* neighborsIdx = new int[neighbors_count]; + //float* distances = new float[neighbors_count]; + //if (m_pca_descriptors_tree->findNearest(pca_coeffs->data.fl,neighbors_count,maxDepth,neighborsIdx,0,distances) > 0) + //{ + // desc_idx = neighborsIdx[0] / m_pose_count; + // pose_idx = neighborsIdx[0] % m_pose_count; + // distance = distances[0]; + //} + //delete[] neighborsIdx; + //delete[] distances; + + cv::Mat m_object(1, m_pca_dim_low, CV_32F); + cv::Mat m_indices(1, 1, CV_32S); + cv::Mat m_dists(1, 1, CV_32F); + + float* object_ptr = m_object.ptr(0); + for (int i=0;idata.fl[i]; + } + + m_pca_descriptors_tree->knnSearch(m_object, m_indices, m_dists, 1, cv::flann::SearchParams(-1) ); + + desc_idx = ((int*)(m_indices.ptr(0)))[0] / m_pose_count; + pose_idx = ((int*)(m_indices.ptr(0)))[0] % m_pose_count; + distance = ((float*)(m_dists.ptr(0)))[0]; + + // delete[] target; + + // for(int i = 0; i < desc_count; i++) // { // int _pose_idx = -1; @@ -905,14 +905,14 @@ namespace cv{ //#if 0 // descriptors[i].EstimatePose(patch, _pose_idx, _distance); //#else - // if (!avg) - // { - // descriptors[i].EstimatePosePCA(patch, _pose_idx, _distance, avg, eigenvectors); - // } - // else - // { - // descriptors[i].EstimatePosePCA(pca_coeffs, _pose_idx, _distance, avg, eigenvectors); - // } + // if (!avg) + // { + // descriptors[i].EstimatePosePCA(patch, _pose_idx, _distance, avg, eigenvectors); + // } + // else + // { + // descriptors[i].EstimatePosePCA(pca_coeffs, _pose_idx, _distance, avg, eigenvectors); + // } //#endif // // if(_distance < distance) @@ -948,7 +948,7 @@ namespace cv{ IplImage* test_img = cvCreateImage(cvSize(patch_width,patch_height), IPL_DEPTH_8U, 1); if(_roi.width != patch_width|| _roi.height != patch_height) { - + cvResize(patch, test_img); _roi = cvGetImageROI(test_img); } @@ -959,7 +959,7 @@ namespace cv{ IplImage* patch_32f = cvCreateImage(cvSize(_roi.width, _roi.height), IPL_DEPTH_32F, 1); double sum = cvSum(test_img).val[0]; cvConvertScale(test_img, patch_32f, 1.0f/sum); - + //ProjectPCASample(patch_32f, avg, eigenvectors, pca_coeffs); //Projecting PCA CvMat* patch_mat = ConvertImageToMatrix(patch_32f); @@ -971,19 +971,19 @@ namespace cv{ cvReleaseMat(&temp); cvReleaseMat(&patch_mat); //End of projecting - + cvReleaseImage(&patch_32f); cvReleaseImage(&test_img); } //-------- - - - + + + for(int i = 0; i < desc_count; i++) { int _pose_idx = -1; float _distance = 0; - + #if 0 descriptors[i].EstimatePose(patch, _pose_idx, _distance); #else @@ -996,7 +996,7 @@ namespace cv{ descriptors[i].EstimatePosePCA(pca_coeffs, _pose_idx, _distance, avg, eigenvectors); } #endif - + for (int j=0;j 244 && roi.y < 200) { @@ -1049,7 +1049,7 @@ namespace cv{ cvWaitKey(0); } #endif - + FindOneWayDescriptor(desc_count, descriptors, input_patch, _desc_idx, _pose_idx, _distance, avg, eigenvectors); if(_distance < distance) { @@ -1059,13 +1059,13 @@ namespace cv{ scale = cur_scale; } } - - + + cvSetImageROI((IplImage*)patch, roi); cvReleaseImage(&input_patch); - + } - + void FindOneWayDescriptorEx(int desc_count, const OneWayDescriptor* descriptors, IplImage* patch, float scale_min, float scale_max, float scale_step, int n, std::vector& desc_idxs, std::vector& pose_idxs, @@ -1075,10 +1075,10 @@ namespace cv{ CvSize patch_size = descriptors[0].GetPatchSize(); IplImage* input_patch; CvRect roi; - + input_patch= cvCreateImage(patch_size, IPL_DEPTH_8U, 1); roi = cvGetImageROI((IplImage*)patch); - + // float min_distance = 1e10; std::vector _desc_idxs; _desc_idxs.resize(n); @@ -1086,22 +1086,22 @@ namespace cv{ _pose_idxs.resize(n); std::vector _distances; _distances.resize(n); - - + + for (int i=0;idepth == 32) { for(int y = 0; y < roi.height; y++) @@ -1212,10 +1212,10 @@ namespace cv{ printf("Image depth %d is not supported\n", patch->depth); return 0; } - + return mat; } - + OneWayDescriptorBase::OneWayDescriptorBase(CvSize patch_size, int pose_count, const char* train_path, const char* pca_config, const char* pca_hr_config, const char* pca_desc_config, int pyr_levels, @@ -1226,21 +1226,21 @@ namespace cv{ m_pca_descriptors_matrix = 0; m_pca_descriptors_tree = 0; #endif - // m_pca_descriptors_matrix = 0; + // m_pca_descriptors_matrix = 0; m_patch_size = patch_size; m_pose_count = pose_count; m_pyr_levels = pyr_levels; m_poses = 0; m_transforms = 0; - + m_pca_avg = 0; m_pca_eigenvectors = 0; m_pca_hr_avg = 0; m_pca_hr_eigenvectors = 0; m_pca_descriptors = 0; - + m_descriptors = 0; - + if(train_path == 0 || strlen(train_path) == 0) { // skip pca loading @@ -1255,9 +1255,9 @@ namespace cv{ sprintf(pca_hr_config_filename, "%s/%s", train_path, pca_hr_config); readPCAFeatures(pca_hr_config_filename, &m_pca_hr_avg, &m_pca_hr_eigenvectors); } - + m_pca_descriptors = new OneWayDescriptor[m_pca_dim_high + 1]; - + #if !defined(_GH_REGIONS) if(pca_desc_config && strlen(pca_desc_config) > 0) // if(0) @@ -1277,7 +1277,7 @@ namespace cv{ } #endif //_GH_REGIONS // SavePCADescriptors("./pca_descriptors.yml"); - + } OneWayDescriptorBase::OneWayDescriptorBase(CvSize patch_size, int pose_count, const string &pca_filename, @@ -1346,8 +1346,8 @@ namespace cv{ scale_min = fn["minScale"]; scale_max = fn["maxScale"]; scale_step = fn["stepScale"]; - - LoadPCAall (fn); + + LoadPCAall (fn); } void OneWayDescriptorBase::LoadPCAall (const FileNode &fn) @@ -1364,21 +1364,21 @@ namespace cv{ { cvReleaseMat(&m_pca_avg); cvReleaseMat(&m_pca_eigenvectors); - + if(m_pca_hr_eigenvectors) { delete[] m_pca_descriptors; cvReleaseMat(&m_pca_hr_avg); cvReleaseMat(&m_pca_hr_eigenvectors); } - - + + if(m_descriptors) delete []m_descriptors; if(m_poses) delete []m_poses; - + if (m_transforms) { for(int i = 0; i < m_pose_count; i++) @@ -1398,7 +1398,7 @@ namespace cv{ } #endif } - + void OneWayDescriptorBase::clear(){ if (m_descriptors) { @@ -1428,7 +1428,7 @@ namespace cv{ m_poses[i] = GenRandomAffinePose(); } } - + void OneWayDescriptorBase::InitializeTransformsFromPoses() { m_transforms = new CvMat*[m_pose_count]; @@ -1438,19 +1438,19 @@ namespace cv{ GenerateAffineTransformFromPose(cvSize(m_patch_size.width*2, m_patch_size.height*2), m_poses[i], m_transforms[i]); } } - + void OneWayDescriptorBase::InitializePoseTransforms() { InitializePoses(); InitializeTransformsFromPoses(); } - + void OneWayDescriptorBase::InitializeDescriptor(int desc_idx, IplImage* train_image, const KeyPoint& keypoint, const char* feature_label) { - + // TBD add support for octave != 0 CvPoint center = keypoint.pt; - + CvRect roi = cvRect(center.x - m_patch_size.width/2, center.y - m_patch_size.height/2, m_patch_size.width, m_patch_size.height); cvResetImageROI(train_image); roi = fit_rect_fixedsize(roi, train_image); @@ -1459,17 +1459,17 @@ namespace cv{ { return; } - + InitializeDescriptor(desc_idx, train_image, feature_label); cvResetImageROI(train_image); } - + void OneWayDescriptorBase::InitializeDescriptor(int desc_idx, IplImage* train_image, const char* feature_label) { m_descriptors[desc_idx].SetPCADimHigh(m_pca_dim_high); m_descriptors[desc_idx].SetPCADimLow(m_pca_dim_low); m_descriptors[desc_idx].SetTransforms(m_poses, m_transforms); - + if(!m_pca_hr_eigenvectors) { m_descriptors[desc_idx].Initialize(m_pose_count, train_image, feature_label); @@ -1479,24 +1479,24 @@ namespace cv{ m_descriptors[desc_idx].InitializeFast(m_pose_count, train_image, feature_label, m_pca_hr_avg, m_pca_hr_eigenvectors, m_pca_descriptors); } - + if(m_pca_avg) { m_descriptors[desc_idx].InitializePCACoeffs(m_pca_avg, m_pca_eigenvectors); } } - + void OneWayDescriptorBase::FindDescriptor(IplImage* src, cv::Point2f pt, int& desc_idx, int& pose_idx, float& distance) const { CvRect roi = cvRect(cvRound(pt.x - m_patch_size.width/4), cvRound(pt.y - m_patch_size.height/4), m_patch_size.width/2, m_patch_size.height/2); cvSetImageROI(src, roi); - + FindDescriptor(src, desc_idx, pose_idx, distance); - cvResetImageROI(src); + cvResetImageROI(src); } - + void OneWayDescriptorBase::FindDescriptor(IplImage* patch, int& desc_idx, int& pose_idx, float& distance, float* _scale, float* scale_ranges) const { #if 0 @@ -1505,15 +1505,15 @@ namespace cv{ float min = scale_min; float max = scale_max; float step = scale_step; - + if (scale_ranges) { min = scale_ranges[0]; max = scale_ranges[1]; } - + float scale = 1.0f; - + #if !defined(_KDTREE) cv::FindOneWayDescriptorEx(m_train_feature_count, m_descriptors, patch, min, max, step, desc_idx, pose_idx, distance, scale, @@ -1523,50 +1523,50 @@ namespace cv{ min, max, step, desc_idx, pose_idx, distance, scale, m_pca_avg, m_pca_eigenvectors); #endif - + if (_scale) *_scale = scale; - + #endif } - + void OneWayDescriptorBase::FindDescriptor(IplImage* patch, int n, std::vector& desc_idxs, std::vector& pose_idxs, std::vector& distances, std::vector& _scales, float* scale_ranges) const { float min = scale_min; float max = scale_max; float step = scale_step; - + if (scale_ranges) { min = scale_ranges[0]; max = scale_ranges[1]; } - + distances.resize(n); _scales.resize(n); desc_idxs.resize(n); pose_idxs.resize(n); /*float scales = 1.0f;*/ - + cv::FindOneWayDescriptorEx(m_train_feature_count, m_descriptors, patch, min, max, step ,n, desc_idxs, pose_idxs, distances, _scales, m_pca_avg, m_pca_eigenvectors); - + } - + void OneWayDescriptorBase::SetPCAHigh(CvMat* avg, CvMat* eigenvectors) { m_pca_hr_avg = cvCloneMat(avg); m_pca_hr_eigenvectors = cvCloneMat(eigenvectors); } - + void OneWayDescriptorBase::SetPCALow(CvMat* avg, CvMat* eigenvectors) { m_pca_avg = cvCloneMat(avg); m_pca_eigenvectors = cvCloneMat(eigenvectors); } - + void OneWayDescriptorBase::AllocatePCADescriptors() { m_pca_descriptors = new OneWayDescriptor[m_pca_dim_high + 1]; @@ -1576,7 +1576,7 @@ namespace cv{ m_pca_descriptors[i].SetPCADimLow(m_pca_dim_low); } } - + void OneWayDescriptorBase::CreatePCADescriptors() { if(m_pca_descriptors == 0) @@ -1584,27 +1584,27 @@ namespace cv{ AllocatePCADescriptors(); } IplImage* frontal = cvCreateImage(m_patch_size, IPL_DEPTH_32F, 1); - + eigenvector2image(m_pca_hr_avg, frontal); m_pca_descriptors[0].SetTransforms(m_poses, m_transforms); m_pca_descriptors[0].Initialize(m_pose_count, frontal, "", 0); - + for(int j = 0; j < m_pca_dim_high; j++) { CvMat eigenvector; cvGetSubRect(m_pca_hr_eigenvectors, &eigenvector, cvRect(0, j, m_pca_hr_eigenvectors->cols, 1)); eigenvector2image(&eigenvector, frontal); - + m_pca_descriptors[j + 1].SetTransforms(m_poses, m_transforms); m_pca_descriptors[j + 1].Initialize(m_pose_count, frontal, "", 0); - + printf("Created descriptor for PCA component %d\n", j); } - + cvReleaseImage(&frontal); } - - + + int OneWayDescriptorBase::LoadPCADescriptors(const char* filename) { FileStorage fs = FileStorage (filename, FileStorage::READ); @@ -1618,7 +1618,7 @@ namespace cv{ printf("Successfully read %d pca components\n", m_pca_dim_high); fs.release (); - + return 1; } @@ -1726,7 +1726,7 @@ namespace cv{ cvReleaseMat(&eigenvalues); } - void extractPatches (IplImage *img, vector& patches, CvSize patch_size) + static void extractPatches (IplImage *img, vector& patches, CvSize patch_size) { vector features; Ptr surf_extractor = FeatureDetector::create("SURF"); @@ -1891,13 +1891,13 @@ namespace cv{ { CvMemStorage* storage = cvCreateMemStorage(); CvFileStorage* fs = cvOpenFileStorage(filename, storage, CV_STORAGE_WRITE); - + SavePCADescriptors (fs); - + cvReleaseMemStorage(&storage); cvReleaseFileStorage(&fs); } - + void OneWayDescriptorBase::SavePCADescriptors(CvFileStorage *fs) const { cvWriteInt(fs, "pca_components_number", m_pca_dim_high); @@ -1939,32 +1939,32 @@ namespace cv{ m_descriptors[i].SetPCADimLow(m_pca_dim_low); } } - + void OneWayDescriptorBase::InitializeDescriptors(IplImage* train_image, const vector& features, const char* feature_label, int desc_start_idx) { for(int i = 0; i < (int)features.size(); i++) { InitializeDescriptor(desc_start_idx + i, train_image, features[i], feature_label); - + } cvResetImageROI(train_image); - + #if defined(_KDTREE) ConvertDescriptorsArrayToTree(); #endif } - + void OneWayDescriptorBase::CreateDescriptorsFromImage(IplImage* src, const std::vector& features) { m_train_feature_count = (int)features.size(); - + m_descriptors = new OneWayDescriptor[m_train_feature_count]; - + InitializeDescriptors(src, features); - + } - + #if defined(_KDTREE) void OneWayDescriptorBase::ConvertDescriptorsArrayToTree() { @@ -1972,18 +1972,18 @@ namespace cv{ if (n<1) return; int pca_dim_low = this->GetDescriptor(0)->GetPCADimLow(); - + //if (!m_pca_descriptors_matrix) - // m_pca_descriptors_matrix = new ::cvflann::Matrix(n*m_pose_count,pca_dim_low); + // m_pca_descriptors_matrix = new ::cvflann::Matrix(n*m_pose_count,pca_dim_low); //else //{ - // if ((m_pca_descriptors_matrix->cols != pca_dim_low)&&(m_pca_descriptors_matrix->rows != n*m_pose_count)) - // { - // delete m_pca_descriptors_matrix; - // m_pca_descriptors_matrix = new ::cvflann::Matrix(n*m_pose_count,pca_dim_low); - // } + // if ((m_pca_descriptors_matrix->cols != pca_dim_low)&&(m_pca_descriptors_matrix->rows != n*m_pose_count)) + // { + // delete m_pca_descriptors_matrix; + // m_pca_descriptors_matrix = new ::cvflann::Matrix(n*m_pose_count,pca_dim_low); + // } //} - + m_pca_descriptors_matrix = cvCreateMat(n*m_pose_count,pca_dim_low,CV_32FC1); for (int i=0;ibuildIndex(); } #endif - + void OneWayDescriptorObject::Allocate(int train_feature_count, int object_feature_count) { OneWayDescriptorBase::Allocate(train_feature_count); m_object_feature_count = object_feature_count; - + m_part_id = new int[m_object_feature_count]; } - - + + void OneWayDescriptorObject::InitializeObjectDescriptors(IplImage* train_image, const vector& features, const char* feature_label, int desc_start_idx, float scale, int is_background) { InitializeDescriptors(train_image, features, feature_label, desc_start_idx); - + for(int i = 0; i < (int)features.size(); i++) { CvPoint center = features[i].pt; - + if(!is_background) { // remember descriptor part id @@ -2034,12 +2034,12 @@ namespace cv{ } cvResetImageROI(train_image); } - + int OneWayDescriptorObject::IsDescriptorObject(int desc_idx) const { return desc_idx < m_object_feature_count ? 1 : 0; } - + int OneWayDescriptorObject::MatchPointToPart(CvPoint pt) const { int idx = -1; @@ -2052,23 +2052,23 @@ namespace cv{ break; } } - + return idx; } - + int OneWayDescriptorObject::GetDescriptorPart(int desc_idx) const { // return MatchPointToPart(GetDescriptor(desc_idx)->GetCenter()); return desc_idx < m_object_feature_count ? m_part_id[desc_idx] : -1; } - + OneWayDescriptorObject::OneWayDescriptorObject(CvSize patch_size, int pose_count, const char* train_path, const char* pca_config, const char* pca_hr_config, const char* pca_desc_config, int pyr_levels) : OneWayDescriptorBase(patch_size, pose_count, train_path, pca_config, pca_hr_config, pca_desc_config, pyr_levels) { m_part_id = 0; } - + OneWayDescriptorObject::OneWayDescriptorObject(CvSize patch_size, int pose_count, const string &pca_filename, const string &train_path, const string &images_list, float _scale_min, float _scale_max, float _scale_step, int pyr_levels) : OneWayDescriptorBase(patch_size, pose_count, pca_filename, train_path, images_list, _scale_min, _scale_max, _scale_step, pyr_levels) @@ -2081,7 +2081,7 @@ namespace cv{ if (m_part_id) delete []m_part_id; } - + vector OneWayDescriptorObject::_GetLabeledFeatures() const { vector features; @@ -2089,10 +2089,10 @@ namespace cv{ { features.push_back(m_train_features[i]); } - + return features; } - + void eigenvector2image(CvMat* eigenvector, IplImage* img) { CvRect roi = cvGetImageROI(img); @@ -2150,11 +2150,11 @@ namespace cv{ cvReleaseMat(&_eigenvectors); } } - + /****************************************************************************************\ * OneWayDescriptorMatcher * \****************************************************************************************/ - + OneWayDescriptorMatcher::Params::Params( int _poseCount, Size _patchSize, string _pcaFilename, string _trainPath, string _trainImagesList, float _minScale, float _maxScale, float _stepScale ) : @@ -2162,45 +2162,45 @@ namespace cv{ trainPath(_trainPath), trainImagesList(_trainImagesList), minScale(_minScale), maxScale(_maxScale), stepScale(_stepScale) {} - - + + OneWayDescriptorMatcher::OneWayDescriptorMatcher( const Params& _params) { initialize(_params); } - + OneWayDescriptorMatcher::~OneWayDescriptorMatcher() {} - + void OneWayDescriptorMatcher::initialize( const Params& _params, const Ptr& _base ) { clear(); - + if( _base.empty() ) base = _base; - + params = _params; } - + void OneWayDescriptorMatcher::clear() { GenericDescriptorMatcher::clear(); - + prevTrainCount = 0; if( !base.empty() ) base->clear(); } - + void OneWayDescriptorMatcher::train() { if( base.empty() || prevTrainCount < (int)trainPointCollection.keypointCount() ) { base = new OneWayDescriptorObject( params.patchSize, params.poseCount, params.pcaFilename, params.trainPath, params.trainImagesList, params.minScale, params.maxScale, params.stepScale ); - + base->Allocate( (int)trainPointCollection.keypointCount() ); prevTrainCount = (int)trainPointCollection.keypointCount(); - + const vector >& points = trainPointCollection.getKeypoints(); int count = 0; for( size_t i = 0; i < points.size(); i++ ) @@ -2209,26 +2209,26 @@ namespace cv{ for( size_t j = 0; j < points[i].size(); j++ ) base->InitializeDescriptor( count++, &_image, points[i][j], "" ); } - + #if defined(_KDTREE) base->ConvertDescriptorsArrayToTree(); #endif } } - + bool OneWayDescriptorMatcher::isMaskSupported() { return false; } - + void OneWayDescriptorMatcher::knnMatchImpl( const Mat& queryImage, vector& queryKeypoints, vector >& matches, int knn, const vector& /*masks*/, bool /*compactResult*/ ) { train(); - + CV_Assert( knn == 1 ); // knn > 1 unsupported because of bug in OneWayDescriptorBase for this case - + matches.resize( queryKeypoints.size() ); IplImage _qimage = queryImage; for( size_t i = 0; i < queryKeypoints.size(); i++ ) @@ -2239,13 +2239,13 @@ namespace cv{ matches[i].push_back( DMatch((int)i, descIdx, distance) ); } } - + void OneWayDescriptorMatcher::radiusMatchImpl( const Mat& queryImage, vector& queryKeypoints, vector >& matches, float maxDistance, const vector& /*masks*/, bool /*compactResult*/ ) { train(); - + matches.resize( queryKeypoints.size() ); IplImage _qimage = queryImage; for( size_t i = 0; i < queryKeypoints.size(); i++ ) @@ -2257,33 +2257,33 @@ namespace cv{ matches[i].push_back( DMatch((int)i, descIdx, distance) ); } } - + void OneWayDescriptorMatcher::read( const FileNode &fn ) { base = new OneWayDescriptorObject( params.patchSize, params.poseCount, string (), string (), string (), params.minScale, params.maxScale, params.stepScale ); base->Read (fn); } - + void OneWayDescriptorMatcher::write( FileStorage& fs ) const { base->Write (fs); } - + bool OneWayDescriptorMatcher::empty() const { return base.empty() || base->empty(); } - + Ptr OneWayDescriptorMatcher::clone( bool emptyTrainData ) const { OneWayDescriptorMatcher* matcher = new OneWayDescriptorMatcher( params ); - + if( !emptyTrainData ) { CV_Error( CV_StsNotImplemented, "deep clone functionality is not implemented, because " "OneWayDescriptorBase has not copy constructor or clone method "); - + //matcher->base; matcher->params = params; matcher->prevTrainCount = prevTrainCount; diff --git a/modules/legacy/src/precomp.hpp b/modules/legacy/src/precomp.hpp index 7c1993b..d919ca3 100644 --- a/modules/legacy/src/precomp.hpp +++ b/modules/legacy/src/precomp.hpp @@ -41,11 +41,11 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4710 4711 4514 4996 ) #endif -#ifdef HAVE_CVCONFIG_H +#ifdef HAVE_CVCONFIG_H #include "cvconfig.h" #endif diff --git a/modules/legacy/src/testseq.cpp b/modules/legacy/src/testseq.cpp index 1b15efe..dd14fe1 100644 --- a/modules/legacy/src/testseq.cpp +++ b/modules/legacy/src/testseq.cpp @@ -65,7 +65,7 @@ typedef struct CvTSTrans float angle; } CvTSTrans; -void SET_TRANS_0(CvTSTrans *pT) +static void SET_TRANS_0(CvTSTrans *pT) { memset(pT,0,sizeof(CvTSTrans)); pT->C = 1; diff --git a/modules/legacy/src/trifocal.cpp b/modules/legacy/src/trifocal.cpp index 22f2fda..cf74108 100644 --- a/modules/legacy/src/trifocal.cpp +++ b/modules/legacy/src/trifocal.cpp @@ -99,8 +99,9 @@ void icvReconstructPointsFor3View( CvMat* projMatr1,CvMat* projMatr2,CvMat* proj /*==========================================================================================*/ /* Functions for calculation the tensor */ /*==========================================================================================*/ +#if 0 #if 1 -void fprintMatrix(FILE* file,CvMat* matrix) +static void fprintMatrix(FILE* file,CvMat* matrix) { int i,j; fprintf(file,"\n"); @@ -116,7 +117,7 @@ void fprintMatrix(FILE* file,CvMat* matrix) #endif /*==========================================================================================*/ -void icvNormalizePoints( CvMat* points, CvMat* normPoints,CvMat* cameraMatr ) +static void icvNormalizePoints( CvMat* points, CvMat* normPoints,CvMat* cameraMatr ) { /* Normalize image points using camera matrix */ @@ -169,7 +170,7 @@ void icvNormalizePoints( CvMat* points, CvMat* normPoints,CvMat* cameraMatr ) return; } - +#endif /*=====================================================================================*/ /* @@ -405,7 +406,7 @@ int icvComputeProjectMatrices6Points( CvMat* points1,CvMat* points2,CvMat* point } /*==========================================================================================*/ -int icvGetRandNumbers(int range,int count,int* arr) +static int icvGetRandNumbers(int range,int count,int* arr) { /* Generate random numbers [0,range-1] */ @@ -454,7 +455,7 @@ int icvGetRandNumbers(int range,int count,int* arr) return 1; } /*==========================================================================================*/ -void icvSelectColsByNumbers(CvMat* srcMatr, CvMat* dstMatr, int* indexes,int number) +static void icvSelectColsByNumbers(CvMat* srcMatr, CvMat* dstMatr, int* indexes,int number) { CV_FUNCNAME( "icvSelectColsByNumbers" ); @@ -501,7 +502,7 @@ void icvSelectColsByNumbers(CvMat* srcMatr, CvMat* dstMatr, int* indexes,int num } /*==========================================================================================*/ -void icvProject4DPoints(CvMat* points4D,CvMat* projMatr, CvMat* projPoints) +static void icvProject4DPoints(CvMat* points4D,CvMat* projMatr, CvMat* projPoints) { CvMat* tmpProjPoints = 0; @@ -584,7 +585,8 @@ void icvProject4DPoints(CvMat* points4D,CvMat* projMatr, CvMat* projPoints) return; } /*==========================================================================================*/ -int icvCompute3ProjectMatricesNPointsStatus( CvMat** points,/* 3 arrays of points on image */ +#if 0 +static int icvCompute3ProjectMatricesNPointsStatus( CvMat** points,/* 3 arrays of points on image */ CvMat** projMatrs,/* array of 3 prejection matrices */ CvMat** statuses,/* 3 arrays of status of points */ double threshold,/* Threshold for good point */ @@ -783,6 +785,7 @@ int icvCompute3ProjectMatricesNPointsStatus( CvMat** points,/* 3 arrays of point return numProjMatrs; } +#endif /*==========================================================================================*/ int icvComputeProjectMatricesNPoints( CvMat* points1,CvMat* points2,CvMat* points3, @@ -2350,8 +2353,8 @@ void ReconstructPointsFor3View_bySolve( CvMat* projMatr1,CvMat* projMatr2,CvMat* #endif /*==========================================================================================*/ - -void icvComputeCameraExrinnsicByPosition(CvMat* camPos, CvMat* rotMatr, CvMat* transVect) +#if 0 +static void icvComputeCameraExrinnsicByPosition(CvMat* camPos, CvMat* rotMatr, CvMat* transVect) { /* We know position of camera. we must to compute rotate matrix and translate vector */ @@ -2468,7 +2471,7 @@ void icvComputeCameraExrinnsicByPosition(CvMat* camPos, CvMat* rotMatr, CvMat* t /*==========================================================================================*/ -void FindTransformForProjectMatrices(CvMat* projMatr1,CvMat* projMatr2,CvMat* rotMatr,CvMat* transVect) +static void FindTransformForProjectMatrices(CvMat* projMatr1,CvMat* projMatr2,CvMat* rotMatr,CvMat* transVect) { /* Computes homography for project matrix be "canonical" form */ CV_FUNCNAME( "computeProjMatrHomography" ); @@ -2586,7 +2589,7 @@ void icvComputeQknowPrincipalPoint(int numImages, CvMat **projMatrs,CvMat *matrQ /* Part with metric reconstruction */ #if 1 -void icvComputeQ(int numMatr, CvMat** projMatr, CvMat** cameraMatr, CvMat* matrQ) +static void icvComputeQ(int numMatr, CvMat** projMatr, CvMat** cameraMatr, CvMat* matrQ) { /* K*K' = P*Q*P' */ /* try to solve Q by linear method */ @@ -2731,7 +2734,7 @@ void icvComputeQ(int numMatr, CvMat** projMatr, CvMat** cameraMatr, CvMat* matrQ #endif /*-----------------------------------------------------------------------------------------------------*/ -void icvDecomposeQ(CvMat* /*matrQ*/,CvMat* /*matrH*/) +static void icvDecomposeQ(CvMat* /*matrQ*/,CvMat* /*matrH*/) { #if 0 /* Use SVD to decompose matrix Q=H*I*H' */ @@ -2789,3 +2792,5 @@ void icvDecomposeQ(CvMat* /*matrQ*/,CvMat* /*matrH*/) #endif } +#endif + diff --git a/modules/legacy/src/vecfacetracking.cpp b/modules/legacy/src/vecfacetracking.cpp index 2dbc462..8b45ac4 100644 --- a/modules/legacy/src/vecfacetracking.cpp +++ b/modules/legacy/src/vecfacetracking.cpp @@ -48,7 +48,7 @@ #include "_vectrack.h" #define NUM_FACE_ELEMENTS 3 -enum +enum { MOUTH = 0, LEYE = 1, @@ -69,7 +69,7 @@ int ChoiceTrackingFace2(CvFaceTracker* pTF, const int nElements, const CvFaceEle inline int GetEnergy(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoint* ptTempl, CvRect* rTempl); inline int GetEnergy2(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoint* ptTempl, CvRect* rTempl, int* element); inline double CalculateTransformationLMS3_0( CvPoint* pTemplPoints, CvPoint* pSrcPoints); -inline double CalculateTransformationLMS3( CvPoint* pTemplPoints, +inline double CalculateTransformationLMS3( CvPoint* pTemplPoints, CvPoint* pSrcPoints, double* pdbAverageScale, double* pdbAverageRotate, @@ -91,13 +91,13 @@ struct CvTrackingRect int Energy(const CvTrackingRect& prev) { int prev_color = 0 == prev.iColor ? iColor : prev.iColor; - iEnergy = 1 * pow2(r.width - prev.r.width) + - 1 * pow2(r.height - prev.r.height) + - 1 * pow2(iColor - prev_color) / 4 + - - 1 * nRectsInThis + - - 0 * nRectsOnTop + - + 0 * nRectsOnLeft + - + 0 * nRectsOnRight + + iEnergy = 1 * pow2(r.width - prev.r.width) + + 1 * pow2(r.height - prev.r.height) + + 1 * pow2(iColor - prev_color) / 4 + + - 1 * nRectsInThis + + - 0 * nRectsOnTop + + + 0 * nRectsOnLeft + + + 0 * nRectsOnRight + + 0 * nRectsOnBottom; return iEnergy; } @@ -110,10 +110,10 @@ struct CvFaceTracker double dbRotateDelta; double dbRotateAngle; CvPoint ptRotate; - + CvPoint ptTempl[NUM_FACE_ELEMENTS]; CvRect rTempl[NUM_FACE_ELEMENTS]; - + IplImage* imgGray; IplImage* imgThresh; CvMemStorage* mstgContours; @@ -149,8 +149,8 @@ struct CvFaceTracker imgGray = cvCreateImage(cvSize(imgGray->width, imgGray->height), 8, 1); imgThresh = cvCreateImage(cvSize(imgGray->width, imgGray->height), 8, 1); mstgContours = cvCreateMemStorage(); - if ((NULL == imgGray) || - (NULL == imgThresh) || + if ((NULL == imgGray) || + (NULL == imgThresh) || (NULL == mstgContours)) return FALSE; return TRUE; @@ -162,11 +162,11 @@ struct CvFaceTracker ReallocImage(&imgThresh, sz, 1); ptRotate = face[MOUTH].ptCenter; float m[6]; - CvMat mat = cvMat( 2, 3, CV_32FC1, m ); + CvMat mat = cvMat( 2, 3, CV_32FC1, m ); if (NULL == imgGray || NULL == imgThresh) return FALSE; - + /*m[0] = (float)cos(-dbRotateAngle*CV_PI/180.); m[1] = (float)sin(-dbRotateAngle*CV_PI/180.); m[2] = (float)ptRotate.x; @@ -175,7 +175,7 @@ struct CvFaceTracker m[5] = (float)ptRotate.y;*/ cv2DRotationMatrix( cvPointTo32f(ptRotate), -dbRotateAngle, 1., &mat ); cvWarpAffine( img, imgGray, &mat ); - + if (NULL == mstgContours) mstgContours = cvCreateMemStorage(); else @@ -225,7 +225,7 @@ protected: void Energy(); }; //class CvFaceElement -int CV_CDECL CompareEnergy(const void* el1, const void* el2, void*) +inline int CV_CDECL CompareEnergy(const void* el1, const void* el2, void*) { return ((CvTrackingRect*)el1)->iEnergy - ((CvTrackingRect*)el2)->iEnergy; }// int CV_CDECL CompareEnergy(const void* el1, const void* el2, void*) @@ -322,7 +322,7 @@ void CvFaceElement::FindContours(IplImage* img, IplImage* thresh, int nLayers, i } for (CvSeq* internal = external->v_next; internal; internal = internal->h_next) { - cr.r = cvContourBoundingRect(internal); + cr.r = cvContourBoundingRect(internal); Move(cr.r, roi.x, roi.y); if (RectInRect(cr.r, m_rROI) && cr.r.width > dMinSize && cr.r.height > dMinSize) { @@ -353,7 +353,7 @@ void CvFaceElement::MergeRects(int d) for (j = i + 1; j < nRects; j++) { CvTrackingRect* pRect2 = (CvTrackingRect*)(reader2.ptr); - if (abs(pRect1->ptCenter.y - pRect2->ptCenter.y) < d && + if (abs(pRect1->ptCenter.y - pRect2->ptCenter.y) < d && abs(pRect1->r.height - pRect2->r.height) < d) { CvTrackingRect rNew; @@ -432,7 +432,7 @@ cvInitFaceTracker(CvFaceTracker* pFaceTracker, const IplImage* imgGray, CvRect* (NULL == pRects) || (nRects < NUM_FACE_ELEMENTS)) return NULL; - + //int new_face = FALSE; CvFaceTracker* pFace = pFaceTracker; if (NULL == pFace) @@ -468,7 +468,7 @@ cvTrackFace(CvFaceTracker* pFaceTracker, IplImage* imgGray, CvRect* pRects, int pFaceTracker->InitNextImage(imgGray); *ptRotate = pFaceTracker->ptRotate; *dbAngleRotate = pFaceTracker->dbRotateAngle; - + int nElements = 16; double dx = pFaceTracker->face[LEYE].ptCenter.x - pFaceTracker->face[REYE].ptCenter.x; double dy = pFaceTracker->face[LEYE].ptCenter.y - pFaceTracker->face[REYE].ptCenter.y; @@ -476,9 +476,9 @@ cvTrackFace(CvFaceTracker* pFaceTracker, IplImage* imgGray, CvRect* pRects, int int d = cvRound(0.25 * d_eyes); int dMinSize = d; int nRestarts = 0; - + int elem; - + CvFaceElement big_face[NUM_FACE_ELEMENTS]; START: // init @@ -533,7 +533,7 @@ START: } if (2 == elements) find2 = TRUE; - else + else restart = TRUE; } } @@ -563,13 +563,13 @@ RESTART: pFaceTracker->iTrackingFaceType = noel; found = TRUE; } - else + else { restart = TRUE; goto RESTART; } } - + if (found) { // angle by mouth & eyes @@ -613,7 +613,7 @@ void ThresholdingParam(IplImage *imgGray, int iNumLayers, int &iMinLevel, int &i { assert(imgGray != NULL); assert(imgGray->nChannels == 1); - int i, j; + int i, j; // create histogram int histImg[256] = {0}; uchar* buffImg = (uchar*)imgGray->imageData; @@ -760,7 +760,7 @@ int ChoiceTrackingFace2(CvFaceTracker* pTF, const int nElements, const CvFaceEle double prev_d02 = sqrt((double)prev_v02.x*prev_v02.x + prev_v02.y*prev_v02.y); double new_d01 = sqrt((double)new_v01.x*new_v01.x + new_v01.y*new_v01.y); double scale = templ_d01 / new_d01; - double new_d02 = templ_d02 / scale; + double new_d02 = templ_d02 / scale; double sin_a = double(prev_v01.x * prev_v02.y - prev_v01.y * prev_v02.x) / (prev_d01 * prev_d02); double cos_a = cos(asin(sin_a)); double x = double(new_v01.x) * cos_a - double(new_v01.y) * sin_a; @@ -806,12 +806,12 @@ inline int GetEnergy(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoin double h_mouth = double(ppNew[MOUTH]->r.height) * scale; energy += int(512.0 * (e_prev + 16.0 * e_templ)) + - 4 * pow2(ppNew[LEYE]->r.width - ppNew[REYE]->r.width) + - 4 * pow2(ppNew[LEYE]->r.height - ppNew[REYE]->r.height) + - 4 * (int)pow(w_eye - double(rTempl[LEYE].width + rTempl[REYE].width) / 2.0, 2) + - 2 * (int)pow(h_eye - double(rTempl[LEYE].height + rTempl[REYE].height) / 2.0, 2) + - 1 * (int)pow(w_mouth - double(rTempl[MOUTH].width), 2) + - 1 * (int)pow(h_mouth - double(rTempl[MOUTH].height), 2) + + 4 * pow2(ppNew[LEYE]->r.width - ppNew[REYE]->r.width) + + 4 * pow2(ppNew[LEYE]->r.height - ppNew[REYE]->r.height) + + 4 * (int)pow(w_eye - double(rTempl[LEYE].width + rTempl[REYE].width) / 2.0, 2) + + 2 * (int)pow(h_eye - double(rTempl[LEYE].height + rTempl[REYE].height) / 2.0, 2) + + 1 * (int)pow(w_mouth - double(rTempl[MOUTH].width), 2) + + 1 * (int)pow(h_mouth - double(rTempl[MOUTH].height), 2) + 0; return energy; } @@ -832,20 +832,20 @@ inline int GetEnergy2(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoi double h0 = (double)ppNew[element[0]]->r.height * scale_templ; double w1 = (double)ppNew[element[1]]->r.width * scale_templ; double h1 = (double)ppNew[element[1]]->r.height * scale_templ; - + int energy = ppNew[element[0]]->iEnergy + ppNew[element[1]]->iEnergy + - - 2 * (ppNew[element[0]]->nRectsInThis - ppNew[element[1]]->nRectsInThis) + + - 2 * (ppNew[element[0]]->nRectsInThis - ppNew[element[1]]->nRectsInThis) + (int)pow(w0 - (double)rTempl[element[0]].width, 2) + (int)pow(h0 - (double)rTempl[element[0]].height, 2) + (int)pow(w1 - (double)rTempl[element[1]].width, 2) + (int)pow(h1 - (double)rTempl[element[1]].height, 2) + (int)pow(new_d - prev_d, 2) + 0; - + return energy; } -inline double CalculateTransformationLMS3( CvPoint* pTemplPoints, +inline double CalculateTransformationLMS3( CvPoint* pTemplPoints, CvPoint* pSrcPoints, double* pdbAverageScale, double* pdbAverageRotate, @@ -866,41 +866,41 @@ inline double CalculateTransformationLMS3( CvPoint* pTemplPoints, double dbYt = double(pTemplPoints[0].y + pTemplPoints[1].y + pTemplPoints[2].y ) / 3.0; double dbXs = double(pSrcPoints[0].x + pSrcPoints[1].x + pSrcPoints[2].x) / 3.0; double dbYs = double(pSrcPoints[0].y + pSrcPoints[1].y + pSrcPoints[2].y) / 3.0; - + double dbXtXt = double(pow2(pTemplPoints[0].x) + pow2(pTemplPoints[1].x) + pow2(pTemplPoints[2].x)) / 3.0; double dbYtYt = double(pow2(pTemplPoints[0].y) + pow2(pTemplPoints[1].y) + pow2(pTemplPoints[2].y)) / 3.0; - + double dbXsXs = double(pow2(pSrcPoints[0].x) + pow2(pSrcPoints[1].x) + pow2(pSrcPoints[2].x)) / 3.0; double dbYsYs = double(pow2(pSrcPoints[0].y) + pow2(pSrcPoints[1].y) + pow2(pSrcPoints[2].y)) / 3.0; - - double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x + - pTemplPoints[1].x * pSrcPoints[1].x + + + double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x + + pTemplPoints[1].x * pSrcPoints[1].x + pTemplPoints[2].x * pSrcPoints[2].x) / 3.0; - double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y + - pTemplPoints[1].y * pSrcPoints[1].y + + double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y + + pTemplPoints[1].y * pSrcPoints[1].y + pTemplPoints[2].y * pSrcPoints[2].y) / 3.0; - - double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y + - pTemplPoints[1].x * pSrcPoints[1].y + + + double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y + + pTemplPoints[1].x * pSrcPoints[1].y + pTemplPoints[2].x * pSrcPoints[2].y) / 3.0; - double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x + - pTemplPoints[1].y * pSrcPoints[1].x + + double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x + + pTemplPoints[1].y * pSrcPoints[1].x + pTemplPoints[2].y * pSrcPoints[2].x ) / 3.0; - + dbXtXt -= dbXt * dbXt; dbYtYt -= dbYt * dbYt; - + dbXsXs -= dbXs * dbXs; dbYsYs -= dbYs * dbYs; - + dbXtXs -= dbXt * dbXs; dbYtYs -= dbYt * dbYs; - + dbXtYs -= dbXt * dbYs; dbYtXs -= dbYt * dbXs; - + dbAverageRotate = atan2( dbXtYs - dbYtXs, dbXtXs + dbYtYs ); - + double cosR = cos(dbAverageRotate); double sinR = sin(dbAverageRotate); double del = dbXsXs + dbYsYs; @@ -909,15 +909,15 @@ inline double CalculateTransformationLMS3( CvPoint* pTemplPoints, dbAverageScale = (double(dbXtXs + dbYtYs) * cosR + double(dbXtYs - dbYtXs) * sinR) / del; dbLMS = dbXtXt + dbYtYt - ((double)pow(dbXtXs + dbYtYs,2) + (double)pow(dbXtYs - dbYtXs,2)) / del; } - + dbAverageShiftX = double(dbXt) - dbAverageScale * (double(dbXs) * cosR + double(dbYs) * sinR); dbAverageShiftY = double(dbYt) - dbAverageScale * (double(dbYs) * cosR - double(dbXs) * sinR); - + if( pdbAverageScale != NULL ) *pdbAverageScale = dbAverageScale; if( pdbAverageRotate != NULL ) *pdbAverageRotate = dbAverageRotate; if( pdbAverageShiftX != NULL ) *pdbAverageShiftX = dbAverageShiftX; if( pdbAverageShiftY != NULL ) *pdbAverageShiftY = dbAverageShiftY; - + assert(dbLMS >= 0); return dbLMS; } @@ -933,39 +933,39 @@ inline double CalculateTransformationLMS3_0( CvPoint* pTemplPoints, CvPoint* pSr double dbYt = double(pTemplPoints[0].y + pTemplPoints[1].y + pTemplPoints[2].y ) / 3.0; double dbXs = double(pSrcPoints[0].x + pSrcPoints[1].x + pSrcPoints[2].x) / 3.0; double dbYs = double(pSrcPoints[0].y + pSrcPoints[1].y + pSrcPoints[2].y) / 3.0; - + double dbXtXt = double(pow2(pTemplPoints[0].x) + pow2(pTemplPoints[1].x) + pow2(pTemplPoints[2].x)) / 3.0; double dbYtYt = double(pow2(pTemplPoints[0].y) + pow2(pTemplPoints[1].y) + pow2(pTemplPoints[2].y)) / 3.0; - + double dbXsXs = double(pow2(pSrcPoints[0].x) + pow2(pSrcPoints[1].x) + pow2(pSrcPoints[2].x)) / 3.0; double dbYsYs = double(pow2(pSrcPoints[0].y) + pow2(pSrcPoints[1].y) + pow2(pSrcPoints[2].y)) / 3.0; - - double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x + - pTemplPoints[1].x * pSrcPoints[1].x + + + double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x + + pTemplPoints[1].x * pSrcPoints[1].x + pTemplPoints[2].x * pSrcPoints[2].x) / 3.0; - double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y + - pTemplPoints[1].y * pSrcPoints[1].y + + double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y + + pTemplPoints[1].y * pSrcPoints[1].y + pTemplPoints[2].y * pSrcPoints[2].y) / 3.0; - - double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y + - pTemplPoints[1].x * pSrcPoints[1].y + + + double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y + + pTemplPoints[1].x * pSrcPoints[1].y + pTemplPoints[2].x * pSrcPoints[2].y) / 3.0; - double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x + - pTemplPoints[1].y * pSrcPoints[1].x + + double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x + + pTemplPoints[1].y * pSrcPoints[1].x + pTemplPoints[2].y * pSrcPoints[2].x ) / 3.0; - + dbXtXt -= dbXt * dbXt; dbYtYt -= dbYt * dbYt; - + dbXsXs -= dbXs * dbXs; dbYsYs -= dbYs * dbYs; - + dbXtXs -= dbXt * dbXs; dbYtYs -= dbYt * dbYs; - + dbXtYs -= dbXt * dbYs; dbYtXs -= dbYt * dbXs; - + double del = dbXsXs + dbYsYs; if( del != 0 ) dbLMS = dbXtXt + dbYtYt - ((double)pow(dbXtXs + dbYtYs,2) + (double)pow(dbXtYs - dbYtXs,2)) / del; diff --git a/modules/ml/src/gbt.cpp b/modules/ml/src/gbt.cpp index 002f240..3ef3e5e 100644 --- a/modules/ml/src/gbt.cpp +++ b/modules/ml/src/gbt.cpp @@ -12,7 +12,7 @@ using namespace std; static CV_IMPLEMENT_QSORT_EX( icvSortFloat, float, CV_CMP_FLOAT, float) //=========================================================================== -string ToString(int i) +static string ToString(int i) { stringstream tmp; tmp << i; @@ -25,7 +25,7 @@ string ToString(int i) //----------------------------- CvGBTreesParams ----------------------------- //=========================================================================== -CvGBTreesParams::CvGBTreesParams() +CvGBTreesParams::CvGBTreesParams() : CvDTreeParams( 3, 10, 0, false, 10, 0, false, false, 0 ) { weak_count = 200; @@ -36,8 +36,8 @@ CvGBTreesParams::CvGBTreesParams() //=========================================================================== -CvGBTreesParams::CvGBTreesParams( int _loss_function_type, int _weak_count, - float _shrinkage, float _subsample_portion, +CvGBTreesParams::CvGBTreesParams( int _loss_function_type, int _weak_count, + float _shrinkage, float _subsample_portion, int _max_depth, bool _use_surrogates ) : CvDTreeParams( 3, 10, 0, false, 10, 0, false, false, 0 ) { @@ -64,7 +64,7 @@ CvGBTrees::CvGBTrees() class_labels = 0; class_count = 1; delta = 0.0f; - + clear(); } @@ -88,10 +88,10 @@ void CvGBTrees::clear() //data->shared = false; for (int i=0; istorage) ); delete[] weak; } - if (data) + if (data) { data->shared = false; delete data; @@ -165,7 +165,7 @@ bool CvGBTrees::problem_type() const //=========================================================================== -bool +bool CvGBTrees::train( CvMLData* data, CvGBTreesParams params, bool update ) { bool result; @@ -218,14 +218,14 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, } orig_response = cvCreateMat( 1, n, CV_32F ); - int step = (_responses->cols > _responses->rows) ? 1 : _responses->step / CV_ELEM_SIZE(_responses->type); + int step = (_responses->cols > _responses->rows) ? 1 : _responses->step / CV_ELEM_SIZE(_responses->type); switch (CV_MAT_TYPE(_responses->type)) { case CV_32FC1: - { - for (int i=0; idata.fl[i] = _responses->data.fl[i*step]; - }; break; + }; break; case CV_32SC1: { for (int i=0; idata.i[0] = int(orig_response->data.fl[0]); int j = 1; @@ -274,14 +274,14 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, if (_sample_idx) { int sample_idx_len = get_len(_sample_idx); - + switch (CV_MAT_TYPE(_sample_idx->type)) { case CV_32SC1: { sample_idx = cvCreateMat( 1, sample_idx_len, CV_32S ); for (int i=0; idata.i[i] = _sample_idx->data.i[i]; + sample_idx->data.i[i] = _sample_idx->data.i[i]; } break; case CV_8S: case CV_8U: @@ -294,7 +294,7 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, for (int i=0; idata.ptr[i] )) sample_idx->data.i[active_samples_count++] = i; - + } break; default: CV_Error(CV_StsUnmatchedFormats, "_sample_idx should be a 32sC1, 8sC1 or 8uC1 vector."); } @@ -335,14 +335,14 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, storage = cvCreateMemStorage(); weak[i] = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvDTree*), storage ); storage = 0; - } + } // subsample params and data rng = &cv::theRNG(); - int samples_count = get_len(sample_idx); + int samples_count = get_len(sample_idx); - params.subsample_portion = params.subsample_portion <= FLT_EPSILON || + params.subsample_portion = params.subsample_portion <= FLT_EPSILON || 1 - params.subsample_portion <= FLT_EPSILON ? 1 : params.subsample_portion; int train_sample_count = cvFloor(params.subsample_portion * samples_count); @@ -358,12 +358,12 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, *subsample_test = cvMat( 1, test_sample_count, CV_32SC1, idx_data + train_sample_count ); } - + // training procedure for ( int i=0; i < params.weak_count; ++i ) { - do_subsample(); + do_subsample(); for ( int k=0; k < class_count; ++k ) { find_gradient(k); @@ -387,21 +387,21 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, cvGetRow( data->train_data, &x, idx); else cvGetCol( data->train_data, &x, idx); - + if (missing) { if (_tflag == CV_ROW_SAMPLE) cvGetRow( missing, &x_miss, idx); else cvGetCol( missing, &x_miss, idx); - + res = (float)tree->predict(&x, &x_miss)->value; } else { res = (float)tree->predict(&x)->value; } - sum_response_tmp->data.fl[idx + k*n] = + sum_response_tmp->data.fl[idx + k*n] = sum_response->data.fl[idx + k*n] + params.shrinkage * res; } @@ -421,13 +421,13 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag, cvReleaseMat(&new_responses); data->free_train_data(); - return true; + return true; } // CvGBTrees::train(...) //=========================================================================== -float Sign(float x) +inline float Sign(float x) { if (x<0.0f) return -1.0f; else if (x>0.0f) return 1.0f; @@ -484,7 +484,7 @@ void CvGBTrees::find_gradient(const int k) residuals[i] = fabs(resp_data[idx] - current_data[idx]); } icvSortFloat(residuals, n, 0.0f); - + delta = residuals[int(ceil(n*alpha))]; for (int i=0; icols > sample_idx->rows) ? 1 : sample_idx->step/CV_ELEM_SIZE(sample_idx->type); int idx = *(sample_data + subsample_data[i]*s_step); - + for (int j=0; jdata.i[orig_label]+1)) - (float)(exp_fk / exp_sfi); - */ - int ensemble_label = 0; - while (class_labels->data.i[ensemble_label] - orig_label) - ensemble_label++; - + */ + int ensemble_label = 0; + while (class_labels->data.i[ensemble_label] - orig_label) + ensemble_label++; + grad_data[idx] = (float)(!(k-ensemble_label)) - (float)(exp_fk / exp_sfi); } @@ -550,19 +550,19 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k) for (int i=0; itflag == CV_ROW_SAMPLE) + int idx = *(sample_data + subsample_data[i]*s_step); + if (data->tflag == CV_ROW_SAMPLE) cvGetRow( data->train_data, &x, idx); else cvGetCol( data->train_data, &x, idx); - + if (missing) { if (data->tflag == CV_ROW_SAMPLE) cvGetRow( missing, &miss_x, idx); else cvGetCol( missing, &miss_x, idx); - + predictions[i] = tree->predict(&x, &miss_x); } else @@ -585,7 +585,7 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k) if (!samples_in_leaf) // It should not be done anyways! but... { leaves[i]->value = 0.0; - continue; + continue; } CvMat* leaf_idx = cvCreateMat(1, samples_in_leaf, CV_32S); @@ -606,12 +606,12 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k) int len = sum_response_tmp->cols; for (int j=0; jdata.fl[idx + _k*len] = sum_response->data.fl[idx + _k*len] + params.shrinkage * value; } - leaf_idx_data = 0; + leaf_idx_data = 0; cvReleaseMat(&leaf_idx); } @@ -634,13 +634,13 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k) /* void CvGBTrees::change_values(CvDTree* tree, const int _k) { - + CvDTreeNode** leaves; int leaves_count = 0; - int offset = _k*sum_response_tmp->cols; - CvMat leaf_idx; - leaf_idx.rows = 1; - + int offset = _k*sum_response_tmp->cols; + CvMat leaf_idx; + leaf_idx.rows = 1; + leaves = GetLeaves( tree, leaves_count); for (int i=0; iget_sample_indices(leaves[i], leaf_idx_data); //CvMat* leaf_idx = new CvMat(); //cvInitMatHeader(leaf_idx, n, 1, CV_32S, leaf_idx_data); - leaf_idx.cols = n; - leaf_idx.data.i = leaf_idx_data; + leaf_idx.cols = n; + leaf_idx.data.i = leaf_idx_data; float value = find_optimal_value(&leaf_idx); leaves[i]->value = value; - float val = params.shrinkage * value; + float val = params.shrinkage * value; + - for (int j=0; jtype) != CV_32F) + if (CV_MAT_TYPE(weak_responses->type) != CV_32F) return 0.0f; if ((k >= 0) && (krows != 1)) return 0.0f; @@ -839,7 +839,7 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing, if (weak_responses->cols != weak_count) return 0.0f; } - + float* sum = new float[class_count]; memset(sum, 0, class_count*sizeof(float)); @@ -847,7 +847,7 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing, { if ((weak[i]) && (weak_count)) { - cvStartReadSeq( weak[i], &reader ); + cvStartReadSeq( weak[i], &reader ); cvSetSeqReaderPos( &reader, slice.start_index ); for (int j=0; jdata.i[i] == class_label+1) orig_class_label = i; - */ - int orig_class_label = class_labels->data.i[class_label]; + */ + int orig_class_label = class_labels->data.i[class_label]; return float(orig_class_label); } @@ -903,69 +903,71 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing, class Tree_predictor { private: - pCvSeq* weak; - float* sum; - const int k; - const CvMat* sample; - const CvMat* missing; + pCvSeq* weak; + float* sum; + const int k; + const CvMat* sample; + const CvMat* missing; const float shrinkage; - + #ifdef HAVE_TBB static tbb::spin_mutex SumMutex; #endif public: - Tree_predictor() : weak(0), sum(0), k(0), sample(0), missing(0), shrinkage(1.0f) {} - Tree_predictor(pCvSeq* _weak, const int _k, const float _shrinkage, - const CvMat* _sample, const CvMat* _missing, float* _sum ) : - weak(_weak), sum(_sum), k(_k), sample(_sample), + Tree_predictor() : weak(0), sum(0), k(0), sample(0), missing(0), shrinkage(1.0f) {} + Tree_predictor(pCvSeq* _weak, const int _k, const float _shrinkage, + const CvMat* _sample, const CvMat* _missing, float* _sum ) : + weak(_weak), sum(_sum), k(_k), sample(_sample), missing(_missing), shrinkage(_shrinkage) - {} - + {} + Tree_predictor( const Tree_predictor& p, cv::Split ) : - weak(p.weak), sum(p.sum), k(p.k), sample(p.sample), + weak(p.weak), sum(p.sum), k(p.k), sample(p.sample), missing(p.missing), shrinkage(p.shrinkage) - {} + {} + + Tree_predictor& operator=( const Tree_predictor& ) + { return *this; } - Tree_predictor& operator=( const Tree_predictor& ) - { return *this; } - virtual void operator()(const cv::BlockedRange& range) const - { + { #ifdef HAVE_TBB tbb::spin_mutex::scoped_lock lock; #endif CvSeqReader reader; - int begin = range.begin(); - int end = range.end(); - - int weak_count = end - begin; - CvDTree* tree; - - for (int i=0; ipredict(sample, missing)->value); - } - } + int begin = range.begin(); + int end = range.end(); + + int weak_count = end - begin; + CvDTree* tree; + + for (int i=0; ipredict(sample, missing)->value); + } + } #ifdef HAVE_TBB lock.acquire(SumMutex); - sum[i] += tmp_sum; + sum[i] += tmp_sum; lock.release(); #else sum[i] += tmp_sum; #endif - } - } // Tree_predictor::operator() - + } + } // Tree_predictor::operator() + + virtual ~Tree_predictor() {} + }; // class Tree_predictor @@ -976,28 +978,28 @@ tbb::spin_mutex Tree_predictor::SumMutex; float CvGBTrees::predict( const CvMat* _sample, const CvMat* _missing, - CvMat* /*weak_responses*/, CvSlice slice, int k) const + CvMat* /*weak_responses*/, CvSlice slice, int k) const { float result = 0.0f; - if (!weak) return 0.0f; + if (!weak) return 0.0f; float* sum = new float[class_count]; for (int i=0; ipredict_serial(&x,&miss,0,slice); } } - } // Sample_predictor::operator() + } // Sample_predictor::operator() + + virtual ~Sample_predictor() {} }; // class Sample_predictor // type in {CV_TRAIN_ERROR, CV_TEST_ERROR} -float +float CvGBTrees::calc_error( CvMLData* _data, int type, std::vector *resp ) { @@ -1294,14 +1298,14 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector *resp ) _data->get_train_sample_idx() : _data->get_test_sample_idx(); const CvMat* response = _data->get_responses(); - + int n = sample_idx ? get_len(sample_idx) : 0; n = (type == CV_TRAIN_ERROR && n == 0) ? _data->get_values()->rows : n; - + if (!n) return -FLT_MAX; - - float* pred_resp = 0; + + float* pred_resp = 0; if (resp) { resp->resize(n); @@ -1312,17 +1316,17 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector *resp ) Sample_predictor predictor = Sample_predictor(this, pred_resp, _data->get_values(), _data->get_missing(), sample_idx); - + //#ifdef HAVE_TBB // tbb::parallel_for(cv::BlockedRange(0,n), predictor, tbb::auto_partitioner()); //#else cv::parallel_for(cv::BlockedRange(0,n), predictor); //#endif - + int* sidx = sample_idx ? sample_idx->data.i : 0; int r_step = CV_IS_MAT_CONT(response->type) ? 1 : response->step / CV_ELEM_SIZE(response->type); - + if ( !problem_type() ) { @@ -1342,9 +1346,9 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector *resp ) float d = pred_resp[i] - response->data.fl[si*r_step]; err += d*d; } - err = err / (float)n; + err = err / (float)n; } - + return err; } @@ -1364,9 +1368,9 @@ CvGBTrees::CvGBTrees( const cv::Mat& trainData, int tflag, class_labels = 0; class_count = 1; delta = 0.0f; - + clear(); - + train(trainData, tflag, responses, varIdx, sampleIdx, varType, missingDataMask, params, false); } @@ -1380,7 +1384,7 @@ bool CvGBTrees::train( const cv::Mat& trainData, int tflag, CvMat _trainData = trainData, _responses = responses; CvMat _varIdx = varIdx, _sampleIdx = sampleIdx, _varType = varType; CvMat _missingDataMask = missingDataMask; - + return train( &_trainData, tflag, &_responses, varIdx.empty() ? 0 : &_varIdx, sampleIdx.empty() ? 0 : &_sampleIdx, varType.empty() ? 0 : &_varType, missingDataMask.empty() ? 0 : &_missingDataMask, params, update); diff --git a/modules/ml/src/inner_functions.cpp b/modules/ml/src/inner_functions.cpp index 0059597..f0e085d 100644 --- a/modules/ml/src/inner_functions.cpp +++ b/modules/ml/src/inner_functions.cpp @@ -122,7 +122,7 @@ void CvStatModel::read( CvFileStorage*, CvFileNode* ) /* Calculates upper triangular matrix S, where A is a symmetrical matrix A=S'*S */ -CV_IMPL void cvChol( CvMat* A, CvMat* S ) +static void cvChol( CvMat* A, CvMat* S ) { int dim = A->rows; @@ -182,7 +182,7 @@ CV_IMPL void cvRandMVNormal( CvMat* mean, CvMat* cov, CvMat* sample, CvRNG* rng /* Generates of points from a discrete variate xi, where Pr{xi = k} == probs[k], 0 < k < len - 1. */ -CV_IMPL void cvRandSeries( float probs[], int len, int sample[], int amount ) +static void cvRandSeries( float probs[], int len, int sample[], int amount ) { CvMat* univals = cvCreateMat(1, amount, CV_32FC1); float* knots = (float*)cvAlloc( len * sizeof(float) ); @@ -321,48 +321,48 @@ CvMat* icvGenerateRandomClusterCenters ( int seed, const CvMat* data, #define ICV_RAND_MAX 4294967296 // == 2^32 -CV_IMPL void cvRandRoundUni (CvMat* center, - float radius_small, - float radius_large, - CvMat* desired_matrix, - CvRNG* rng_state_ptr) -{ - float rad, norm, coefficient; - int dim, size, i, j; - CvMat *cov, sample; - CvRNG rng_local; - - CV_FUNCNAME("cvRandRoundUni"); - __BEGIN__ - - rng_local = *rng_state_ptr; - - CV_ASSERT ((radius_small >= 0) && - (radius_large > 0) && - (radius_small <= radius_large)); - CV_ASSERT (center && desired_matrix && rng_state_ptr); - CV_ASSERT (center->rows == 1); - CV_ASSERT (center->cols == desired_matrix->cols); - - dim = desired_matrix->cols; - size = desired_matrix->rows; - cov = cvCreateMat (dim, dim, CV_32FC1); - cvSetIdentity (cov); - cvRandMVNormal (center, cov, desired_matrix, &rng_local); - - for (i = 0; i < size; i++) - { - rad = (float)(cvRandReal(&rng_local)*(radius_large - radius_small) + radius_small); - cvGetRow (desired_matrix, &sample, i); - norm = (float) cvNorm (&sample, 0, CV_L2); - coefficient = rad / norm; - for (j = 0; j < dim; j++) - CV_MAT_ELEM (sample, float, 0, j) *= coefficient; - } - - __END__ - -} +// static void cvRandRoundUni (CvMat* center, +// float radius_small, +// float radius_large, +// CvMat* desired_matrix, +// CvRNG* rng_state_ptr) +// { +// float rad, norm, coefficient; +// int dim, size, i, j; +// CvMat *cov, sample; +// CvRNG rng_local; + +// CV_FUNCNAME("cvRandRoundUni"); +// __BEGIN__ + +// rng_local = *rng_state_ptr; + +// CV_ASSERT ((radius_small >= 0) && +// (radius_large > 0) && +// (radius_small <= radius_large)); +// CV_ASSERT (center && desired_matrix && rng_state_ptr); +// CV_ASSERT (center->rows == 1); +// CV_ASSERT (center->cols == desired_matrix->cols); + +// dim = desired_matrix->cols; +// size = desired_matrix->rows; +// cov = cvCreateMat (dim, dim, CV_32FC1); +// cvSetIdentity (cov); +// cvRandMVNormal (center, cov, desired_matrix, &rng_local); + +// for (i = 0; i < size; i++) +// { +// rad = (float)(cvRandReal(&rng_local)*(radius_large - radius_small) + radius_small); +// cvGetRow (desired_matrix, &sample, i); +// norm = (float) cvNorm (&sample, 0, CV_L2); +// coefficient = rad / norm; +// for (j = 0; j < dim; j++) +// CV_MAT_ELEM (sample, float, 0, j) *= coefficient; +// } + +// __END__ + +// } // By S. Dilman - end - @@ -1769,7 +1769,7 @@ void cvCombineResponseMaps (CvMat* _responses, } -int icvGetNumberOfCluster( double* prob_vector, int num_of_clusters, float r, +static int icvGetNumberOfCluster( double* prob_vector, int num_of_clusters, float r, float outlier_thresh, int normalize_probs ) { int max_prob_loc = 0; diff --git a/modules/ml/src/precomp.hpp b/modules/ml/src/precomp.hpp index 285abea..5ec1a60 100644 --- a/modules/ml/src/precomp.hpp +++ b/modules/ml/src/precomp.hpp @@ -41,11 +41,11 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4514 4710 4711 4710 ) #endif -#ifdef HAVE_CVCONFIG_H +#ifdef HAVE_CVCONFIG_H #include "cvconfig.h" #endif @@ -298,10 +298,10 @@ cvPrepareTrainData( const char* /*funcname*/, CvMat** out_sample_idx=0 ); void -cvSortSamplesByClasses( const float** samples, const CvMat* classes, +cvSortSamplesByClasses( const float** samples, const CvMat* classes, int* class_ranges, const uchar** mask CV_DEFAULT(0) ); -void +void cvCombineResponseMaps (CvMat* _responses, const CvMat* old_response_map, CvMat* new_response_map, @@ -329,7 +329,7 @@ CvFileNode* icvFileNodeGetNext(CvFileNode* n, const char* name); void cvCheckTrainData( const CvMat* train_data, int tflag, - const CvMat* missing_mask, + const CvMat* missing_mask, int* var_all, int* sample_all ); CvMat* cvPreprocessIndexArray( const CvMat* idx_arr, int data_arr_size, bool check_for_duplicates=false ); @@ -365,7 +365,7 @@ namespace cv CvDTree* tree; CvDTreeNode* node; }; - + struct ForestTreeBestSplitFinder : DTreeBestSplitFinder { ForestTreeBestSplitFinder() : DTreeBestSplitFinder() {} diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index c16cce5..bfe1ed6 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -88,7 +88,7 @@ using namespace cv; #include #include -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4514 ) /* unreferenced inline functions */ #endif @@ -1593,7 +1593,7 @@ bool CvSVM::train( const CvMat* _train_data, const CvMat* _responses, return ok; } -struct indexedratio +struct indexedratio { double val; int ind; @@ -1774,7 +1774,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses, else CV_SWAP( responses->data.i[i1], responses->data.i[i2], y ); } - + if (!is_regression && class_labels->cols==2 && balanced) { // count class samples @@ -1786,13 +1786,13 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses, else ++num_1; } - + int label_smallest_class; int label_biggest_class; if (num_0 < num_1) { label_biggest_class = class_labels->data.i[1]; - label_smallest_class = class_labels->data.i[0]; + label_smallest_class = class_labels->data.i[0]; } else { @@ -2001,7 +2001,7 @@ float CvSVM::predict( const float* row_sample, int row_len, bool returnDFVal ) c int var_count = get_var_count(); assert( row_len == var_count ); - (void)row_len; + (void)row_len; int class_count = class_labels ? class_labels->cols : params.svm_type == ONE_CLASS ? 1 : 0; @@ -2072,7 +2072,7 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const __BEGIN__; int class_count; - + if( !kernel ) CV_ERROR( CV_StsBadArg, "The SVM should be trained first" ); @@ -2082,7 +2082,7 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const CV_CALL( cvPreparePredictData( sample, var_all, var_idx, class_count, 0, &row_sample )); result = predict( row_sample, get_var_count(), returnDFVal ); - + __END__; if( sample && (!CV_IS_MAT(sample) || sample->data.fl != row_sample) ) @@ -2099,12 +2099,12 @@ struct predict_body_svm { samples = _samples; results = _results; } - + const CvSVM* pointer; float* result; const CvMat* samples; CvMat* results; - + void operator()( const cv::BlockedRange& range ) const { for(int i = range.begin(); i < range.end(); i++ ) @@ -2116,15 +2116,15 @@ struct predict_body_svm { results->data.fl[i] = (float)r; if (i == 0) *result = (float)r; - } + } } }; float CvSVM::predict(const CvMat* samples, CV_OUT CvMat* results) const { float result = 0; - cv::parallel_for(cv::BlockedRange(0, samples->rows), - predict_body_svm(this, &result, samples, results) + cv::parallel_for(cv::BlockedRange(0, samples->rows), + predict_body_svm(this, &result, samples, results) ); return result; } @@ -2141,7 +2141,7 @@ CvSVM::CvSVM( const Mat& _train_data, const Mat& _responses, kernel = 0; solver = 0; default_model_name = "my_svm"; - + train( _train_data, _responses, _var_idx, _sample_idx, _params ); } @@ -2166,7 +2166,7 @@ bool CvSVM::train_auto( const Mat& _train_data, const Mat& _responses, float CvSVM::predict( const Mat& _sample, bool returnDFVal ) const { - CvMat sample = _sample; + CvMat sample = _sample; return predict(&sample, returnDFVal); } @@ -2648,11 +2648,11 @@ cvTrainSVM_CrossValidation( const CvMat* train_data, int tflag, __BEGIN__; double degree_step = 7, - g_step = 15, - coef_step = 14, - C_step = 20, - nu_step = 5, - p_step = 7; // all steps must be > 1 + g_step = 15, + coef_step = 14, + C_step = 20, + nu_step = 5, + p_step = 7; // all steps must be > 1 double degree_begin = 0.01, degree_end = 2; double g_begin = 1e-5, g_end = 0.5; double coef_begin = 0.1, coef_end = 300; @@ -2662,12 +2662,12 @@ cvTrainSVM_CrossValidation( const CvMat* train_data, int tflag, double rate = 0, gamma = 0, C = 0, degree = 0, coef = 0, p = 0, nu = 0; - double best_rate = 0; + double best_rate = 0; double best_degree = degree_begin; double best_gamma = g_begin; double best_coef = coef_begin; - double best_C = C_begin; - double best_nu = nu_begin; + double best_C = C_begin; + double best_nu = nu_begin; double best_p = p_begin; CvSVMModelParams svm_params, *psvm_params; diff --git a/modules/ml/src/testset.cpp b/modules/ml/src/testset.cpp index e4f3249..5edb3b4 100644 --- a/modules/ml/src/testset.cpp +++ b/modules/ml/src/testset.cpp @@ -46,7 +46,7 @@ typedef struct CvDI int i; } CvDI; -int CV_CDECL +static int CV_CDECL icvCmpDI( const void* a, const void* b, void* ) { const CvDI* e1 = (const CvDI*) a; @@ -65,7 +65,7 @@ cvCreateTestSet( int type, CvMat** samples, CvMat* mean = NULL; CvMat* cov = NULL; CvMemStorage* storage = NULL; - + CV_FUNCNAME( "cvCreateTestSet" ); __BEGIN__; @@ -125,7 +125,7 @@ cvCreateTestSet( int type, CvMat** samples, CV_WRITE_SEQ_ELEM( elem, writer ); } CV_CALL( seq = cvEndWriteSeq( &writer ) ); - + /* sort the sequence in a distance ascending order */ CV_CALL( cvSeqSort( seq, icvCmpDI, NULL ) ); @@ -137,7 +137,7 @@ cvCreateTestSet( int type, CvMat** samples, { int last_idx; double max_dst; - + last_idx = num_samples * (cur_class + 1) / num_classes - 1; CV_CALL( max_dst = (*((CvDI*) cvGetSeqElem( seq, last_idx ))).d ); max_dst = MAX( max_dst, elem.d ); diff --git a/modules/nonfree/perf/perf_precomp.hpp b/modules/nonfree/perf/perf_precomp.hpp index d86769c..64e2dba 100644 --- a/modules/nonfree/perf/perf_precomp.hpp +++ b/modules/nonfree/perf/perf_precomp.hpp @@ -5,7 +5,7 @@ #include "opencv2/nonfree/nonfree.hpp" #include "opencv2/highgui/highgui.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/nonfree/src/precomp.hpp b/modules/nonfree/src/precomp.hpp index 9d7c4f0..1d5c2f8 100644 --- a/modules/nonfree/src/precomp.hpp +++ b/modules/nonfree/src/precomp.hpp @@ -43,11 +43,11 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4251 4512 4710 4711 4514 4996 ) #endif -#ifdef HAVE_CVCONFIG_H +#ifdef HAVE_CVCONFIG_H #include "cvconfig.h" #endif diff --git a/modules/nonfree/src/surf.cpp b/modules/nonfree/src/surf.cpp index 76939f8..b6e776d 100644 --- a/modules/nonfree/src/surf.cpp +++ b/modules/nonfree/src/surf.cpp @@ -17,16 +17,16 @@ * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: - * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * The name of Contributor may not be used to endorse or - * promote products derived from this software without - * specific prior written permission. + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * The name of Contributor may not be used to endorse or + * promote products derived from this software without + * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, @@ -43,7 +43,7 @@ * OF SUCH DAMAGE. */ -/* +/* The following changes have been made, comparing to the original contribution: 1. A lot of small optimizations, less memory allocations, got rid of global buffers 2. Reversed order of cvGetQuadrangleSubPix and cvResize calls; probably less accurate, but much faster @@ -79,8 +79,8 @@ octave. The extraction of the patch of pixels surrounding a keypoint used to build a descriptor has been simplified. -KeyPoint descriptor normalisation has been changed from normalising each 4x4 -cell (resulting in a descriptor of magnitude 16) to normalising the entire +KeyPoint descriptor normalisation has been changed from normalising each 4x4 +cell (resulting in a descriptor of magnitude 16) to normalising the entire descriptor to magnitude 1. The default number of octaves has been increased from 3 to 4 to match the @@ -88,20 +88,20 @@ original SURF binary default. The increase in computation time is minimal since the higher octaves are sampled sparsely. The default number of layers per octave has been reduced from 3 to 2, to prevent -redundant calculation of similar sizes in consecutive octaves. This decreases -computation time. The number of features extracted may be less, however the +redundant calculation of similar sizes in consecutive octaves. This decreases +computation time. The number of features extracted may be less, however the additional features were mostly redundant. The radius of the circle of gradient samples used to assign an orientation has -been increased from 4 to 6 to match the description in the SURF paper. This is +been increased from 4 to 6 to match the description in the SURF paper. This is now defined by ORI_RADIUS, and could be made into a parameter. The size of the sliding window used in orientation assignment has been reduced from 120 to 60 degrees to match the description in the SURF paper. This is now defined by ORI_WIN, and could be made into a parameter. -Other options like HAAR_SIZE0, HAAR_SIZE_INC, SAMPLE_STEP0, ORI_SEARCH_INC, -ORI_SIGMA and DESC_SIGMA have been separated from the code and documented. +Other options like HAAR_SIZE0, HAAR_SIZE_INC, SAMPLE_STEP0, ORI_SEARCH_INC, +ORI_SIGMA and DESC_SIGMA have been separated from the code and documented. These could also be made into parameters. Modifications by Ian Mahon @@ -124,12 +124,14 @@ static const int SURF_HAAR_SIZE0 = 9; // This ensures that when looking for the neighbours of a sample, the layers // above and below are aligned correctly. static const int SURF_HAAR_SIZE_INC = 6; - - + + struct SurfHF { int p0, p1, p2, p3; float w; + + SurfHF(): p0(0), p1(0), p2(0), p3(0), w(0) {} }; inline float calcHaarPattern( const int* origin, const SurfHF* f, int n ) @@ -208,10 +210,10 @@ static void calcLayerDetAndTrace( const Mat& sum, int size, int sampleStep, * Maxima location interpolation as described in "Invariant Features from * Interest Point Groups" by Matthew Brown and David Lowe. This is performed by * fitting a 3D quadratic to a set of neighbouring samples. - * - * The gradient vector and Hessian matrix at the initial keypoint location are + * + * The gradient vector and Hessian matrix at the initial keypoint location are * approximated using central differences. The linear system Ax = b is then - * solved, where A is the Hessian, b is the negative gradient, and x is the + * solved, where A is the Hessian, b is the negative gradient, and x is the * offset of the interpolated maxima coordinates from the initial estimate. * This is equivalent to an iteration of Netwon's optimisation algorithm. * @@ -234,18 +236,18 @@ interpolateKeypoint( float N9[3][9], int dx, int dy, int ds, KeyPoint& kpt ) N9[1][3]-2*N9[1][4]+N9[1][5], // 2nd deriv x, x (N9[1][8]-N9[1][6]-N9[1][2]+N9[1][0])/4, // 2nd deriv x, y (N9[2][5]-N9[2][3]-N9[0][5]+N9[0][3])/4, // 2nd deriv x, s - (N9[1][8]-N9[1][6]-N9[1][2]+N9[1][0])/4, // 2nd deriv x, y - N9[1][1]-2*N9[1][4]+N9[1][7], // 2nd deriv y, y - (N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s + (N9[1][8]-N9[1][6]-N9[1][2]+N9[1][0])/4, // 2nd deriv x, y + N9[1][1]-2*N9[1][4]+N9[1][7], // 2nd deriv y, y + (N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s (N9[2][5]-N9[2][3]-N9[0][5]+N9[0][3])/4, // 2nd deriv x, s (N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s N9[0][4]-2*N9[1][4]+N9[2][4]); // 2nd deriv s, s Vec3f x = A.solve(b, DECOMP_LU); - + bool ok = (x[0] != 0 || x[1] != 0 || x[2] != 0) && std::abs(x[0]) <= 1 && std::abs(x[1]) <= 1 && std::abs(x[2]) <= 1; - + if( ok ) { kpt.pt.x += x[0]*dx; @@ -425,7 +427,7 @@ struct SURFFindInvoker { int layer = (*middleIndices)[i]; int octave = i / nOctaveLayers; - findMaximaInLayer( *sum, *mask_sum, *dets, *traces, *sizes, + findMaximaInLayer( *sum, *mask_sum, *dets, *traces, *sizes, *keypoints, octave, layer, hessianThreshold, (*sampleSteps)[layer] ); } @@ -459,7 +461,7 @@ struct KeypointGreater } }; - + static void fastHessianDetector( const Mat& sum, const Mat& mask_sum, vector& keypoints, int nOctaves, int nOctaveLayers, float hessianThreshold ) { @@ -479,7 +481,7 @@ static void fastHessianDetector( const Mat& sum, const Mat& mask_sum, vectorrows < grad_wav_size || sum->cols < grad_wav_size ) @@ -670,7 +672,7 @@ struct SURFInvoker kp.angle = descriptor_dir; if( !descriptors || !descriptors->data ) continue; - + /* Extract a window of pixels around the keypoint of size 20s */ int win_size = (int)((PATCH_SZ+1)*s); CV_Assert( winbuf->cols >= win_size*win_size ); @@ -678,13 +680,13 @@ struct SURFInvoker if( !upright ) { - descriptor_dir *= (float)(CV_PI/180); + descriptor_dir *= (float)(CV_PI/180); float sin_dir = std::sin(descriptor_dir); float cos_dir = std::cos(descriptor_dir); /* Subpixel interpolation version (slower). Subpixel not required since the pixels will all get averaged when we scale down to 20 pixels */ - /* + /* float w[] = { cos_dir, sin_dir, center.x, -sin_dir, cos_dir , center.y }; CvMat W = cvMat(2, 3, CV_32F, w); @@ -711,12 +713,12 @@ struct SURFInvoker else { // extract rect - slightly optimized version of the code above - // TODO: find faster code, as this is simply an extract rect operation, + // TODO: find faster code, as this is simply an extract rect operation, // e.g. by using cvGetSubRect, problem is the border processing // descriptor_dir == 90 grad // sin_dir == 1 // cos_dir == 0 - + float win_offset = -(float)(win_size-1)/2; int start_x = cvRound(center.x + win_offset); int start_y = cvRound(center.y - win_offset); @@ -733,7 +735,7 @@ struct SURFInvoker y = MIN( y, img->rows-1 ); WIN[i*win_size + j] = img->at(y, x); } - } + } } // Scale the window to size PATCH_SZ so each pixel's size is s. This // makes calculating the gradients with wavelets of size 2s easy @@ -860,7 +862,7 @@ void SURF::operator()(InputArray imgarg, InputArray maskarg, { (*this)(imgarg, maskarg, keypoints, noArray(), false); } - + void SURF::operator()(InputArray _img, InputArray _mask, CV_OUT vector& keypoints, OutputArray _descriptors, @@ -868,18 +870,18 @@ void SURF::operator()(InputArray _img, InputArray _mask, { Mat img = _img.getMat(), mask = _mask.getMat(), mask1, sum, msum; bool doDescriptors = _descriptors.needed(); - + CV_Assert(!img.empty() && img.depth() == CV_8U); if( img.channels() > 1 ) cvtColor(img, img, COLOR_BGR2GRAY); - + CV_Assert(mask.empty() || (mask.type() == CV_8U && mask.size() == img.size())); CV_Assert(hessianThreshold >= 0); CV_Assert(nOctaves > 0); CV_Assert(nOctaveLayers > 0); - + integral(img, sum, CV_32S); - + // Compute keypoints only if we are not asked for evaluating the descriptors are some given locations: if( !useProvidedKeypoints ) { @@ -890,7 +892,7 @@ void SURF::operator()(InputArray _img, InputArray _mask, } fastHessianDetector( sum, msum, keypoints, nOctaves, nOctaveLayers, (float)hessianThreshold ); } - + int i, j, N = (int)keypoints.size(); if( N > 0 ) { @@ -898,7 +900,7 @@ void SURF::operator()(InputArray _img, InputArray _mask, bool _1d = false; int dcols = extended ? 128 : 64; size_t dsize = dcols*sizeof(float); - + if( doDescriptors ) { _1d = _descriptors.kind() == _InputArray::STD_VECTOR && _descriptors.type() == CV_32F; @@ -913,11 +915,11 @@ void SURF::operator()(InputArray _img, InputArray _mask, descriptors = _descriptors.getMat(); } } - + // we call SURFInvoker in any case, even if we do not need descriptors, // since it computes orientation of each feature. parallel_for(BlockedRange(0, N), SURFInvoker(img, sum, keypoints, descriptors, extended, upright) ); - + // remove keypoints that were marked for deletion for( i = j = 0; i < N; i++ ) { @@ -951,7 +953,7 @@ void SURF::operator()(InputArray _img, InputArray _mask, void SURF::detectImpl( const Mat& image, vector& keypoints, const Mat& mask) const { (*this)(image, mask, keypoints, noArray(), false); -} +} void SURF::computeImpl( const Mat& image, vector& keypoints, Mat& descriptors) const { diff --git a/modules/objdetect/perf/perf_precomp.hpp b/modules/objdetect/perf/perf_precomp.hpp index 397f127..deb362e 100644 --- a/modules/objdetect/perf/perf_precomp.hpp +++ b/modules/objdetect/perf/perf_precomp.hpp @@ -5,7 +5,7 @@ #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" -#if GTEST_CREATE_SHARED_LIBRARY +#ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined #endif diff --git a/modules/objdetect/src/distancetransform.cpp b/modules/objdetect/src/distancetransform.cpp index dd8c22c..1e3555e 100644 --- a/modules/objdetect/src/distancetransform.cpp +++ b/modules/objdetect/src/distancetransform.cpp @@ -9,8 +9,8 @@ // // // API -// int GetPointOfIntersection(const float *f, - const float a, const float b, +// int GetPointOfIntersection(const float *f, + const float a, const float b, int q1, int q2, float *point); // INPUT // f - function on the regular grid @@ -23,15 +23,15 @@ // RESULT // Error status */ -int GetPointOfIntersection(const float *f, - const float a, const float b, +int GetPointOfIntersection(const float *f, + const float a, const float b, int q1, int q2, float *point) { if (q1 == q2) { return DISTANCE_TRANSFORM_EQUAL_POINTS; - } /* if (q1 == q2) */ - (*point) = ( (f[q2] - a * q2 + b *q2 * q2) - + } /* if (q1 == q2) */ + (*point) = ( (f[q2] - a * q2 + b *q2 * q2) - (f[q1] - a * q1 + b * q1 * q1) ) / (2 * b * (q2 - q1)); return DISTANCE_TRANSFORM_OK; } @@ -43,9 +43,9 @@ int GetPointOfIntersection(const float *f, // // API // int DistanceTransformOneDimensionalProblem(const float *f, const int n, - const float a, const float b, + const float a, const float b, float *distanceTransform, - int *points); + int *points); // INPUT // f - function on the regular grid // n - grid dimension @@ -58,7 +58,7 @@ int GetPointOfIntersection(const float *f, // Error status */ int DistanceTransformOneDimensionalProblem(const float *f, const int n, - const float a, const float b, + const float a, const float b, float *distanceTransform, int *points) { @@ -73,7 +73,7 @@ int DistanceTransformOneDimensionalProblem(const float *f, const int n, // Allocation memory (must be free in this function) v = (int *)malloc (sizeof(int) * n); z = (float *)malloc (sizeof(float) * (n + 1)); - + v[0] = 0; z[0] = (float)F_MIN; // left border of envelope z[1] = (float)F_MAX; // right border of envelope @@ -89,7 +89,7 @@ int DistanceTransformOneDimensionalProblem(const float *f, const int n, } /* if (tmp != DISTANCE_TRANSFORM_OK) */ if (pointIntersection <= z[k]) { - // Envelope doesn't contain current parabola + // Envelope doesn't contain current parabola do { k--; @@ -144,7 +144,7 @@ int DistanceTransformOneDimensionalProblem(const float *f, const int n, // INPUT // k - index of the previous cycle element // n - number of matrix rows -// q - parameter that equal +// q - parameter that equal (number_of_rows * number_of_columns - 1) // OUTPUT // None @@ -196,7 +196,7 @@ void TransposeCycleElements(float *a, int *cycle, int cycle_len) // RESULT // Error status */ -void TransposeCycleElements_int(int *a, int *cycle, int cycle_len) +static void TransposeCycleElements_int(int *a, int *cycle, int cycle_len) { int i; int buf; @@ -229,7 +229,7 @@ void Transpose(float *a, int n, int m) int max_cycle_len; max_cycle_len = n * m; - + // Allocation memory (must be free in this function) cycle = (int *)malloc(sizeof(int) * max_cycle_len); @@ -240,12 +240,12 @@ void Transpose(float *a, int n, int m) k = GetNextCycleElement(i, n, q); cycle[cycle_len] = i; cycle_len++; - + while (k > i) - { - cycle[cycle_len] = k; + { + cycle[cycle_len] = k; cycle_len++; - k = GetNextCycleElement(k, n, q); + k = GetNextCycleElement(k, n, q); } if (k == i) { @@ -272,14 +272,14 @@ void Transpose(float *a, int n, int m) // RESULT // None */ -void Transpose_int(int *a, int n, int m) +static void Transpose_int(int *a, int n, int m) { int *cycle; int i, k, q, cycle_len; int max_cycle_len; max_cycle_len = n * m; - + // Allocation memory (must be free in this function) cycle = (int *)malloc(sizeof(int) * max_cycle_len); @@ -290,12 +290,12 @@ void Transpose_int(int *a, int n, int m) k = GetNextCycleElement(i, n, q); cycle[cycle_len] = i; cycle_len++; - + while (k > i) - { - cycle[cycle_len] = k; + { + cycle[cycle_len] = k; cycle_len++; - k = GetNextCycleElement(k, n, q); + k = GetNextCycleElement(k, n, q); } if (k == i) { @@ -311,21 +311,21 @@ void Transpose_int(int *a, int n, int m) /* // Decision of two dimensional problem generalized distance transform // on the regular grid at all points -// min{d2(y' - y) + d4(y' - y)(y' - y) + +// min{d2(y' - y) + d4(y' - y)(y' - y) + min(d1(x' - x) + d3(x' - x)(x' - x) + f(x',y'))} (on x', y') // // API -// int DistanceTransformTwoDimensionalProblem(const float *f, +// int DistanceTransformTwoDimensionalProblem(const float *f, const int n, const int m, - const float coeff[4], + const float coeff[4], float *distanceTransform, - int *pointsX, int *pointsY); + int *pointsX, int *pointsY); // INPUT // f - function on the regular grid // n - number of rows // m - number of columns // coeff - coefficients of optimizable function - coeff[0] = d1, coeff[1] = d2, + coeff[0] = d1, coeff[1] = d2, coeff[2] = d3, coeff[3] = d4 // OUTPUT // distanceTransform - values of generalized distance transform @@ -334,9 +334,9 @@ void Transpose_int(int *a, int n, int m) // RESULT // Error status */ -int DistanceTransformTwoDimensionalProblem(const float *f, +int DistanceTransformTwoDimensionalProblem(const float *f, const int n, const int m, - const float coeff[4], + const float coeff[4], float *distanceTransform, int *pointsX, int *pointsY) { @@ -349,10 +349,10 @@ int DistanceTransformTwoDimensionalProblem(const float *f, for (i = 0; i < n; i++) { resOneDimProblem = DistanceTransformOneDimensionalProblem( - f + i * m, m, - coeff[0], coeff[2], - &internalDistTrans[i * m], - &internalPointsX[i * m]); + f + i * m, m, + coeff[0], coeff[2], + &internalDistTrans[i * m], + &internalPointsX[i * m]); if (resOneDimProblem != DISTANCE_TRANSFORM_OK) return DISTANCE_TRANSFORM_ERROR; } @@ -360,9 +360,9 @@ int DistanceTransformTwoDimensionalProblem(const float *f, for (j = 0; j < m; j++) { resOneDimProblem = DistanceTransformOneDimensionalProblem( - &internalDistTrans[j * n], n, - coeff[1], coeff[3], - distanceTransform + j * n, + &internalDistTrans[j * n], n, + coeff[1], coeff[3], + distanceTransform + j * n, pointsY + j * n); if (resOneDimProblem != DISTANCE_TRANSFORM_OK) return DISTANCE_TRANSFORM_ERROR; diff --git a/modules/objdetect/src/featurepyramid.cpp b/modules/objdetect/src/featurepyramid.cpp index 22bee33..12dc5c4 100644 --- a/modules/objdetect/src/featurepyramid.cpp +++ b/modules/objdetect/src/featurepyramid.cpp @@ -30,12 +30,12 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) int height, width, numChannels; int i, j, kk, c, ii, jj, d; float * datadx, * datady; - + //íîìåð êàíàëà â öèêëå - int ch; + int ch; //ïåðåìåííûå âû÷èñëåíèÿ ìàãíèòóäû float magnitude, x, y, tx, ty; - + IplImage * dx, * dy; int *nearest; float *w, a_x, b_x; @@ -51,7 +51,7 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) // ÷åòíûå èííåêñû íå êîíòðàñòíîå èçîáðàæåíèå // íå ÷åòíûå èííåêñû êîíòðàñòíîå èçîáðàæåíèå int * alfa; - + // âåêòîðû ãðàíèö ñåêòîðîâ float boundary_x[NUM_SECTOR + 1]; float boundary_y[NUM_SECTOR + 1]; @@ -63,9 +63,9 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) numChannels = image->nChannels; - dx = cvCreateImage(cvSize(image->width, image->height), + dx = cvCreateImage(cvSize(image->width, image->height), IPL_DEPTH_32F, 3); - dy = cvCreateImage(cvSize(image->width, image->height), + dy = cvCreateImage(cvSize(image->width, image->height), IPL_DEPTH_32F, 3); sizeX = width / k; @@ -77,7 +77,7 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) cvFilter2D(image, dx, &kernel_dx, cvPoint(-1, 0)); cvFilter2D(image, dy, &kernel_dy, cvPoint(0, -1)); - + float arg_vector; for(i = 0; i <= NUM_SECTOR; i++) { @@ -113,20 +113,20 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) y = ty; } }/*for(ch = 1; ch < numChannels; ch++)*/ - + max = boundary_x[0] * x + boundary_y[0] * y; maxi = 0; - for (kk = 0; kk < NUM_SECTOR; kk++) + for (kk = 0; kk < NUM_SECTOR; kk++) { dotProd = boundary_x[kk] * x + boundary_y[kk] * y; - if (dotProd > max) + if (dotProd > max) { max = dotProd; maxi = kk; } - else + else { - if (-dotProd > max) + if (-dotProd > max) { max = -dotProd; maxi = kk + NUM_SECTOR; @@ -134,14 +134,14 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) } } alfa[j * width * 2 + i * 2 ] = maxi % NUM_SECTOR; - alfa[j * width * 2 + i * 2 + 1] = maxi; + alfa[j * width * 2 + i * 2 + 1] = maxi; }/*for(i = 0; i < width; i++)*/ }/*for(j = 0; j < height; j++)*/ //ïîäñ÷åò âåñîâ è ñìåùåíèé nearest = (int *)malloc(sizeof(int ) * k); w = (float*)malloc(sizeof(float) * (k * 2)); - + for(i = 0; i < k / 2; i++) { nearest[i] = -1; @@ -155,15 +155,15 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) { b_x = k / 2 + j + 0.5f; a_x = k / 2 - j - 0.5f; - w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x)); - w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x)); + w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x)); + w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x)); }/*for(j = 0; j < k / 2; j++)*/ for(j = k / 2; j < k; j++) { a_x = j - k / 2 + 0.5f; b_x =-j + k / 2 - 0.5f + k; - w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x)); - w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x)); + w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x)); + w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x)); }/*for(j = k / 2; j < k; j++)*/ @@ -176,40 +176,40 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) { for(jj = 0; jj < k; jj++) { - if ((i * k + ii > 0) && - (i * k + ii < height - 1) && - (j * k + jj > 0) && + if ((i * k + ii > 0) && + (i * k + ii < height - 1) && + (j * k + jj > 0) && (j * k + jj < width - 1)) { d = (k * i + ii) * width + (j * k + jj); - (*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 ]] += + (*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 ]] += r[d] * w[ii * 2] * w[jj * 2]; - (*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += + (*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += r[d] * w[ii * 2] * w[jj * 2]; - if ((i + nearest[ii] >= 0) && + if ((i + nearest[ii] >= 0) && (i + nearest[ii] <= sizeY - 1)) { - (*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 ] ] += + (*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 ] ] += r[d] * w[ii * 2 + 1] * w[jj * 2 ]; - (*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += + (*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += r[d] * w[ii * 2 + 1] * w[jj * 2 ]; } - if ((j + nearest[jj] >= 0) && + if ((j + nearest[jj] >= 0) && (j + nearest[jj] <= sizeX - 1)) { - (*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] += + (*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] += r[d] * w[ii * 2] * w[jj * 2 + 1]; - (*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += + (*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += r[d] * w[ii * 2] * w[jj * 2 + 1]; } - if ((i + nearest[ii] >= 0) && - (i + nearest[ii] <= sizeY - 1) && - (j + nearest[jj] >= 0) && + if ((i + nearest[ii] >= 0) && + (i + nearest[ii] <= sizeY - 1) && + (j + nearest[jj] >= 0) && (j + nearest[jj] <= sizeX - 1)) { - (*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] += + (*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] += r[d] * w[ii * 2 + 1] * w[jj * 2 + 1]; - (*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += + (*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += r[d] * w[ii * 2 + 1] * w[jj * 2 + 1]; } } @@ -217,14 +217,14 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) }/*for(ii = 0; ii < k; ii++)*/ }/*for(j = 1; j < sizeX - 1; j++)*/ }/*for(i = 1; i < sizeY - 1; i++)*/ - + cvReleaseImage(&dx); cvReleaseImage(&dy); free(w); free(nearest); - + free(r); free(alfa); @@ -232,7 +232,7 @@ int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMap **map) } /* -// Feature map Normalization and Truncation +// Feature map Normalization and Truncation // // API // int normalizeAndTruncate(featureMap *map, const float alfa); @@ -270,7 +270,7 @@ int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa) }/*for(j = 0; j < p; j++)*/ partOfNorm[i] = valOfNorm; }/*for(i = 0; i < sizeX * sizeY; i++)*/ - + sizeX -= 2; sizeY -= 2; @@ -369,13 +369,13 @@ int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa) // Error status */ int PCAFeatureMaps(CvLSVMFeatureMap *map) -{ +{ int i,j, ii, jj, k; int sizeX, sizeY, p, pp, xp, yp, pos1, pos2; float * newData; float val; float nx, ny; - + sizeX = map->sizeX; sizeY = map->sizeY; p = map->numFeatures; @@ -424,7 +424,7 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map) }/*for(jj = 0; jj < xp; jj++)*/ newData[pos2 + k] = val * nx; k++; - } /*for(ii = 0; ii < yp; ii++)*/ + } /*for(ii = 0; ii < yp; ii++)*/ }/*for(j = 0; j < sizeX; j++)*/ }/*for(i = 0; i < sizeY; i++)*/ //swop data @@ -439,7 +439,7 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map) } -int getPathOfFeaturePyramid(IplImage * image, +static int getPathOfFeaturePyramid(IplImage * image, float step, int numStep, int startIndex, int sideLength, CvLSVMFeaturePyramid **maps) { @@ -447,7 +447,7 @@ int getPathOfFeaturePyramid(IplImage * image, IplImage *scaleTmp; float scale; int i, err; - + for(i = 0; i < numStep; i++) { scale = 1.0f / powf(step, (float)i); @@ -462,13 +462,13 @@ int getPathOfFeaturePyramid(IplImage * image, } /* -// Getting feature pyramid +// Getting feature pyramid // // API -// int getFeaturePyramid(IplImage * image, const filterObject **all_F, +// int getFeaturePyramid(IplImage * image, const filterObject **all_F, const int n_f, - const int lambda, const int k, - const int startX, const int startY, + const int lambda, const int k, + const int startX, const int startY, const int W, const int H, featurePyramid **maps); // INPUT // image - image @@ -484,7 +484,7 @@ int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps) int numStep; int maxNumCells; int W, H; - + if(image->depth == IPL_DEPTH_32F) { imgResize = image; @@ -493,9 +493,9 @@ int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps) { imgResize = cvCreateImage(cvSize(image->width , image->height) , IPL_DEPTH_32F , 3); - cvConvert(image, imgResize); + cvConvert(image, imgResize); } - + W = imgResize->width; H = imgResize->height; @@ -506,14 +506,14 @@ int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps) maxNumCells = H / SIDE_LENGTH; } numStep = (int)(logf((float) maxNumCells / (5.0f)) / logf( step )) + 1; - + allocFeaturePyramidObject(maps, numStep + LAMBDA); - getPathOfFeaturePyramid(imgResize, step , LAMBDA, 0, + getPathOfFeaturePyramid(imgResize, step , LAMBDA, 0, SIDE_LENGTH / 2, maps); - getPathOfFeaturePyramid(imgResize, step, numStep, LAMBDA, + getPathOfFeaturePyramid(imgResize, step, numStep, LAMBDA, SIDE_LENGTH , maps); - + if(image->depth != IPL_DEPTH_32F) { cvReleaseImage(&imgResize); diff --git a/modules/objdetect/src/fft.cpp b/modules/objdetect/src/fft.cpp index f60121f..b4164f5 100644 --- a/modules/objdetect/src/fft.cpp +++ b/modules/objdetect/src/fft.cpp @@ -1,14 +1,14 @@ #include "precomp.hpp" #include "_lsvm_fft.h" -int getEntireRes(int number, int divisor, int *entire, int *res) -{ - *entire = number / divisor; - *res = number % divisor; - return FFT_OK; -} +// static int getEntireRes(int number, int divisor, int *entire, int *res) +// { +// *entire = number / divisor; +// *res = number % divisor; +// return FFT_OK; +// } -int getMultipliers(int n, int *n1, int *n2) +static int getMultipliers(int n, int *n1, int *n2) { int multiplier, i; if (n == 1) @@ -36,13 +36,13 @@ int getMultipliers(int n, int *n1, int *n2) // 1-dimensional FFT // // API -// int fft(float *x_in, float *x_out, int n, int shift); +// int fft(float *x_in, float *x_out, int n, int shift); // INPUT // x_in - input signal // n - number of elements for searching Fourier image // shift - shift between input elements // OUTPUT -// x_out - output signal (contains 2n elements in order +// x_out - output signal (contains 2n elements in order Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.) // RESULT // Error status @@ -107,8 +107,8 @@ int fft(float *x_in, float *x_out, int n, int shift) // API // int fftInverse(float *x_in, float *x_out, int n, int shift); // INPUT -// x_in - Fourier image of 1d input signal(contains 2n elements - in order Re(x_in[0]), Im(x_in[0]), +// x_in - Fourier image of 1d input signal(contains 2n elements + in order Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.) // n - number of elements for searching counter FFT image // shift - shift between input elements @@ -180,7 +180,7 @@ int fftInverse(float *x_in, float *x_out, int n, int shift) // numColls - number of collumns // OUTPUT // x_out - output signal (contains (2 * numRows * numColls) elements - in order Re(x_in[0][0]), Im(x_in[0][0]), + in order Re(x_in[0][0]), Im(x_in[0][0]), Re(x_in[0][1]), Im(x_in[0][1]) and etc.) // RESULT // Error status @@ -193,14 +193,14 @@ int fft2d(float *x_in, float *x_out, int numRows, int numColls) x_outTmp = (float *)malloc(sizeof(float) * (2 * size)); for (i = 0; i < numRows; i++) { - fft(x_in + i * 2 * numColls, + fft(x_in + i * 2 * numColls, x_outTmp + i * 2 * numColls, numColls, 2); } for (i = 0; i < numColls; i++) { - fft(x_outTmp + 2 * i, - x_out + 2 * i, + fft(x_outTmp + 2 * i, + x_out + 2 * i, numRows, 2 * numColls); } free(x_outTmp); @@ -213,8 +213,8 @@ int fft2d(float *x_in, float *x_out, int numRows, int numColls) // API // int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls); // INPUT -// x_in - Fourier image of matrix (contains (2 * numRows * numColls) - elements in order Re(x_in[0][0]), Im(x_in[0][0]), +// x_in - Fourier image of matrix (contains (2 * numRows * numColls) + elements in order Re(x_in[0][0]), Im(x_in[0][0]), Re(x_in[0][1]), Im(x_in[0][1]) and etc.) // numRows - number of rows // numColls - number of collumns @@ -237,8 +237,8 @@ int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls) } for (i = 0; i < numColls; i++) { - fftInverse(x_outTmp + 2 * i, - x_out + 2 * i, + fftInverse(x_outTmp + 2 * i, + x_out + 2 * i, numRows, 2 * numColls); } free(x_outTmp); diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index f6c7d61..06e89e6 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -653,7 +653,7 @@ double icvEvalHidHaarClassifier( CvHidHaarClassifier* classifier, } -CV_IMPL int +static int cvRunHaarClassifierCascadeSum( const CvHaarClassifierCascade* _cascade, CvPoint pt, double& stage_sum, int start_stage ) { @@ -759,7 +759,7 @@ cvRunHaarClassifierCascadeSum( const CvHaarClassifierCascade* _cascade, sum += calc_sum(node->feature.rect[1],p_offset) * node->feature.rect[1].weight; if( node->feature.rect[2].p0 ) sum += calc_sum(node->feature.rect[2],p_offset) * node->feature.rect[2].weight; - + stage_sum += classifier->alpha[sum >= t]; #else // ayasin - NHM perf optim. Avoid use of costly flaky jcc @@ -771,7 +771,7 @@ cvRunHaarClassifierCascadeSum( const CvHaarClassifierCascade* _cascade, if( node->feature.rect[2].p0 ) _sum += calc_sum(node->feature.rect[2],p_offset) * node->feature.rect[2].weight; __m128d sum = _mm_set_sd(_sum); - + t = _mm_cmpgt_sd(t, sum); stage_sum = _mm_add_sd(stage_sum, _mm_blendv_pd(b, a, t)); #endif @@ -823,7 +823,7 @@ struct HaarDetectObjects_ScaleImage_Invoker HaarDetectObjects_ScaleImage_Invoker( const CvHaarClassifierCascade* _cascade, int _stripSize, double _factor, const Mat& _sum1, const Mat& _sqsum1, Mat* _norm1, - Mat* _mask1, Rect _equRect, ConcurrentRectVector& _vec, + Mat* _mask1, Rect _equRect, ConcurrentRectVector& _vec, std::vector& _levels, std::vector& _weights, bool _outputLevels ) { @@ -839,19 +839,19 @@ struct HaarDetectObjects_ScaleImage_Invoker rejectLevels = _outputLevels ? &_levels : 0; levelWeights = _outputLevels ? &_weights : 0; } - + void operator()( const BlockedRange& range ) const { Size winSize0 = cascade->orig_window_size; Size winSize(cvRound(winSize0.width*factor), cvRound(winSize0.height*factor)); int y1 = range.begin()*stripSize, y2 = min(range.end()*stripSize, sum1.rows - 1 - winSize0.height); - + if (y2 <= y1 || sum1.cols <= 1 + winSize0.width) return; - + Size ssz(sum1.cols - 1 - winSize0.width, y2 - y1); int x, y, ystep = factor > 2 ? 1 : 2; - + #ifdef HAVE_IPP if( cascade->hid_cascade->ipp_stages ) { @@ -860,7 +860,7 @@ struct HaarDetectObjects_ScaleImage_Invoker sqsum1.ptr(y1), sqsum1.step, norm1->ptr(y1), norm1->step, ippiSize(ssz.width, ssz.height), iequRect ); - + int positive = (ssz.width/ystep)*((ssz.height + ystep-1)/ystep); if( ystep == 1 ) @@ -870,12 +870,12 @@ struct HaarDetectObjects_ScaleImage_Invoker { uchar* mask1row = mask1->ptr(y); memset( mask1row, 0, ssz.width ); - + if( y % ystep == 0 ) for( x = 0; x < ssz.width; x += ystep ) mask1row[x] = (uchar)1; } - + for( int j = 0; j < cascade->count; j++ ) { if( ippiApplyHaarClassifier_32f_C1R( @@ -889,7 +889,7 @@ struct HaarDetectObjects_ScaleImage_Invoker if( positive <= 0 ) break; } - + if( positive > 0 ) for( y = y1; y < y2; y += ystep ) { @@ -929,11 +929,11 @@ struct HaarDetectObjects_ScaleImage_Invoker { if( result > 0 ) vec->push_back(Rect(cvRound(x*factor), cvRound(y*factor), - winSize.width, winSize.height)); + winSize.width, winSize.height)); } } } - + const CvHaarClassifierCascade* cascade; int stripSize; double factor; @@ -943,7 +943,7 @@ struct HaarDetectObjects_ScaleImage_Invoker std::vector* rejectLevels; std::vector* levelWeights; }; - + struct HaarDetectObjects_ScaleCascade_Invoker { @@ -960,7 +960,7 @@ struct HaarDetectObjects_ScaleCascade_Invoker p = _p; pq = _pq; vec = &_vec; } - + void operator()( const BlockedRange& range ) const { int iy, startY = range.begin(), endY = range.end(); @@ -968,14 +968,14 @@ struct HaarDetectObjects_ScaleCascade_Invoker const int *pq0 = pq[0], *pq1 = pq[1], *pq2 = pq[2], *pq3 = pq[3]; bool doCannyPruning = p0 != 0; int sstep = (int)(sumstep/sizeof(p0[0])); - + for( iy = startY; iy < endY; iy++ ) { int ix, y = cvRound(iy*ystep), ixstep = 1; for( ix = xrange.start; ix < xrange.end; ix += ixstep ) { int x = cvRound(ix*ystep); // it should really be ystep, not ixstep - + if( doCannyPruning ) { int offset = y*sstep + x; @@ -987,7 +987,7 @@ struct HaarDetectObjects_ScaleCascade_Invoker continue; } } - + int result = cvRunHaarClassifierCascade( cascade, cvPoint(x, y), 0 ); if( result > 0 ) vec->push_back(Rect(x, y, winsize.width, winsize.height)); @@ -995,7 +995,7 @@ struct HaarDetectObjects_ScaleCascade_Invoker } } } - + const CvHaarClassifierCascade* cascade; double ystep; size_t sumstep; @@ -1005,16 +1005,16 @@ struct HaarDetectObjects_ScaleCascade_Invoker const int** pq; ConcurrentRectVector* vec; }; - - + + } - + CvSeq* -cvHaarDetectObjectsForROC( const CvArr* _img, +cvHaarDetectObjectsForROC( const CvArr* _img, CvHaarClassifierCascade* cascade, CvMemStorage* storage, std::vector& rejectLevels, std::vector& levelWeights, - double scaleFactor, int minNeighbors, int flags, + double scaleFactor, int minNeighbors, int flags, CvSize minSize, CvSize maxSize, bool outputRejectLevels ) { const double GROUP_EPS = 0.2; @@ -1044,13 +1044,13 @@ cvHaarDetectObjectsForROC( const CvArr* _img, if( CV_MAT_DEPTH(img->type) != CV_8U ) CV_Error( CV_StsUnsupportedFormat, "Only 8-bit images are supported" ); - + if( scaleFactor <= 1 ) CV_Error( CV_StsOutOfRange, "scale factor must be > 1" ); if( findBiggestObject ) flags &= ~CV_HAAR_SCALE_IMAGE; - + if( maxSize.height == 0 || maxSize.width == 0 ) { maxSize.height = img->rows; @@ -1132,7 +1132,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img, #else const int stripCount = 1; #endif - + #ifdef HAVE_IPP if( use_ipp ) { @@ -1141,8 +1141,8 @@ cvHaarDetectObjectsForROC( const CvArr* _img, } else #endif - cvSetImagesForHaarClassifierCascade( cascade, &sum1, &sqsum1, _tilted, 1. ); - + cvSetImagesForHaarClassifierCascade( cascade, &sum1, &sqsum1, _tilted, 1. ); + cv::Mat _norm1(&norm1), _mask1(&mask1); cv::parallel_for(cv::BlockedRange(0, stripCount), cv::HaarDetectObjects_ScaleImage_Invoker(cascade, @@ -1242,22 +1242,22 @@ cvHaarDetectObjectsForROC( const CvArr* _img, { rectList.resize(allCandidates.size()); std::copy(allCandidates.begin(), allCandidates.end(), rectList.begin()); - + groupRectangles(rectList, std::max(minNeighbors, 1), GROUP_EPS); - + if( !rectList.empty() ) { size_t i, sz = rectList.size(); cv::Rect maxRect; - + for( i = 0; i < sz; i++ ) { if( rectList[i].area() > maxRect.area() ) maxRect = rectList[i]; } - + allCandidates.push_back(maxRect); - + scanROI = maxRect; int dx = cvRound(maxRect.width*GROUP_EPS); int dy = cvRound(maxRect.height*GROUP_EPS); @@ -1265,7 +1265,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img, scanROI.y = std::max(scanROI.y - dy, 0); scanROI.width = std::min(scanROI.width + dx*2, img->cols-1-scanROI.x); scanROI.height = std::min(scanROI.height + dy*2, img->rows-1-scanROI.y); - + double minScale = roughSearch ? 0.6 : 0.4; minSize.width = cvRound(maxRect.width*minScale); minSize.height = cvRound(maxRect.height*minScale); @@ -1277,7 +1277,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img, rectList.resize(allCandidates.size()); if(!allCandidates.empty()) std::copy(allCandidates.begin(), allCandidates.end(), rectList.begin()); - + if( minNeighbors != 0 || findBiggestObject ) { if( outputRejectLevels ) @@ -1291,11 +1291,11 @@ cvHaarDetectObjectsForROC( const CvArr* _img, } else rweights.resize(rectList.size(),0); - + if( findBiggestObject && rectList.size() ) { CvAvgComp result_comp = {{0,0,0,0},0}; - + for( size_t i = 0; i < rectList.size(); i++ ) { cv::Rect r = rectList[i]; @@ -1322,14 +1322,14 @@ cvHaarDetectObjectsForROC( const CvArr* _img, } CV_IMPL CvSeq* -cvHaarDetectObjects( const CvArr* _img, +cvHaarDetectObjects( const CvArr* _img, CvHaarClassifierCascade* cascade, CvMemStorage* storage, double scaleFactor, int minNeighbors, int flags, CvSize minSize, CvSize maxSize ) { std::vector fakeLevels; std::vector fakeWeights; - return cvHaarDetectObjectsForROC( _img, cascade, storage, fakeLevels, fakeWeights, + return cvHaarDetectObjectsForROC( _img, cascade, storage, fakeLevels, fakeWeights, scaleFactor, minNeighbors, flags, minSize, maxSize, false ); } @@ -2091,7 +2091,7 @@ namespace cv HaarClassifierCascade::HaarClassifierCascade() {} HaarClassifierCascade::HaarClassifierCascade(const String& filename) { load(filename); } - + bool HaarClassifierCascade::load(const String& filename) { cascade = Ptr((CvHaarClassifierCascade*)cvLoad(filename.c_str(), 0, 0, 0)); diff --git a/modules/objdetect/src/latentsvm.cpp b/modules/objdetect/src/latentsvm.cpp index d61755a..3856cd3 100644 --- a/modules/objdetect/src/latentsvm.cpp +++ b/modules/objdetect/src/latentsvm.cpp @@ -3,11 +3,11 @@ #include "_lsvm_matching.h" /* -// Transformation filter displacement from the block space +// Transformation filter displacement from the block space // to the space of pixels at the initial image // // API -// int convertPoints(int countLevel, CvPoint *points, int *levels, +// int convertPoints(int countLevel, CvPoint *points, int *levels, CvPoint **partsDisplacement, int kPoints, int n); // INPUT // countLevel - the number of levels in the feature pyramid @@ -25,10 +25,10 @@ // RESULT // Error status */ -int convertPoints(int /*countLevel*/, int lambda, +int convertPoints(int /*countLevel*/, int lambda, int initialImageLevel, - CvPoint *points, int *levels, - CvPoint **partsDisplacement, int kPoints, int n, + CvPoint *points, int *levels, + CvPoint **partsDisplacement, int kPoints, int n, int maxXBorder, int maxYBorder) { @@ -37,7 +37,7 @@ int convertPoints(int /*countLevel*/, int lambda, step = powf( 2.0f, 1.0f / ((float)lambda) ); computeBorderSize(maxXBorder, maxYBorder, &bx, &by); - + for (i = 0; i < kPoints; i++) { // scaling factor for root filter @@ -48,10 +48,10 @@ int convertPoints(int /*countLevel*/, int lambda, // scaling factor for part filters scale = SIDE_LENGTH * powf(step, (float)(levels[i] - lambda - initialImageLevel)); for (j = 0; j < n; j++) - { - partsDisplacement[i][j].x = (int)((partsDisplacement[i][j].x - + { + partsDisplacement[i][j].x = (int)((partsDisplacement[i][j].x - 2 * bx + 1) * scale); - partsDisplacement[i][j].y = (int)((partsDisplacement[i][j].y - + partsDisplacement[i][j].y = (int)((partsDisplacement[i][j].y - 2 * by + 1) * scale); } } @@ -62,7 +62,7 @@ int convertPoints(int /*countLevel*/, int lambda, // Elimination boxes that are outside the image boudaries // // API -// int clippingBoxes(int width, int height, +// int clippingBoxes(int width, int height, CvPoint *points, int kPoints); // INPUT // width - image wediht @@ -72,12 +72,12 @@ int convertPoints(int /*countLevel*/, int lambda, // kPoints - points number // OUTPUT // points - updated points (if coordinates less than zero then - set zero coordinate, if coordinates more than image + set zero coordinate, if coordinates more than image size then set coordinates equal image size) // RESULT // Error status */ -int clippingBoxes(int width, int height, +int clippingBoxes(int width, int height, CvPoint *points, int kPoints) { int i; @@ -111,7 +111,7 @@ int clippingBoxes(int width, int height, int maxXBorder, int maxYBorder); // INPUT -// image - initial image +// image - initial image // maxXBorder - the largest root filter size (X-direction) // maxYBorder - the largest root filter size (Y-direction) // OUTPUT @@ -149,54 +149,54 @@ CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image, // Computation of the root filter displacement and values of score function // // API -// int searchObject(const featurePyramid *H, const filterObject **all_F, int n, - float b, +// int searchObject(const featurePyramid *H, const filterObject **all_F, int n, + float b, int maxXBorder, - int maxYBorder, + int maxYBorder, CvPoint **points, int **levels, int *kPoints, float *score, CvPoint ***partsDisplacement); // INPUT // image - initial image for searhing object -// all_F - the set of filters (the first element is root filter, +// all_F - the set of filters (the first element is root filter, other elements - part filters) // n - the number of part filters // b - linear term of the score function // maxXBorder - the largest root filter size (X-direction) // maxYBorder - the largest root filter size (Y-direction) // OUTPUT -// points - positions (x, y) of the upper-left corner +// points - positions (x, y) of the upper-left corner of root filter frame // levels - levels that correspond to each position // kPoints - number of positions // score - value of the score function -// partsDisplacement - part filters displacement for each position +// partsDisplacement - part filters displacement for each position of the root filter // RESULT // Error status */ -int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, - int n, float b, +int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, + int n, float b, int maxXBorder, - int maxYBorder, + int maxYBorder, CvPoint **points, int **levels, int *kPoints, float *score, CvPoint ***partsDisplacement) { int opResult; // Matching - opResult = maxFunctionalScore(all_F, n, H, b, maxXBorder, maxYBorder, - score, points, levels, + opResult = maxFunctionalScore(all_F, n, H, b, maxXBorder, maxYBorder, + score, points, levels, kPoints, partsDisplacement); if (opResult != LATENT_SVM_OK) { return LATENT_SVM_SEARCH_OBJECT_FAILED; } - - // Transformation filter displacement from the block space + + // 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->numLevels, LAMBDA, LAMBDA, (*points), - (*levels), (*partsDisplacement), (*kPoints), n, + convertPoints(H->numLevels, LAMBDA, LAMBDA, (*points), + (*levels), (*partsDisplacement), (*kPoints), n, maxXBorder, maxYBorder); return LATENT_SVM_OK; @@ -206,7 +206,7 @@ int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F // Computation right bottom corners coordinates of bounding boxes // // API -// int estimateBoxes(CvPoint *points, int *levels, int kPoints, +// int estimateBoxes(CvPoint *points, int *levels, int kPoints, int sizeX, int sizeY, CvPoint **oppositePoints); // INPUT // points - left top corners coordinates of bounding boxes @@ -217,7 +217,7 @@ int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F // RESULT // Error status */ -int estimateBoxes(CvPoint *points, int *levels, int kPoints, +static int estimateBoxes(CvPoint *points, int *levels, int kPoints, int sizeX, int sizeY, CvPoint **oppositePoints) { int i; @@ -237,16 +237,16 @@ int estimateBoxes(CvPoint *points, int *levels, int kPoints, // Computation of the root filter displacement and values of score function // // API -// int searchObjectThreshold(const featurePyramid *H, +// int searchObjectThreshold(const featurePyramid *H, const filterObject **all_F, int n, - float b, - int maxXBorder, int maxYBorder, + float b, + int maxXBorder, int maxYBorder, float scoreThreshold, - CvPoint **points, int **levels, int *kPoints, + CvPoint **points, int **levels, int *kPoints, float **score, CvPoint ***partsDisplacement); // INPUT // H - feature pyramid -// all_F - the set of filters (the first element is root filter, +// all_F - the set of filters (the first element is root filter, other elements - part filters) // n - the number of part filters // b - linear term of the score function @@ -254,22 +254,22 @@ int estimateBoxes(CvPoint *points, int *levels, int kPoints, // maxYBorder - the largest root filter size (Y-direction) // scoreThreshold - score threshold // OUTPUT -// points - positions (x, y) of the upper-left corner +// points - positions (x, y) of the upper-left corner of root filter frame // levels - levels that correspond to each position // kPoints - number of positions // score - values of the score function -// partsDisplacement - part filters displacement for each position +// partsDisplacement - part filters displacement for each position of the root filter // RESULT // Error status */ -int searchObjectThreshold(const CvLSVMFeaturePyramid *H, +int searchObjectThreshold(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, int n, - float b, - int maxXBorder, int maxYBorder, + float b, + int maxXBorder, int maxYBorder, float scoreThreshold, - CvPoint **points, int **levels, int *kPoints, + CvPoint **points, int **levels, int *kPoints, float **score, CvPoint ***partsDisplacement, int numThreads) { @@ -284,28 +284,28 @@ int searchObjectThreshold(const CvLSVMFeaturePyramid *H, return opResult; } opResult = tbbThresholdFunctionalScore(all_F, n, H, b, maxXBorder, maxYBorder, - scoreThreshold, numThreads, score, - points, levels, kPoints, + scoreThreshold, numThreads, score, + points, levels, kPoints, partsDisplacement); #else - opResult = thresholdFunctionalScore(all_F, n, H, b, - maxXBorder, maxYBorder, - scoreThreshold, - score, points, levels, + opResult = thresholdFunctionalScore(all_F, n, H, b, + maxXBorder, maxYBorder, + scoreThreshold, + score, points, levels, kPoints, partsDisplacement); - (void)numThreads; + (void)numThreads; #endif if (opResult != LATENT_SVM_OK) { return LATENT_SVM_SEARCH_OBJECT_FAILED; - } - - // Transformation filter displacement from the block space + } + + // 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->numLevels, LAMBDA, LAMBDA, (*points), - (*levels), (*partsDisplacement), (*kPoints), n, + convertPoints(H->numLevels, LAMBDA, LAMBDA, (*points), + (*levels), (*partsDisplacement), (*kPoints), n, maxXBorder, maxYBorder); return LATENT_SVM_OK; @@ -350,9 +350,9 @@ int getOppositePoint(CvPoint point, // // API // int showRootFilterBoxes(const IplImage *image, - const filterObject *filter, + const filterObject *filter, CvPoint *points, int *levels, int kPoints, - CvScalar color, int thickness, + CvScalar color, int thickness, int line_type, int shift); // INPUT // image - initial image @@ -370,22 +370,22 @@ int getOppositePoint(CvPoint point, // Error status */ int showRootFilterBoxes(IplImage *image, - const CvLSVMFilterObject *filter, + const CvLSVMFilterObject *filter, CvPoint *points, int *levels, int kPoints, - CvScalar color, int thickness, + CvScalar color, int thickness, int line_type, int shift) -{ +{ int i; float step; CvPoint oppositePoint; step = powf( 2.0f, 1.0f / ((float)LAMBDA)); - + for (i = 0; i < kPoints; i++) { // Drawing rectangle for filter - getOppositePoint(points[i], filter->sizeX, filter->sizeY, + getOppositePoint(points[i], filter->sizeX, filter->sizeY, step, levels[i] - LAMBDA, &oppositePoint); - cvRectangle(image, points[i], oppositePoint, + cvRectangle(image, points[i], oppositePoint, color, thickness, line_type, shift); } #ifdef HAVE_OPENCV_HIGHGUI @@ -399,9 +399,9 @@ int showRootFilterBoxes(IplImage *image, // // API // int showPartFilterBoxes(const IplImage *image, - const filterObject *filter, + const filterObject *filter, CvPoint *points, int *levels, int kPoints, - CvScalar color, int thickness, + CvScalar color, int thickness, int line_type, int shift); // INPUT // image - initial image @@ -421,9 +421,9 @@ int showRootFilterBoxes(IplImage *image, */ int showPartFilterBoxes(IplImage *image, const CvLSVMFilterObject **filters, - int n, CvPoint **partsDisplacement, + int n, CvPoint **partsDisplacement, int *levels, int kPoints, - CvScalar color, int thickness, + CvScalar color, int thickness, int line_type, int shift) { int i, j; @@ -437,10 +437,10 @@ int showPartFilterBoxes(IplImage *image, for (j = 0; j < n; j++) { // Drawing rectangles for part filters - getOppositePoint(partsDisplacement[i][j], - filters[j + 1]->sizeX, filters[j + 1]->sizeY, + getOppositePoint(partsDisplacement[i][j], + filters[j + 1]->sizeX, filters[j + 1]->sizeY, step, levels[i] - 2 * LAMBDA, &oppositePoint); - cvRectangle(image, partsDisplacement[i][j], oppositePoint, + cvRectangle(image, partsDisplacement[i][j], oppositePoint, color, thickness, line_type, shift); } } @@ -454,8 +454,8 @@ int showPartFilterBoxes(IplImage *image, // Drawing boxes // // API -// int showBoxes(const IplImage *img, - const CvPoint *points, const CvPoint *oppositePoints, int kPoints, +// int showBoxes(const IplImage *img, + const CvPoint *points, const CvPoint *oppositePoints, int kPoints, CvScalar color, int thickness, int line_type, int shift); // INPUT // img - initial image @@ -470,14 +470,14 @@ int showPartFilterBoxes(IplImage *image, // RESULT // Error status */ -int showBoxes(IplImage *img, - const CvPoint *points, const CvPoint *oppositePoints, int kPoints, +int showBoxes(IplImage *img, + const CvPoint *points, const CvPoint *oppositePoints, int kPoints, CvScalar color, int thickness, int line_type, int shift) { int i; for (i = 0; i < kPoints; i++) { - cvRectangle(img, points[i], oppositePoints[i], + cvRectangle(img, points[i], oppositePoints[i], color, thickness, line_type, shift); } #ifdef HAVE_OPENCV_HIGHGUI @@ -491,10 +491,10 @@ int showBoxes(IplImage *img, // // API // int getMaxFilterDims(const filterObject **filters, int kComponents, - const int *kPartFilters, + const int *kPartFilters, unsigned int *maxXBorder, unsigned int *maxYBorder); // INPUT -// filters - a set of filters (at first root filter, then part filters +// filters - a set of filters (at first root filter, then part filters and etc. for all components) // kComponents - number of components // kPartFilters - number of part filters for each component @@ -505,10 +505,10 @@ int showBoxes(IplImage *img, // Error status */ int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents, - const int *kPartFilters, + const int *kPartFilters, unsigned int *maxXBorder, unsigned int *maxYBorder) { - int i, componentIndex; + int i, componentIndex; *maxXBorder = filters[0]->sizeX; *maxYBorder = filters[0]->sizeY; componentIndex = kPartFilters[0] + 1; @@ -532,7 +532,7 @@ int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents, // // API // int searchObjectThresholdSomeComponents(const featurePyramid *H, - const filterObject **filters, + const filterObject **filters, int kComponents, const int *kPartFilters, const float *b, float scoreThreshold, CvPoint **points, CvPoint **oppPoints, @@ -553,7 +553,7 @@ int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents, // Error status */ int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H, - const CvLSVMFilterObject **filters, + const CvLSVMFilterObject **filters, int kComponents, const int *kPartFilters, const float *b, float scoreThreshold, CvPoint **points, CvPoint **oppPoints, @@ -566,7 +566,7 @@ int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H, CvPoint **pointsArr, **oppPointsArr, ***partsDisplacementArr; float **scoreArr; int *kPointsArr, **levelsArr; - + // Allocation memory pointsArr = (CvPoint **)malloc(sizeof(CvPoint *) * kComponents); oppPointsArr = (CvPoint **)malloc(sizeof(CvPoint *) * kComponents); @@ -574,7 +574,7 @@ int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H, kPointsArr = (int *)malloc(sizeof(int) * kComponents); levelsArr = (int **)malloc(sizeof(int *) * kComponents); partsDisplacementArr = (CvPoint ***)malloc(sizeof(CvPoint **) * kComponents); - + // Getting maximum filter dimensions error = getMaxFilterDims(filters, kComponents, kPartFilters, &maxXBorder, &maxYBorder); componentIndex = 0; @@ -585,7 +585,7 @@ int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H, #ifdef HAVE_TBB error = searchObjectThreshold(H, &(filters[componentIndex]), kPartFilters[i], b[i], maxXBorder, maxYBorder, scoreThreshold, - &(pointsArr[i]), &(levelsArr[i]), &(kPointsArr[i]), + &(pointsArr[i]), &(levelsArr[i]), &(kPointsArr[i]), &(scoreArr[i]), &(partsDisplacementArr[i]), numThreads); if (error != LATENT_SVM_OK) { @@ -599,17 +599,17 @@ int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H, return LATENT_SVM_SEARCH_OBJECT_FAILED; } #else - (void)numThreads; + (void)numThreads; searchObjectThreshold(H, &(filters[componentIndex]), kPartFilters[i], - b[i], maxXBorder, maxYBorder, scoreThreshold, - &(pointsArr[i]), &(levelsArr[i]), &(kPointsArr[i]), + b[i], maxXBorder, maxYBorder, scoreThreshold, + &(pointsArr[i]), &(levelsArr[i]), &(kPointsArr[i]), &(scoreArr[i]), &(partsDisplacementArr[i])); #endif - estimateBoxes(pointsArr[i], levelsArr[i], kPointsArr[i], - filters[componentIndex]->sizeX, filters[componentIndex]->sizeY, &(oppPointsArr[i])); + estimateBoxes(pointsArr[i], levelsArr[i], kPointsArr[i], + filters[componentIndex]->sizeX, filters[componentIndex]->sizeY, &(oppPointsArr[i])); componentIndex += (kPartFilters[i] + 1); *kPoints += kPointsArr[i]; - } + } *points = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); *oppPoints = (CvPoint *)malloc(sizeof(CvPoint) * (*kPoints)); diff --git a/modules/objdetect/src/latentsvmdetector.cpp b/modules/objdetect/src/latentsvmdetector.cpp index cf20702..dd417fa 100644 --- a/modules/objdetect/src/latentsvmdetector.cpp +++ b/modules/objdetect/src/latentsvmdetector.cpp @@ -192,7 +192,7 @@ size_t LatentSvmDetector::getClassCount() const return classNames.size(); } -string extractModelName( const string& filename ) +static string extractModelName( const string& filename ) { size_t startPos = filename.rfind('/'); if( startPos == string::npos ) diff --git a/modules/objdetect/src/linemod.cpp b/modules/objdetect/src/linemod.cpp index 4635cc0..7a83190 100644 --- a/modules/objdetect/src/linemod.cpp +++ b/modules/objdetect/src/linemod.cpp @@ -91,7 +91,7 @@ void Feature::write(FileStorage& fs) const * * \return The bounding box of all the templates in original image coordinates. */ -Rect cropTemplates(std::vector