Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Crash: example from Cascade Classifier tutorial

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.1".
[New Thread 0x7fffebd03700 (LWP 21922)]
face detector: 1 face(s) detected in collection/image_case_001.png
now detecting eyes for the face[0]=564x564+422+442...
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6edb158 in cv::CascadeClassifierImpl::runAt(cv::Ptr<cv::FeatureEvaluator>&, cv::Point_<int>, int, double&) () from /x/opencv/lib/libopencv_objdetect.so.3.0
gdb > bt
#0  0x00007ffff6edb158 in cv::CascadeClassifierImpl::runAt(cv::Ptr<cv::FeatureEvaluator>&, cv::Point_<int>, int, double&) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#1  0x00007ffff6ede0b9 in cv::CascadeClassifierInvoker::operator()(cv::Range const&) const () from /x/opencv/lib/libopencv_objdetect.so.3.0
#2  0x00007ffff6edf001 in cv::CascadeClassifierImpl::detectMultiScaleNoGrouping(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, cv::Size_<int>, cv::Size_<int>, bool) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#3  0x00007ffff6ee811d in cv::CascadeClassifierImpl::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, int, int, cv::Size_<int>, cv::Size_<int>, bool) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#4  0x00007ffff6ed2b1b in cv::CascadeClassifierImpl::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#5  0x00007ffff6ed7d35 in cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#6  0x0000000000401d6a in main (argc=2, argv=0x7fffffffe018) at crash.c++:40
gdb >

Crash: example from Cascade Classifier tutorial

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.1".
[New Thread 0x7fffebd03700 (LWP 21922)]
face detector: 1 face(s) detected in collection/image_case_001.png
now detecting eyes for the face[0]=564x564+422+442...
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6edb158 in cv::CascadeClassifierImpl::runAt(cv::Ptr<cv::FeatureEvaluator>&, cv::Point_<int>, int, double&) () from /x/opencv/lib/libopencv_objdetect.so.3.0
gdb > bt
#0  0x00007ffff6edb158 in cv::CascadeClassifierImpl::runAt(cv::Ptr<cv::FeatureEvaluator>&, cv::Point_<int>, int, double&) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#1  0x00007ffff6ede0b9 in cv::CascadeClassifierInvoker::operator()(cv::Range const&) const () from /x/opencv/lib/libopencv_objdetect.so.3.0
#2  0x00007ffff6edf001 in cv::CascadeClassifierImpl::detectMultiScaleNoGrouping(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, cv::Size_<int>, cv::Size_<int>, bool) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#3  0x00007ffff6ee811d in cv::CascadeClassifierImpl::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, int, int, cv::Size_<int>, cv::Size_<int>, bool) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#4  0x00007ffff6ed2b1b in cv::CascadeClassifierImpl::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#5  0x00007ffff6ed7d35 in cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>) () from /x/opencv/lib/libopencv_objdetect.so.3.0
#6  0x0000000000401d6a in main (argc=2, argv=0x7fffffffe018) at crash.c++:40
crash.c++:31
gdb >