Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV detectMultiScale() minNeighbors parameter

I'm currently using Haar classifiers, to detect objects. On my way, I didn't understand what is the minNeighbors parameter, what is it representing? Actually I don't understand what are the neighbors of the detection candidate rectangle. Please can anybody define the neighboring idea?

like image 480
blakeO Avatar asked Mar 07 '14 12:03

blakeO


People also ask

What is detectMultiScale in OpenCV?

detectMultiScale function is used to detect the faces. This function will return a rectangle with coordinates(x,y,w,h) around the detected face. It takes 3 common arguments — the input image, scaleFactor, and minNeighbours. scaleFactor specifies how much the image size is reduced with each scale.

What is scale factor in detectMultiScale?

I. Here is a list of the most common parameters of the detectMultiScale function : scaleFactor : Parameter specifying how much the image size is reduced at each image scale. minNeighbors : Parameter specifying how many neighbors each candidate rectangle should have to retain it. minSize : Minimum possible object size.

What is scale factor in cv2?

scaleFactor – Parameter specifying how much the image size is reduced at each image scale. Basically the scale factor is used to create your scale pyramid. More explanation can be found here. In short, as described here, your model has a fixed size defined during training, which is visible in the xml .

What is Face_detector detectMultiScale?

detectMultiScale(gray, 1.3, 5) MultiScale detects objects of different sizes in the input image and returns rectangles positioned on the faces.


1 Answers

Haar cascade classifier works with a sliding window approach. If you look at the cascade files you can see a size parameter which usually a pretty small value like 20 20. This is the smallest window that cascade can detect. So by applying a sliding window approach, you slide a window through out the picture than you resize it and search again until you can not resize it further. So with every iteration haar's cascaded classifier true outputs are stored. So when this window is slided in picture resized and slided again; it actually detects many many false positives. You can check what it detects by giving minNeighbors 0. So an example here :

minNeighbors = 0

So there are a lot of face detection because of resizing the sliding window and a lot of false positives too. So to eliminate false positives and get the proper face rectangle out of detections, neighborhood approach is applied. It is like if it is in neighborhood of other rectangles than it is ok, you can pass it further. So this number determines the how much neighborhood is required to pass it as a face rectangle. In the same image when it is 1 :

minNeighbors = 1

So by increasing this number you can eliminate false positives but be careful, by increasing it you can also lose true positives too. When it is 3 a perfect result :

minNeighbors = 3

like image 96
yutasrobot Avatar answered Sep 28 '22 00:09

yutasrobot