0

I am using openCV 2.4.10 on c++ this code to count the faces in an image, but I am not getting the right result sometimes: I tried it on 50 images; only 22 images got the right result. What should I add to make it better?

 int countFacesInImage(Mat frame)
    {
    std::vector<Rect> faces;
    Mat frame_gray;

    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));

    return faces.size();
    }
PointedEars
  • 14,752
  • 4
  • 34
  • 33
laeemra
  • 1
  • 4
  • How are we supposed to know what your code does? Are you using OpenCV? – Potaito May 26 '15 at 11:03
  • @potAito it is opencv 2.4.10 and this is the function that count the faces and return the result – laeemra May 26 '15 at 11:07
  • opencv has the method documented. http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html#cascadeclassifier-detectmultiscale . you can tweak parameters. otherwise you may have to train your own cascade classifier. – 911 May 26 '15 at 11:11
  • @911 I am not using specific images , i have different image every time i use this function how could i modify the function for different images !!! – laeemra May 26 '15 at 11:55
  • How does your images that are not detected look like? – sop May 26 '15 at 12:42
  • @sop like if i have image with 4 faces it detect 3 or 5 or even 6 faces – laeemra May 26 '15 at 17:55
  • One thing that might help is to set a maxSize too. in your code you are only specifying a minSize. For example if the smaller face in your dataset is 30x30 and the largest one is 60x60: `face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30), Size(60,60))` – Amin Suzani May 27 '15 at 00:10
  • what do you mean by 5 or 6 faces, like two detections on one face (you should play with scaleFactor)? Not detecting one face may be because of the rotation of the face... Try to display all the detections to see exactly what is happening there. You can post the strange result for getting interpretations – sop May 27 '15 at 07:11

0 Answers0