pull/2/head
Maria Dimashova 13 years ago
parent d38f694275
commit 69296c3333
  1. 14
      apps/traincascade/boost.cpp
  2. 40
      apps/traincascade/cascadeclassifier.cpp

@ -1257,6 +1257,7 @@ bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator,
int _precalcValBufSize, int _precalcIdxBufSize,
const CvCascadeBoostParams& _params )
{
bool isTrained = false;
CV_Assert( !data );
clear();
data = new CvCascadeBoostTrainData( _featureEvaluator, _numSamples,
@ -1291,9 +1292,16 @@ bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator,
}
while( !isErrDesired() && (weak->total < params.weak_count) );
data->is_classifier = true;
data->free_train_data();
return true;
if(weak->total > 0)
{
data->is_classifier = true;
data->free_train_data();
isTrained = true;
}
else
clear();
return isTrained;
}
float CvCascadeBoost::predict( int sampleIdx, bool returnSum ) const

@ -208,45 +208,55 @@ bool CvCascadeClassifier::train( const String _cascadeDirName,
}
CvCascadeBoost* tempStage = new CvCascadeBoost;
tempStage->train( (CvFeatureEvaluator*)featureEvaluator,
curNumSamples, _precalcValBufSize, _precalcIdxBufSize,
*((CvCascadeBoostParams*)stageParams) );
stageClassifiers.push_back( tempStage );
bool isStageTrained = tempStage->train( (CvFeatureEvaluator*)featureEvaluator,
curNumSamples, _precalcValBufSize, _precalcIdxBufSize,
*((CvCascadeBoostParams*)stageParams) );
cout << "END>" << endl;
if(!isStageTrained)
break;
stageClassifiers.push_back( tempStage );
// save params
String filename;
if ( i == 0)
if( i == 0)
{
filename = dirName + CC_PARAMS_FILENAME;
FileStorage fs( filename, FileStorage::WRITE);
std::string paramsFilename = dirName + CC_PARAMS_FILENAME;
FileStorage fs( paramsFilename, FileStorage::WRITE);
if ( !fs.isOpened() )
{
cout << "Parameters can not be written, because file " << filename
cout << "Parameters can not be written, because file " << paramsFilename
<< " can not be opened." << endl;
return false;
}
fs << FileStorage::getDefaultObjectName(filename) << "{";
fs << FileStorage::getDefaultObjectName(paramsFilename) << "{";
writeParams( fs );
fs << "}";
}
// save current stage
char buf[10];
sprintf(buf, "%s%d", "stage", i );
filename = dirName + buf + ".xml";
FileStorage fs( filename, FileStorage::WRITE );
string stageFilename = dirName + buf + ".xml";
FileStorage fs( stageFilename, FileStorage::WRITE );
if ( !fs.isOpened() )
{
cout << "Current stage can not be written, because file " << filename
cout << "Current stage can not be written, because file " << stageFilename
<< " can not be opened." << endl;
return false;
}
fs << FileStorage::getDefaultObjectName(filename) << "{";
fs << FileStorage::getDefaultObjectName(stageFilename) << "{";
tempStage->write( fs, Mat() );
fs << "}";
}
if(stageClassifiers.size() == 0)
{
cout << "Cascade classifier can't be trained. Check the used training parameters." << endl;
return false;
}
save( dirName + CC_CASCADE_FILENAME, baseFormatSave );
return true;
}

Loading…
Cancel
Save