Is there a way to get a measurement of confidence level when using haar face detection using OpenCV?
Asked Answered
C

5

10

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?

Cabalism answered 10/5, 2012 at 8:17 Comment(0)
F
8

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

Farlie answered 7/5, 2014 at 9:1 Comment(4)
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?Olenolin
Apparently there is an undocumented function in the C++ API aswell. void CascadeClassifier::detectMultiScale( const Mat& image, vector<Rect>& objects, vector<int>& rejectLevels, vector<double>& levelWeights, double scaleFactor, int minNeighbors, int flags, Size minObjectSize, Size maxObjectSize, bool outputRejectLevels )Kopeck
The newer OpenCV versions have this exposed and documented - docs.opencv.org/4.0.1/d1/de5/…Unpen
how to get confidence value when detecting face using this haar cascadeGoldstein
M
4

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.

Malcolm answered 10/5, 2012 at 8:26 Comment(0)
C
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

Couthie answered 22/5, 2013 at 19:39 Comment(0)
C
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) );

Churchy answered 27/5, 2014 at 16:21 Comment(0)
H
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.

Helladic answered 15/1, 2023 at 12:6 Comment(1)
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.Swatch

© 2022 - 2025 — McMap. All rights reserved.