vss*_*vss 7 python opencv object-detection
我无法理解传递给detectMultiScale的参数.我知道一般语法是detectMultiScale(image,rejectLevels,levelWeights)但是,参数rejectLevels和levelWeights是什么意思?用于检测物体的最佳值是多少?
我想用它来检测眼睛的瞳孔
Raj*_*hah 14
在这些参数中,你需要更加关注其中的四个:
scaleFactor
– 指定图像大小在每个图像比例下缩小多少的参数。基本上,比例因子用于创建您的比例金字塔。更多解释,您的模型在训练期间定义了固定大小,这在 XML 中可见。这意味着在图像中检测到此大小的人脸(如果存在)。但是,通过重新缩放输入图像,您可以将较大的人脸调整为较小的人脸,使其可被算法检测到。
1.05 是一个很好的可能值,这意味着您使用一小步调整大小,即将大小减小 5%,您增加了找到与模型匹配的大小的机会以进行检测。这也意味着该算法的工作速度较慢,因为它更彻底。您可以将其增加到 1.4 以加快检测速度,但可能会完全遗漏某些人脸。
minNeighbors
– 指定每个候选矩形应保留多少邻居的参数。该参数会影响检测到的人脸的质量。值越高,检测次数越少,但质量越高。3~6 是一个很好的价值。
minSize
– 最小可能的对象大小。小于该值的对象将被忽略。这个参数决定了你想要检测的尺寸有多小。你来决定!通常,[30, 30] 是人脸检测的良好开端。
maxSize
– 最大可能的对象大小。大于此值的对象将被忽略。这个参数决定了你想检测多大的尺寸。再次,你决定!通常,您不需要手动设置它,默认值假设您要检测的人脸大小没有上限。
可以在此处找到代码示例:http: //docs.opencv.org/3.1.0/d7/d8b/tutorial_py_face_detection.html#gsc.tab=0
关于参数描述,您可能引用了旧的参数定义,实际上您可能面临以下参数:
在这里你可以找到关于这些参数的一个很好的解释:http: //www.bogotobogo.com/python/OpenCV_Python/python_opencv3_Image_Object_Detection_Face_Detection_Haar_Cascade_Classifiers.php
确保为面部和眼睛获得适当的预训练分类器组,例如
OpenCV类列表文档提供了所有 C++ 和 Python 方法的描述。
这是cv::CascadeClassifier detectorMultiScale的一个:
检测多尺度
Python:
Run Code Online (Sandbox Code Playgroud)objects = cv.CascadeClassifier.detectMultiScale(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]
参数:
Run Code Online (Sandbox Code Playgroud)image Matrix of the type CV_8U containing an image where objects are detected. objects Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image. 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. flags Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade. minSize Minimum possible object size. Objects smaller than that are ignored. maxSize Maximum possible object size. Objects larger than that are ignored. If maxSize == minSize model is evaluated on single scale.
笔记
- (Python) 使用级联分类器的人脸检测示例可以在 opencv_source_code/samples/python/facedetect.py 找到
如前所述,OpenCV 源代码中提供了示例用法。您可以将每个记录的参数作为关键字传递。
rects = cascade.detectMultiScale(img,
scaleFactor=1.3,
minNeighbors=4,
minSize=(30, 30),
flags=cv.CASCADE_SCALE_IMAGE)
Run Code Online (Sandbox Code Playgroud)