By blakeO


2014-03-07 12:02:31 8 Comments

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?

2 comments

@yutasrobot 2014-03-07 12:41:11

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

@blakeO 2014-03-11 19:17:08

But why in case of setting minNeighbors to 1 it does't select the marked region? [link] (drive.google.com/file/d/0Bwc6G0Ct0fzFeURXbWJHdUswYlk/…)

@yutasrobot 2014-03-12 20:30:58

I don't know the full details of neighborhood approach, but idea is somehow similar. Maybe overlapping is required to select as a neighbor.

@herohuyongtao 2014-03-07 16:28:25

From OpenCV documentation:

minNeighbors – Parameter specifying how many neighbors each candidate rectangle should have to retain it.

In other words, this parameter will affect the quality of the detected faces. Higher value results in less detections but with higher quality.

The idea behind this parameter is that the detector will run on a multiple scale style and at the same time following sliding window strategy. After this step, it will give you multiple responses even for a single face region. This parameter tends to filter these responses just like by setting up a lower-bound threshold, i.e. it will only be counted as a valid face if the number of responses for this face is higher than minNeighbors.


To learn other parameters of CascadeClassifier::detectMultiScale, check out this post that I answered earlier.

Related Questions

Sponsored Content

23 Answered Questions

[SOLVED] Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition

0 Answered Questions

Non-Transformed Object detection with OpenCV

2 Answered Questions

[SOLVED] Haar classifier parameters tuning

0 Answered Questions

Hand detection and tracking methods

0 Answered Questions

OpenCV - Extract Features or use Haar training

1 Answered Questions

[SOLVED] OpenCV HOG Descriptor Parameters

1 Answered Questions

2 Answered Questions

1 Answered Questions

OpenCV `detectMultiScale()` neighbours algorithm

1 Answered Questions

Sponsored Content