首页 > 其他 > 详细

QT与OpenCV的碰撞

时间:2021-05-17 22:44:30      阅读:56      评论:0      收藏:0      [点我收藏+]

QT中对OpenCV的支持性还是非常好的

下文转自对OpenCV人脸检测方法detectMultiScale参数的理解

OpenCV中detectMultiScale参数的含义

detectMultiScale(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]) -> objects
@brief Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
此方法的任务是检测不同大小的对象,并返回矩形的列表。

@param image Matrix of the type CV_8U containing an image where objects are detected.
被检测的图片,需要转换为灰度图

@param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
scaleFactor 是重点,直接翻译就是“指定每次图像缩小的比例”,后面再说我的理解。

@param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have to retain it.
minNeighbors 也是重点,翻译为:指定每个候选矩形有多少个“邻居”,后面详说。

@param flags Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
flag参数与旧的级联方法cvHaarDetectObjects中一样,新的级联中不用。(没用到这个参数)

@param minSize Minimum possible object size. Objects smaller than that are ignored.
@param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.
minSize和maxSize 设置检测对象的最大最小值,低于minSize和高于maxSize的话就不会检测出来。

这里面最关键的两个参数就是scaleFactor和minNeighbors,我是通过一段英文解释来理解的,先来看一下:

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 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. 

So by increasing this number you can eliminate false positives but be careful, by increasing it you can also lose true positives too.

我就不直接翻译了,说一下我的理解:

大概意思是Haar cascade的工作原理是一种“滑动窗口”的方法,通过在图像中不断的“滑动检测窗口”来匹配人脸。

因为图像的像素有大有小,图像中的人脸因为远近不同也会有大有小,所以需要通过scaleFactor参数设置一个缩小的比例,对图像进行逐步缩小来检测,这个参数设置的越大,计算速度越快,但可能会错过了某个大小的人脸。

其实可以根据图像的像素值来设置此参数,像素大缩小的速度就可以快一点,通常在1~1.5之间。

那么,经过多次的迭代,实际会检测出很多很多个人脸,这一点可以通过把minNeighbors 设为0来验证。

所以呢,minNeighbors参数的作用就来了,只有其“邻居”大于等于这个值的结果才认为是正确结果。

参数值测试

首先scaleFactor=1.1(默认值),分别设置minNeighbors=0,1,3(默认为3),看一下输出结果。

minNeighbors=0,每个人脸都识别出来了,特别的是孟佳(左3)被识别出2次,李斯(右二上)被识别出1次:

技术分享图片

minNeighbors=1,李斯没识别出来,因为她的识别结果中没有“邻居”:

技术分享图片

minNeighbors=3,孟佳也没有识别出来,因为她的识别结果中只有1个“邻居”:

 技术分享图片

此时,对minNeighbors是不是有了形象的认识了。

因为我的图像只有300*200像素,而每次缩小1.1倍,所以导致识别出的结果较少。下面我让scaleFactor=1.03,minNeighbors=0,1,3,你会发现,当scaleFactor=1.03时,每个人脸被识别的次数都比上一组测试要多,因为每次缩小的比例小,迭代的次数就多了。看一下输出结果:

scaleFactor=1.03,minNeighbors=0:

技术分享图片

scaleFactor=1.03,minNeighbors=1:

技术分享图片

scaleFactor=1.03,minNeighbors=3:

技术分享图片

QT与OpenCV的碰撞

原文:https://www.cnblogs.com/coderhrz/p/14778084.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!