2

I'm using Haar-Cascade Classifier in order to detect faces.

I'm currently facing some problems with the following function:

void ImageManager::detectAndDisplay(Mat frame, CascadeClassifier face_cascade){


    string window_name = "Capture - Face detection";
    string filename;

    std::vector<Rect> faces;
    std::vector<Rect> eyes;
    Mat frame_gray;
    Mat crop;
    Mat res;
    Mat gray;
    string text;
    stringstream sstm;


    cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);

    // Detect faces
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));

    // Set Region of Interest
    cv::Rect roi_b;
    cv::Rect roi_c;

    size_t ic = 0; // ic is index of current element


    for (ic = 0; ic < faces.size(); ic++) // Iterate through all current elements (detected faces)  
    {

        roi_c.x = faces[ic].x;
        roi_c.y = faces[ic].y;
        roi_c.width = (faces[ic].width);
        roi_c.height = (faces[ic].height);



        crop = frame_gray(roi_c);

        faces_img.push_back(crop);

        rectangle(frame, Point(roi_c.x, roi_c.y), Point(roi_c.x + roi_c.width, roi_c.y + roi_c.height), Scalar(0,0,255), 2);


    }

    imshow("test", frame);
    waitKey(0);

    cout << faces_img.size();


}

The frame is the photo I'm trying to scan.

The face_cascade is the classifier.

Ema.jar
  • 2,370
  • 1
  • 33
  • 43
  • 2
    increase the minNeighbours param from 2 to 5 maybe (until you start to miss positives). – berak Dec 23 '14 at 15:22
  • btw, if you find more nice false detections, - feel free to [add them here](http://machine-pareidolia.appspot.com/) – berak Dec 28 '14 at 20:52

2 Answers2

8

internally, the CascadeClassifier does several detections, and groups those.

minNeighbours (in the detectMultiScale call) is the amount of detections in about the same place nessecary to count as a valid detection, so increase that from your current 2 to maybe 5 or so, until you start to miss positives.

berak
  • 39,159
  • 9
  • 91
  • 89
0

As an addition to berak's statement, it's not only about reducing/increasing of detectMultiScale parameters if you're not doing the stuff only on an image. You'll face performance problems that do not let the user use the application.

Performance issues are relying on miscalculations. And what calculation takes is just testing. If you are not trying to have the best results under different light conditions(since this is visual-dependent information) you'll have to scale the input array before sending it as an argument to detectMultiScale function. Once detection's completed, rescale to the previous size(it may be done by changing the rectangle's size that's used as an argument for detectMultiScale).