1

I'v got OpenCV 3.4 and I'm using c++ for developement on a Linux computer.

I'm doing some face recognition stuff and wanted to use Haar-Cascadeclassifiers. I found pretrained mouth and nose Cascadeclassifier, but they are in the "old" .xml format which looks like this:

<opencv_storage>
    <Boca_17stages type_id="opencv-haar-classifier">
       <size>
        25 15</size>
       <stages>
       <_>
       <!-- stage 0 -->
          <trees>
       ...

The .xml files provided by OpenCV work well. Those files are the new version, which looks like this:

<opencv_storage>
<cascade type_id="opencv-cascade-classifier"> 
 <stageType>BOOST</stageType>
  <featureType>HAAR</featureType>
  <height>20</height>
  <width>20</width>
  <stageParams>
  ...

I read in different posts, that OpenCV still can handle those old .xml files and can even convert them. But when I call cv::CascadeClassifier::convert(const String& oldcascade, const String& newcascade) nothing happens and it returns false;

When I loaded an old .xml file and tried detectMultiScale(... I get an Assertion:

OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file opencv-location/modules/objdetect/src/cascadedetect.cpp, line 1698
terminate called after throwing an instance of 'cv::Exception'
  what():  opencv-location/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215) !empty() in function detectMultiScale

My code looks similar to this:

 //Greyscale image myGrayMat is given
 Vector<Rect> eyes;
 Vector<Rect> mouth;
 CasscadeClassifier eyes = CascadeClassifier ("haarcascade_frontalface_alt.xml")
 CasscadeClassifier mouthCas1 = CascadeClassifier("mouth.xml");
 CassCadeClassifier mouthCas2= CascadeClassifier();
 mouthCas1.load("mouth.xml");

 //nothing happens here, returns false, no file is created
 CascadeClassifier::convert("mouth.xml","mouth_new.xml");

 //works well:
 eyesCas.detectMultiScale(myGrayMat,eyes,1.1,2,0|CV_HAAR_FIND_BIGGEST_OBJECT,Size(20,20));
 //Assertion fail
 mouthCas.detectMultiScale(myGrayMat,mouths,1.1,2,0|CV_HAAR_FIND_BIGGEST_OBJECT,Size(15,25));
 //assertion fail
 mouthCas.detectMultiScale(myGrayMat,mouths,1.1,2,0|CV_HAAR_FIND_BIGGEST_OBJECT,Size(15,25));

Can anyone please help me? Or can anyone just please convert the .xml files? That would be great. Thanks a lot!

Michriko
  • 337
  • 1
  • 11
  • 1
    can you try with opencv 2.4? There, both, old and new cascades definitely do work. If you got a problem there, too, maybe your cascade is corrupted. – Micka Jan 12 '18 at 18:17
  • I will have a try. Too bad OpenCV has such problems in version 3.4. Thanks for your response. – Michriko Jan 13 '18 at 07:36

1 Answers1

-2
CasscadeClassifier eyes = CascadeClassifier("haarcascade_frontalface_alt.xml")

cd /home/user/opencv-3.4.0/data/haarcascades

CasscadeClassifier eyes = CascadeClassifier ("/home/user/opencv-3.4.0/data/haarcascades/haarcascade_frontalface_alt.xml")
Floern
  • 33,559
  • 24
  • 104
  • 119
  • 2
    Please add some explanation/text to your answer. – Impulse The Fox Mar 22 '18 at 11:02
  • 1
    Thank you for this code snippet, which might provide some limited short-term help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its long-term value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Toby Speight Mar 22 '18 at 11:42