Animesh Pandey
Animesh Pandey

Reputation: 6018

Error in loading cascade classifier in Opencv using cascade.load()!

I am using the facedetect.cpp code given in opencv samples. But the after building and running an error comes up because cascade.load(cascadeName) given an error i.e. returns zero. It was working a few days ago. Suddenly this error started to come. I also the full path of the XML file,but it did not work! This command was used to run the executable of the code :

`objectDetect --cascade="Full path to haarcascade_frontalface_alt.xml" --scale=1.3 %1`

The path of the XML file is correct!! Kindly check this snap shot

#include <opencv2\objdetect\objdetect.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[]) {
string xmlArray[] = {
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_eye.xml",
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_eye_tree_eyeglasses.xml",
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_frontalface_alt.xml",
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_frontalface_alt2.xml",
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_frontalface_alt_tree.xml",
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_frontalface_default.xml",
"D:/Visual Studio 2010/Projects/loadClassifierTest/haarcascades/haarcascade_fullbody.xml"
};
CascadeClassifier cascade;
for (int i = 0; i < 6; ++i) {
    if (!cascade.load(xmlArray[i]))
        cerr << "Could not load " << xmlArray[i] << " !" << endl;
    else
        cout << xmlArray[i] << " has been loaded!" << endl;
}
return 0;
}

All the xml files are in the same folder .... even after giving the full path .... they are not loading ... ! I don't think that there are any permission issues ...

Please help!

Upvotes: 0

Views: 4469

Answers (1)

Luca Davanzo
Luca Davanzo

Reputation: 21528

Have you tried passing absolute path in this way:

 String xmlFilePath = "c:/.../haarcascade_frontalface_alt.xml";

Is your file in a folder with Read-permission?

It should work, otherwise the problem is in another place of your code..

Upvotes: 1

Related Questions