Boring changes - apps.

This commit is contained in:
Roman Donchenko 2013-08-13 18:33:06 +04:00
parent eaa7fcc3e6
commit 34af7eeb84
2 changed files with 18 additions and 22 deletions

View File

@ -159,10 +159,10 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
cascadeParams = _cascadeParams;
featureParams = CvFeatureParams::create(cascadeParams.featureType);
featureParams->init(_featureParams);
stageParams = new CvCascadeBoostParams;
stageParams = makePtr<CvCascadeBoostParams>();
*stageParams = _stageParams;
featureEvaluator = CvFeatureEvaluator::create(cascadeParams.featureType);
featureEvaluator->init( (CvFeatureParams*)featureParams, numPos + numNeg, cascadeParams.winSize );
featureEvaluator->init( featureParams, numPos + numNeg, cascadeParams.winSize );
stageClassifiers.reserve( numStages );
}
cout << "PARAMETERS:" << endl;
@ -206,10 +206,10 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
break;
}
CvCascadeBoost* tempStage = new CvCascadeBoost;
bool isStageTrained = tempStage->train( (CvFeatureEvaluator*)featureEvaluator,
Ptr<CvCascadeBoost> tempStage = makePtr<CvCascadeBoost>();
bool isStageTrained = tempStage->train( featureEvaluator,
curNumSamples, _precalcValBufSize, _precalcIdxBufSize,
*((CvCascadeBoostParams*)stageParams) );
*stageParams );
cout << "END>" << endl;
if(!isStageTrained)
@ -325,7 +325,7 @@ void CvCascadeClassifier::writeParams( FileStorage &fs ) const
void CvCascadeClassifier::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
{
((CvFeatureEvaluator*)((Ptr<CvFeatureEvaluator>)featureEvaluator))->writeFeatures( fs, featureMap );
featureEvaluator->writeFeatures( fs, featureMap );
}
void CvCascadeClassifier::writeStages( FileStorage &fs, const Mat& featureMap ) const
@ -339,7 +339,7 @@ void CvCascadeClassifier::writeStages( FileStorage &fs, const Mat& featureMap )
sprintf( cmnt, "stage %d", i );
cvWriteComment( fs.fs, cmnt, 0 );
fs << "{";
((CvCascadeBoost*)((Ptr<CvCascadeBoost>)*it))->write( fs, featureMap );
(*it)->write( fs, featureMap );
fs << "}";
}
fs << "]";
@ -350,7 +350,7 @@ bool CvCascadeClassifier::readParams( const FileNode &node )
if ( !node.isMap() || !cascadeParams.read( node ) )
return false;
stageParams = new CvCascadeBoostParams;
stageParams = makePtr<CvCascadeBoostParams>();
FileNode rnode = node[CC_STAGE_PARAMS];
if ( !stageParams->read( rnode ) )
return false;
@ -371,12 +371,9 @@ bool CvCascadeClassifier::readStages( const FileNode &node)
FileNodeIterator it = rnode.begin();
for( int i = 0; i < min( (int)rnode.size(), numStages ); i++, it++ )
{
CvCascadeBoost* tempStage = new CvCascadeBoost;
if ( !tempStage->read( *it, (CvFeatureEvaluator *)featureEvaluator, *((CvCascadeBoostParams*)stageParams) ) )
{
delete tempStage;
Ptr<CvCascadeBoost> tempStage = makePtr<CvCascadeBoost>();
if ( !tempStage->read( *it, featureEvaluator, *stageParams) )
return false;
}
stageClassifiers.push_back(tempStage);
}
return true;
@ -453,7 +450,7 @@ void CvCascadeClassifier::save( const string filename, bool baseFormat )
fs << "{";
fs << ICV_HAAR_FEATURE_NAME << "{";
((CvHaarEvaluator*)((CvFeatureEvaluator*)featureEvaluator))->writeFeature( fs, tempNode->split->var_idx );
((CvHaarEvaluator*)featureEvaluator.get())->writeFeature( fs, tempNode->split->var_idx );
fs << "}";
fs << ICV_HAAR_THRESHOLD_NAME << tempNode->split->ord.c;
@ -499,7 +496,7 @@ bool CvCascadeClassifier::load( const string cascadeDirName )
if ( !readParams( node ) )
return false;
featureEvaluator = CvFeatureEvaluator::create(cascadeParams.featureType);
featureEvaluator->init( ((CvFeatureParams*)featureParams), numPos + numNeg, cascadeParams.winSize );
featureEvaluator->init( featureParams, numPos + numNeg, cascadeParams.winSize );
fs.release();
char buf[10];
@ -510,11 +507,10 @@ bool CvCascadeClassifier::load( const string cascadeDirName )
node = fs.getFirstTopLevelNode();
if ( !fs.isOpened() )
break;
CvCascadeBoost *tempStage = new CvCascadeBoost;
Ptr<CvCascadeBoost> tempStage = makePtr<CvCascadeBoost>();
if ( !tempStage->read( node, (CvFeatureEvaluator*)featureEvaluator, *((CvCascadeBoostParams*)stageParams )) )
if ( !tempStage->read( node, featureEvaluator, *stageParams ))
{
delete tempStage;
fs.release();
break;
}
@ -531,7 +527,7 @@ void CvCascadeClassifier::getUsedFeaturesIdxMap( Mat& featureMap )
for( vector< Ptr<CvCascadeBoost> >::const_iterator it = stageClassifiers.begin();
it != stageClassifiers.end(); it++ )
((CvCascadeBoost*)((Ptr<CvCascadeBoost>)(*it)))->markUsedFeaturesInMap( featureMap );
(*it)->markUsedFeaturesInMap( featureMap );
for( int fi = 0, idx = 0; fi < varCount; fi++ )
if ( featureMap.at<int>(0, fi) >= 0 )

View File

@ -18,9 +18,9 @@ int main( int argc, char* argv[] )
CvCascadeParams cascadeParams;
CvCascadeBoostParams stageParams;
Ptr<CvFeatureParams> featureParams[] = { Ptr<CvFeatureParams>(new CvHaarFeatureParams),
Ptr<CvFeatureParams>(new CvLBPFeatureParams),
Ptr<CvFeatureParams>(new CvHOGFeatureParams)
Ptr<CvFeatureParams> featureParams[] = { makePtr<CvHaarFeatureParams>(),
makePtr<CvLBPFeatureParams>(),
makePtr<CvHOGFeatureParams>()
};
int fc = sizeof(featureParams)/sizeof(featureParams[0]);
if( argc == 1 )