Loading a saved yml file for LBPH Algorithm
I've saved the model in .yml
extension and tried to load it later. But unfortunately, I'm getting exception when loading the .yml
file.
When I tried to recognize the face through predict
function,
model->predict(preprocessedFace, identity, confidenceRatio);
it gives me the following exception:
Program has stopped working.
Windows can check online for a solution bla bla bla...
So, someone please suggest how should I proceed to overcome the problem. Thanks.
My save code:
Ptr<FaceRecognizer> model;
cout << "Learning the collected faces using the [" << facerecAlgorithm << "] algorithm ..." << endl;
bool haveContribModule = initModule_contrib();
if (!haveContribModule) {
cerr << "ERROR: The 'contrib' module is needed for FaceRecognizer but has not been loaded into OpenCV!" << endl;
exit(1);
}
model = Algorithm::create<FaceRecognizer>(facerecAlgorithm);
if (model.empty()) {
cerr << "ERROR: The FaceRecognizer algorithm [" << facerecAlgorithm << "] is not available in your version of OpenCV. Please update to OpenCV v2.4.1 or newer." << endl;
exit(1);
}
model->train(preprocessedFaces, faceLabels);
model->save("lbph_trained_data1.yml");
My load code:
Ptr<FaceRecognizer> model;
cout << "Loading the file ..." << endl;
bool haveContribModule = initModule_contrib();
if (!haveContribModule) {
cerr << "ERROR: The 'contrib' module is needed for FaceRecognizer but has not been loaded into OpenCV!" << endl;
exit(1);
}
model = Algorithm::create<FaceRecognizer>("FaceRecognizer.LBPH");
if (model.empty()) {
cerr << "ERROR: The FaceRecognizer algorithm [FaceRecognizer.LBPH] is not available in your version of OpenCV. Please update to OpenCV v2.4.1 or newer." << endl;
exit(1);
}
model->load("H:\\Face\\lbph_trained_data1.yml");
cout << "file loaded successfully" << endl;
did you try to debug it ?
model->load has a return value, check it !
@berak: It shows void as Load() return value. My openCV version is 2.4.7
oh, sorry, you're right, i confused something.
can you give me a direction plz? You solved my previous problem http://answers.opencv.org/question/25564/opencv-recognition-throws-exception-lbph-algorithm/
i am facing the same problem. so i updated opencv from 2.4.7 to 2.4.8, but the problem remains. it shows parsing error and missing , between elements in icvYMLParseValue. i am stuck. i debugged my code and found the exception is only because of model->load. plz help.
@AndroidXtreme: The problem is in the version 2.4.7. I forgot to give an answer here. I just update the version to 2.4.9 and it resolved. Plz try it. Thanks