9

I developed an application for face detection using OpenCVs HAAR cascade face detection. The algorithm works fine, however every once in a while It finds patterns on the wall or ather things that are not faces.
I want to run additional checks on object suspected as faces but I want to do it only on objects that I am not confidant that they are faces. Is there a way to get a "confidence" level for a face detected by the HAAR cascade face detection?

Itay k
  • 4,163
  • 4
  • 31
  • 39

5 Answers5

8

OpenCV provides the confidence via the argument "weights" in function "detectMultiScale" from class CascadeClassifier, you need to put the flag "outputRejectLevels" to true

user3611413
  • 96
  • 1
  • 2
  • 1
    is this parameter available for openCV C++ API? I just see it in python API?!? For example, is there an undocumented way to use the flags parameter for this purpose? – Micka Feb 22 '16 at 09:38
  • [Apparently](http://code.opencv.org/issues/3064) there is an undocumented function in the C++ API aswell. `void CascadeClassifier::detectMultiScale( const Mat& image, vector& objects, vector& rejectLevels, vector& levelWeights, double scaleFactor, int minNeighbors, int flags, Size minObjectSize, Size maxObjectSize, bool outputRejectLevels )` – sietschie Apr 26 '16 at 10:00
  • The newer OpenCV versions have this exposed and documented - https://docs.opencv.org/4.0.1/d1/de5/classcv_1_1CascadeClassifier.html#accf96d130d9f3cf4c58bf445b7861c19 – Gabi Lee Mar 31 '19 at 08:49
  • how to get confidence value when detecting face using this haar cascade – Bryan Lumbantobing Feb 26 '21 at 02:39
3

OpenCV actually finds more than one result for any particular object, each detected area largely overlapping each other; those are then grouped together and form a 'number of neighbours' count. This count is the so called confidence.

When you perform object detection, one of the parameters is the minimum neighbours before a hit is returned. Increasing it reduces false positives, but also decreases the number of possible detected faces.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
1

Why not run multiple haar cascades (trained differently) against the same image and see if they produce similar results? Have them vote, as it were. Thus if only one cascade found a given face and the others didn't, that would give you less confidence in that given face.

I was able to run 3 cascades simultaneously on an iPhone video feed in real-time, so performance shouldn't be an issue in many normal scenarios. More here: http://rwoodley.org/?p=417

Bob Woodley
  • 1,246
  • 15
  • 30
0

Not a direct answer to your question, but this may help in reducing false detection.

You can get less false detection by tweaking MinNeibhbours, CV_HAAR_FIND_BIGGEST_OBJECT, and Size values.

int MinNeighbours = 7;

face_cascade.detectMultiScale( frame_gray, faces, 1.1, MinNeighbours, CV_HAAR_FIND_BIGGEST_OBJECT, Size(60, 60) );

MrGreen
  • 147
  • 1
  • 9
0

OpenCV's HAAR Cascade Face detection is very weak.

I suggest you use teachable machines to train personally and use tensorflow option to retrieve the code.

In my coding, i used tensorflow and it gave me the confidence parameter

   probabilities = model.predict_proba(x)

i used this.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 17 '23 at 12:53