My LBP face detection does not detect anything, never

asked 2015-06-03 06:06:19 -0500

Gioz79 gravatar image

updated 2015-06-03 07:07:07 -0500

Hi to all,

I'm a beginner with OpenCV. A real beginner, I'm at my first real application.

I'm setting up OpenCV for face detection on an embedded device; the face detection will occur an image at a time, image are fed from an external source.

I have read a lot of guides and tutorials, wanting to statically link libs, so I recompiled OpenCV 2.4.11 and finally did it (flags were ALL unchecked apart BUILD_opencv_[calib3d, contrib, core, features2d, flann, gpu, highgui, improc, legacy, ml, nonfree, objdetect, ocl, photo, stitching, superres, ts, video, videostab] and ENABLE_OMIT_FRAME_POINTER; I set CMAKE_BUILD_TYPE to "Release" too).

Now I can compile and run my application using "-lopencv_oobjdetect -lopencv_imgproc -lopencv_highgui -lopencv_core -lrt -lz -lm" as linker flags.

My code is:

CascadeClassifier face("/<full_path>/lbpcascade_frontalface.xml"); // shipped with OpenCV
vector<Rect> results;
unsigned char *data; // contains a frame extracted from a network camera, format is UYVY 640x480
int len; // length of data above
const vector<unsigned char> bytes(data, data + len);
Mat frame(bytes);
frame = imdecode(frame, CV_LOAD_IMAGE_GRAYSCALE);
Mat equalized;
equalizeHist(frame, equalized);
face.detectMultiScale(equalized, results, 1.1, 3, 0, Size(10,10));
if (results.size() > 0) {
  // never gets here :/

I redirected stdout and stderr to two files but they stay empty, it seems to work like a charm, but nothing is ever detected. I tried, in many steps, to pass to the above code 1 to 30 images per second, without any errors/complains/exceptions/(other things I don't know what to expect in my noobiness).

Any ideas, suggestions, tutorial that I should have read and I missed?

TIA, Ivan

edit retag flag offensive close merge delete



You can verify if your cascade is loaded: if(face.empty()) std::cout<<"empty cascade"<<std::endl;

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-06-03 06:44:24 -0500 )edit

Thanks for the suggestion! Just did it, and it seems loaded

Gioz79 gravatar imageGioz79 ( 2015-06-03 06:53:45 -0500 )edit

I was talking about this. More, if results is not empty, then you have detected something...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-06-03 07:51:16 -0500 )edit

Yes, sorry, I edited first post after your response. face.empty() is false, so I think it's loaded; and results.size() is always 0

Gioz79 gravatar imageGioz79 ( 2015-06-03 07:57:57 -0500 )edit


I started to work again on this project after a compelling job. I tried to save Mat s in files as per:

imwrite("test1.ppm", frame); imwrite("test2.ppm", equalized);

but the saved files have width 0! So I think the problem is transforming my UYVY image into an OpenCV frame. I haven't compiled OpenCV with PNG nor JPEG support so I tried to save them as PPM, but for the same reason is it possible that imdecode (see example above) fails for UYVY? Do I need to recompile OpenCV with some support? Some cmake flag enabled? And in this case, which one?

Gioz79 gravatar imageGioz79 ( 2015-07-09 10:42:52 -0500 )edit