fixed #2165
This commit is contained in:
parent
d38f694275
commit
69296c3333
@ -1257,6 +1257,7 @@ bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator,
|
|||||||
int _precalcValBufSize, int _precalcIdxBufSize,
|
int _precalcValBufSize, int _precalcIdxBufSize,
|
||||||
const CvCascadeBoostParams& _params )
|
const CvCascadeBoostParams& _params )
|
||||||
{
|
{
|
||||||
|
bool isTrained = false;
|
||||||
CV_Assert( !data );
|
CV_Assert( !data );
|
||||||
clear();
|
clear();
|
||||||
data = new CvCascadeBoostTrainData( _featureEvaluator, _numSamples,
|
data = new CvCascadeBoostTrainData( _featureEvaluator, _numSamples,
|
||||||
@ -1291,9 +1292,16 @@ bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator,
|
|||||||
}
|
}
|
||||||
while( !isErrDesired() && (weak->total < params.weak_count) );
|
while( !isErrDesired() && (weak->total < params.weak_count) );
|
||||||
|
|
||||||
data->is_classifier = true;
|
if(weak->total > 0)
|
||||||
data->free_train_data();
|
{
|
||||||
return true;
|
data->is_classifier = true;
|
||||||
|
data->free_train_data();
|
||||||
|
isTrained = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
clear();
|
||||||
|
|
||||||
|
return isTrained;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CvCascadeBoost::predict( int sampleIdx, bool returnSum ) const
|
float CvCascadeBoost::predict( int sampleIdx, bool returnSum ) const
|
||||||
|
@ -208,45 +208,55 @@ bool CvCascadeClassifier::train( const String _cascadeDirName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CvCascadeBoost* tempStage = new CvCascadeBoost;
|
CvCascadeBoost* tempStage = new CvCascadeBoost;
|
||||||
tempStage->train( (CvFeatureEvaluator*)featureEvaluator,
|
bool isStageTrained = tempStage->train( (CvFeatureEvaluator*)featureEvaluator,
|
||||||
curNumSamples, _precalcValBufSize, _precalcIdxBufSize,
|
curNumSamples, _precalcValBufSize, _precalcIdxBufSize,
|
||||||
*((CvCascadeBoostParams*)stageParams) );
|
*((CvCascadeBoostParams*)stageParams) );
|
||||||
stageClassifiers.push_back( tempStage );
|
|
||||||
|
|
||||||
cout << "END>" << endl;
|
cout << "END>" << endl;
|
||||||
|
|
||||||
|
if(!isStageTrained)
|
||||||
|
break;
|
||||||
|
|
||||||
|
stageClassifiers.push_back( tempStage );
|
||||||
|
|
||||||
// save params
|
// save params
|
||||||
String filename;
|
if( i == 0)
|
||||||
if ( i == 0)
|
|
||||||
{
|
{
|
||||||
filename = dirName + CC_PARAMS_FILENAME;
|
std::string paramsFilename = dirName + CC_PARAMS_FILENAME;
|
||||||
FileStorage fs( filename, FileStorage::WRITE);
|
FileStorage fs( paramsFilename, FileStorage::WRITE);
|
||||||
if ( !fs.isOpened() )
|
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;
|
<< " can not be opened." << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fs << FileStorage::getDefaultObjectName(filename) << "{";
|
fs << FileStorage::getDefaultObjectName(paramsFilename) << "{";
|
||||||
writeParams( fs );
|
writeParams( fs );
|
||||||
fs << "}";
|
fs << "}";
|
||||||
}
|
}
|
||||||
// save current stage
|
// save current stage
|
||||||
char buf[10];
|
char buf[10];
|
||||||
sprintf(buf, "%s%d", "stage", i );
|
sprintf(buf, "%s%d", "stage", i );
|
||||||
filename = dirName + buf + ".xml";
|
string stageFilename = dirName + buf + ".xml";
|
||||||
FileStorage fs( filename, FileStorage::WRITE );
|
FileStorage fs( stageFilename, FileStorage::WRITE );
|
||||||
if ( !fs.isOpened() )
|
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;
|
<< " can not be opened." << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fs << FileStorage::getDefaultObjectName(filename) << "{";
|
fs << FileStorage::getDefaultObjectName(stageFilename) << "{";
|
||||||
tempStage->write( fs, Mat() );
|
tempStage->write( fs, Mat() );
|
||||||
fs << "}";
|
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 );
|
save( dirName + CC_CASCADE_FILENAME, baseFormatSave );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user