pythonopencvdeep-learningface-detectionhaar-classifier

how to limit number of faces detected by haar cascades


I am using Haar cascade in an emotion detection system. Every video input I am giving to the model has only one face in it (It is a requirement). When I run Haar cascade model to detect faces, it has some false positives. Since I have only one face in the video, I want to take the most positive area detected and ignore all other detection. Is there a way to do that?


Solution

  • when you are calling detectMultiScale function, set the minNeighbours value to a high value to avoid false positives. Also, you can set the minSize parameter to specify a minimum size of face to be detected. Here is what I am using for face detection using a webcam.

    faces = faceCascade.detectMultiScale(
                gray,
                scaleFactor=1.2,
                minNeighbors=10,
                minSize=(64,64),
                flags=cv2.CASCADE_SCALE_IMAGE
            )