Search code examples
javac++opencvface-detection

Poor Performance with OpenCV 2.4.8 face detection


I installed the OpenCV 2.4.8 Java API to play with the face detection example that is given in the tutorial.

In the example, lbpcascade_frontalface.xml -which is a CascadeClassifier- works OK in detecting the female face image (lena.png) that they provide. However, when I tried it on this random image from the web, the classifier produced the following image, missing 4 obvious(!) faces:

enter image description here

I am quite disappointed because I expected this (with the clear contrasts) to be a very easy image for detecting faces.

1) Coding in Java, is it possible to improve this classifier to detect all faces in this picture? Or do I need C++ for this?

2) I looked at OpenCV's CascadeClassification web page and saw taht it is possible to train your own classifier. But the instructions are in C++. Has anyone done this using Java or is it only doable in C++?


Solution

  • I have saved your image and this c++ code finds the missing 4 faces as well as all the others (note the different Haar cascade and the minimum size):enter image description here

        Mat im1 = imread("JuVIA.png", CV_LOAD_IMAGE_COLOR);
    
        vector<Rect> faces;
        CascadeClassifier cascade( "C:/local/opencv249/sources/data/haarcascades/haarcascade_frontalface_alt2.xml" );
        cascade.detectMultiScale( im1, faces, 1.1, 2, 0| CV_HAAR_SCALE_IMAGE, Size(30, 30) );
    
        for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++ )
            cv::rectangle( im1, *r, CV_RGB(255,0,0) );
    
        imshow("in", im1);
        imwrite( "miss4.png", im1);
        waitKey();