Explore Courses Blog Tutorials Interview Questions
0 votes
in Machine Learning by (19k points)

I'm using OpenCV's har cascade face detector in python.

For example:

    faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2,

    cv.CV_HAAR_DO_CANNY_PRUNING, (50,50))

       for f in faces:


This will print a list of detections in this form:

 ((174, 54, 114, 114), 53)

 ((22, 51, 121, 121), 36)

 ((321, 56, 114, 114), 21)

 ((173, 263, 125, 125), 51)

 ((323, 272, 114, 114), 20)

 ((26, 271, 121, 121), 36)

Where each line represents a detection. The first 4 numbers are the x,y location of the top-left point, and the height, width of the bounding box. The last number is (quoting from the OpenCV documentation) the number of neighbors.

I guess I have two questions:

1) What does the last number mean? I couldn't find any reference to that when googling.

2) (more important)Is there a way to get a confidence score for each detection? How much is the face classifier certain that the detection corresponds to a real face?


1 Answer

0 votes
by (33.1k points)

1) The detection code produces more than one detection for an object - e.g. in different scales, slightly shifted, etc. The detections are then grouped and the number of neighbours in such a group is the number returned. See this ( and OpenCV source.

2) You can possibly use the number of neighbors as some measure of confidence.

For more details, go through Opencv Machine Learning. While to master the topic, one can always go through Machine Learning Certification.

Hope this answer helps you!

Browse Categories