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;
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)
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
sprintf( cmnt, "stage %d", i );
cvWriteComment( fs.fs, cmnt, 0 );
fs << "{";
- ((CvCascadeBoost*)((Ptr<CvCascadeBoost>)*it))->write( fs, featureMap );
+ (*it)->write( fs, featureMap );
fs << "}";
}
fs << "]";
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;
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;
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;
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];
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;
}
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 )