How to copy NormalBayesClassifier?
I am training and testing more classifiers and I want to save just the best of them. I have tried to use an if
and =
// for each train/eval
if (smallestError > errorRate)
{
best_Classifier = classifier;
}
// end for
best_Classifier.save("name");
but it seems that it gives me some null pointer error:
OpenCV Error: Null pointer (Null pointer to the written object) in cvWrite, file /home/me/opencv/modules/core/src/persistence.cpp, line 5011
terminate called after throwing an instance of 'cv::Exception'
what(): /home/me/opencv/modules/core/src/persistence.cpp:5011: error: (-27) Null pointer to the written object in function cvWrite
Can you suggest me some other way if this is not possible?
EDIT:
I have also tried using Ptr
, but it still does not work:
cv::Ptr< cv::NormalBayesClassifier > bestClassifier;
// for loop where train and evaluate the classifier cv::NormalBayesClassifier classifier;
if (smallestError > errorRate)
{
best_Classifier = &classifier;
smallesError = errorRate;
}
// end loop
best_Classifier->save("name");
And it gives me the following error:
OpenCV Error: The function/feature is not implemented () in CvStatModel::write, file /home/me/opencv/modules/ml/src/inner_functions.cpp, line 114
terminate called after throwing an instance of 'cv::Exception'
what(): /home/me/opencv/modules/ml/src/inner_functions.cpp:114: error: (-213) in function CvStatModel::write