I'm working on a application that requires OpenCV object detection using Haar cascade classifier. I'm using OpenCV 2.3.1 with VS2010 on a 64bit Windows Machine. I compiled and built OpenCV myself and didn't use any pre-compiled binaries.
First, I wanted to start meddling with the example facedetect.cpp that's included in OpenCV. I built it with no errors, but when I'm trying to run it won't open the cascade classifier xml file (the CascadeClassifier.load() function returns false). I didn't change anything from the sample source code.
I'm using the xml file that is distributed with OpenCV so the problem isn't with the xml file. I also made sure that the application can access and read the file using a simple fopen.
I believe (but not sure) that the problem seems to be that the cascade classifier is of an "old" type. But in the OpenCV documentation it is specifically implied that the new CascadeClassifier object can open both "old" and "new" cascade classifiers.
Here's a link: http://opencv.itseez.com/modules/objdetect/doc/cascade_classification.html#cascadeclassifier-load
I even tried using the pre-compiled OpenCV2.2 binary and it works excellent with that xml. And then I tried to compile the 2.2 sample source code, and again it couldn't load the xml.
I'm aware that I can try using the old object CvHaarClassifierCascade, but I prefer to use the latest version of OpenCV and its objects.
Does anyone have a clue what am I doing wrong?
Give the complete path of the xml file
String face = "c:/data/xml/haarcascade_frontalface_alt.xml";
It should work!
I had the same situation. I solved it when I realized that I’m linking release libs in Debug configuration. Changing opencv_231*.lib
to opencv_*231d.lib
has solved the problem.
CascadeClassifier::load
is not the only function causing such troubles, see this thread for details: OpenCV imread(filename) fails in debug mode when using release libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With