Search code examples
javaxmlimageopencvadaboost

opencv face-detection in java : conception steps


I'm working on face-detection project via webcam using opencv
In this approach (viola-jones) to detecting object in images combines four key concepts :

1-Simple rectangular features called haar features ( i can find this one in haarcascade_frontalface_alt.xml file).

2- An integral Image for raped feature detection.

3- The AdaBoost machine-learning method.

4-A cascaded classifier to combine many features efficiently.

my questions are:

-does haarcascade_frontalface_alt.xml contains the cascaded classifier also with the haar feature?

-how can i add the integral image and AdaBoost in my project and how to use it??or is it already done automatically??


Solution

  • it seems, you've read a lot of papers and pondered ideas, but have not found the opencv implementation ;)

    using it is actually quite easy:

    // setup a  cascade classifier:
    CascadeClassifier cascade;
    
    // load a pretrained cascadefile(and PLEASE CHECK!):
    bool ok = cascade.load("haarcascade_frontalface_alt.xml");
    if ( ! ok ) 
    {
        ...
    }
    
    
    // later, search for stuff in your img:
    Mat gray; // uchar grayscale!
    vector<Rect> faces; // the result vec
    
    cascade.detectMultiScale( gray, faces, 1.1, 3, 
        CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH  ,
        cv::Size(20, 20) );
    
    for ( size_t i=0; i<faces.size(); i++ )
    {
    // gray( faces[i] ); is the img portion that contains the detected object
    }