In the OpenCV example, the cascading classifier xml does not load

I am working on an application that requires the discovery of an OpenCV object using the cascading Haar classifier. I am using OpenCV 2.3.1 with VS2010 on a 64 bit Windows machine. I compiled and built OpenCV myself and did not use any precompiled binaries.

First, I wanted to start interfering with the facesetect.cpp example that is included in OpenCV. I built it without errors, but when I try to run it, it will not open the XML file of the cascading classifier (the CascadeClassifier.load () function returns false). I did not change anything from the source code of the sample.

I am using an xml file that is distributed with OpenCV, so the problem is not with the xml file. I also made sure that the application can access and read the file using simple fopen.

I believe (but not sure) that the problem is that the cascading classifier is of the "old" type. But the OpenCV documentation specifically implies that the new CascadeClassifier object can open both "old" and "new" cascading classifiers.

Here's the 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 fine with this xml. And then I tried to compile the source code of example 2.2, and again it could not load xml.

I know that I can try to use the old CvHaarClassifierCascade object, but I prefer to use the latest version of OpenCV and its objects.

Does anyone know what I'm doing wrong?

+4
source share
4 answers

I had the same situation. I solved this when I realized that Im bundles libs releases in the Debug configuration. Changing opencv_231*.lib to opencv_*231d.lib solved the problem.

CascadeClassifier::load is not the only function that causes such problems. See this thread for more details: OpenCV imread (filename) error in debug mode when using release libraries .

+6
source

Specify the full path to the xml file

 String face = "c:/data/xml/haarcascade_frontalface_alt.xml"; 

It should work!

+5
source

I got this working using notepad ++. I converted all the relevant xml files to ANSI and also deleted the first line <?xml version="1.0"?> And then rewrote it manually.

+2
source

If you use windows, check the path. Concern

  • escape sequence on the way.
  • forward or backslashes depending on the operating system.

It should be like C:\\Ceemple\\data\\haarcascades\\haarcascade_frontalface_alt.xml . (by the way, I am using Ceemple IDE)

+2
source

Source: https://habr.com/ru/post/1381496/


All Articles