43

我目前正在使用 Haar 分类器来检测物体。在路上,我不明白 minNeighbors 参数是什么,它代表什么?实际上我不明白检测候选矩形的邻居是什么。请问有人可以定义相邻的想法吗?

4

2 回答 2

100

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

于 2014-03-07T12:41:11.227 回答
14

来自OpenCV 文档

minNeighbors – 指定每个候选矩形应该保留多少个邻居的参数。

也就是说,这个参数会影响检测到的人脸质量。更高的值导致更少的检测,但质量更高。

这个参数背后的想法是检测器将以多尺度样式运行,同时遵循滑动窗口策略。在此步骤之后,即使是单个面部区域,它也会为您提供多个响应。该参数倾向于过滤这些响应,就像通过设置下限阈值一样,即仅当此人脸的响应数高于 时才会将其视为有效人脸minNeighbors


要了解CascadeClassifier::detectMultiScale的其他参数,请查看我之前回答的这篇文章

于 2014-03-07T16:28:25.127 回答