Crash: example from Cascade Classifier tutorial

asked 2014-10-10 06:08:37 -0600

ilyad gravatar image

updated 2014-10-10 06:09:58 -0600

I try to run the example program from here (tutorial for Cascade Classifier). In order to run the face/eyes classifiers on set of existing photos I changed the code and made a minimal crashing example.

If I execute the program without eye recognition, it runs successfully and detects faces:

face detector: 1 face(s) detected in collection/image_case_001.png
face detector: 3 face(s) detected in collection/image_case_002.png
face detector: 5 face(s) detected in collection/image_case_003.png
face detector: 1 face(s) detected in collection/image_case_004.png
..... etc ...... 171 images processed

As soon as I call it with "-eyes" flag it crashes in detectMultiScale call when trying to find eyes in a successfully detected face:

face detector: 1 face(s) detected in collection/image_case_001.png
now detecting eyes for the face[0]=564x564+422+442...
Segmentation fault

The same happens if I try any of my images instead of the first one, so I believe something is wrong with the program, while data is okay.

I'm using opencv from git repo, last commit is "7e8846b81e420b 2014-09-30 13:39" on Debian Linux (testing distro).

Here is my program (very short, just 36 lines)

 1 #include <iostream>
 2 #include <opencv/cv.hpp>
 3 #include <opencv/highgui.h>
 4 #include <opencv2/objdetect/objdetect.hpp>
 5 #include <opencv2/objdetect/detection_based_tracker.hpp>

 6 int main(int argc, char **argv)
 7 {
 8   cv::CascadeClassifier face_classifier, eyes_classifier;

 9   if (not face_classifier.load("haarcascade_frontalface_alt.xml") or not eyes_classifier.load("haarcascade_eye_tree_eyeglasses.xml"))
10   {
11     std::cerr << "sorry, can't load XML files" << std::endl;
12     return 1;
13   }

14   for (int no=1; no<=171; ++no)
15   {
16     char path[1024];
17     sprintf(path, "collection/image_case_%03d.png", no);

18     std::vector<cv::Rect> faces;

19     cv::Mat gray, image = cv::imread(path, CV_LOAD_IMAGE_COLOR);

20     cv::cvtColor(image, gray, CV_BGRA2GRAY);
21     cv::equalizeHist(gray, gray);

22     face_classifier.detectMultiScale (gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
23     std::cout << "face detector: " << faces.size() << " face(s) detected in " << path << std::endl;

24     if (argc > 1 and (std::string) argv[1]=="-eyes") // eyes requested on command line
25       for (unsigned i=0; i < faces.size(); ++i)
26       {
27         std::vector<cv::Rect> eyes;
28         cv::Mat face_region = gray(faces[i]);
29         std::cout << "now detecting eyes for the face[" << i << "]="
30           << faces[i].width << "x" << faces[i].height << "+" << faces[i].x << "+" << faces[i].y << "..." << std::endl;
31         eyes_classifier.detectMultiScale(face_region, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
32         std::cout << "eyes detector: " << eyes.size() << " eye(s) detected in face[" << i << "]: " << std::endl;
33       }
34   }
35   return 0;
36 }

And here is the stack dump printed by GDB:

gdb > run -eyes
Starting program: /home/ilya/vision/./crash -eyes
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so ...
(more)
edit retag flag offensive close merge delete

Comments

throw in a :

if ( image.empty() ) { cerr &lt;&lt; "bah" &lt;&lt; endl; return 0;}

at line 19

berak gravatar imageberak ( 2014-10-10 07:01:00 -0600 )edit

oh, I'm happy you're here, I know your name from git commit history for the doc file. "image" is okay (but "image" is not the issue, it crashes when tries to find eyes in "face_region" after line 28) Alas, checking any of "image" or "face_region" doesn't help: both are correct images (I used the gui to output them both, I see the full image for "image" and just the black white face for "face_region")

ilyad gravatar imageilyad ( 2014-10-10 07:08:32 -0600 )edit