Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 2.1: facedetect.cpp crashes when it finds ugly face

I am trying to compile the facedetect.cpp in the OpenCV\Samples\C folder, in Visual Studio 2010. The project compiles and begins just fine, shows a preview of my camera, and then seems to crash at cascade.detectMultiScale() as soon as it detects a face. I concluded that OpenCV thinks I am too ugly.

Unhandled exception at 0x100342bf in HeadTrackerExample.exe: 0xC0000005: Access violation writing location 0x00000000.

Unfortunately the debug info doesn't let me probe deeper. I am linking against cv210.lib;cxcore210.lib;highgui210.lib; the debug versions won't work:

LDR: LdrpWalkImportDescriptor() failed to probe D:\OpenCV2.1\bin\cv210d.dll for its manifest, ntstatus 0xc0150002

I'm going to try to trick the classifier with a printout of Anne Hathaway but I am open to other suggestions.

https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/facedetect.cpp

like image 899
Matt Montag Avatar asked Sep 29 '11 19:09

Matt Montag


1 Answers

I guess I'm better looking than you because it's working here (under OS X). Are you sure you're successfully loading the xml files? Are you using the default xml files (haarcascade_frontalface_alt.xml and haarcascade_eye_tree_eyeglasses.xml)?

It sure looks like you have a null pointer. Try setting a breakpoint at the call to cascade.detectMultiScale() and examine the values of cascade, smallImg, smallImg.data, and faces.

Edit: populating the faces vector

Here's the detectMultiScale code:

void HaarClassifierCascade::detectMultiScale( const Mat& image,
                       Vector<Rect>& objects, double scaleFactor,
                       int minNeighbors, int flags,
                       Size minSize )
{
    MemStorage storage(cvCreateMemStorage(0));
    CvMat _image = image;
    CvSeq* _objects = cvHaarDetectObjects( &_image, cascade, storage, scaleFactor,
                                           minNeighbors, flags, minSize );
    Seq<Rect>(_objects).copyTo(objects);
}

It's not touching the faces vector until the last line after all the detection is done. If you are adventurous, you could throw some printf statements in here to see if cvHaarDetectObjects is completing and if it is returning a null pointer.

like image 147
SSteve Avatar answered Sep 22 '22 22:09

SSteve