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

不羁岁月 提交于 2019-12-08 09:31:22

问题


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!


回答1:


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..



来源:https://stackoverflow.com/questions/13824620/error-in-loading-cascade-classifier-in-opencv-using-cascade-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!