分类器对 opencv 人脸检测器的置信度

发布于 2024-12-12 14:19:11 字数 697 浏览 0 评论 0原文

我在 python 中使用 opencv 的 har 级联人脸检测器 (cv.HaarDetectObjects)。

例如:

    faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2,
    cv.CV_HAAR_DO_CANNY_PRUNING, (50,50))

       for f in faces:
           print(f)

这将以这种形式打印检测列表:

 ((174, 54, 114, 114), 53)
 ((22, 51, 121, 121), 36)
 ((321, 56, 114, 114), 21)
 ((173, 263, 125, 125), 51)
 ((323, 272, 114, 114), 20)
 ((26, 271, 121, 121), 36)

其中每行代表一个检测。前 4 个数字是左上角点的 x、y 位置,以及边界框的高度和宽度。最后一个数字是(引用自 openCV 文档)邻居的数量。

我想我有两个问题:

1)最后一个数字是什么意思?我在谷歌搜索时找不到任何相关参考。

2)(更重要)有没有办法获得每次检测的置信度分数?面部分类器在多大程度上确定检测对应于真实面部?

谢谢

I'm using opencv's har cascade face detector (cv.HaarDetectObjects) in python.

for example:

    faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2,
    cv.CV_HAAR_DO_CANNY_PRUNING, (50,50))

       for f in faces:
           print(f)

This will print a list of detections in this form:

 ((174, 54, 114, 114), 53)
 ((22, 51, 121, 121), 36)
 ((321, 56, 114, 114), 21)
 ((173, 263, 125, 125), 51)
 ((323, 272, 114, 114), 20)
 ((26, 271, 121, 121), 36)

Where each line represent a detection. The first 4 numbers are the x,y location of the top-left point, and the height, width of the bounding box. The last number is (quoting from the openCV documentation) the number of neighbors.

I guess I have two questions:

1) What does the last number mean? I couldn't find any reference to that when googling.

2) (more important)Is there a way to get a confidence score for each detection? How much is the face classifier certain that the detection corresponds to a real face?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说好的呢 2024-12-19 14:19:11

1) 检测代码对一个对象产生多个检测 - 例如以不同的比例、稍微偏移等。然后将检测分组,并且该组中的邻居的数量就是返回的数量。另请参见 Viola Jones 论文,第 5.6 段 (http: //research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_IJCV.pdf)和 OpenCV 源代码。

2)您可以使用邻居的数量作为某种置信度。

1) The detection code produces more than one detection for an object - e.g. in different scales, slightly shifted, etc. The detections are then grouped and the number of neighbours in such a group is the number returned. See also Viola Jones paper, paragraph 5.6 (http://research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_IJCV.pdf) and OpenCV source.

2) You can possibly use the number of neighbours as some measure of confidence.

陪你到最终 2024-12-19 14:19:11

非常感谢您的提问和回答,我一直在寻找具有置信度分数的 opencv 人脸检测一天。您的问题和回答为我解决问题提供了一些指导。

正如 Palmstrom 所说,最后一个数字表示该簇中对象位置的数量。您可以将其用作置信度得分。

据我所知,旧的Python API中只有这种API。新的API没有这个(集群中对象的数量)值。

我把我的代码放在这里,以防它对其他人有所帮助。这是一个旧的 python API,其教程很难找到。

import sys
import cv

def detect_face(image):
    image_size = cv.GetSize(image)
    # # create grayscale version
    grayscale = cv.CreateImage(image_size, 8, 1)
    cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)
    # # equalize histogram
    cv.EqualizeHist( grayscale,grayscale )

    #parameters to the detection function    
    cascade = cv.Load('haarcascade_frontalface_alt.xml')
    haar_scale = 1.1
    min_neighbors = 3
    haar_flags = cv.CV_HAAR_DO_CANNY_PRUNING
    min_size = (30,30)

    faces = cv.HaarDetectObjects(grayscale, cascade, cv.CreateMemStorage(0),
                                haar_scale, min_neighbors, haar_flags, min_size)

    print faces

    if len(faces) > 0:
        print '=> ' +  str(len(faces)) + ' face detected!'
        for ((x,y,width,height), n) in faces:
            pt1 = (x,y)
            pt2 = (x + width, y + height)
            cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 3, 8, 0) 


if __name__ == '__main__':

    filename = sys.argv[1]
    image = cv.LoadImage(filename,cv.CV_LOAD_IMAGE_COLOR);
    detect_face(image)

    cv.ShowImage("cam", image)
    cv.WaitKey(0)

Thanks a lot for your question and answer, I have been looking for a opencv face detection with confidence scores for a day. Your question and answer give me some guidance to solve the problem.

Like Palmstrom said, the last number means the number of object positions in that cluster. and you can use that as confidence score.

As far as I know, there is only such kind of API in the old python API. New API does not have this (number of object in the cluster) value.

I put my code here in case it will help some other people. This is a old python API whose tutorial is hard to find.

import sys
import cv

def detect_face(image):
    image_size = cv.GetSize(image)
    # # create grayscale version
    grayscale = cv.CreateImage(image_size, 8, 1)
    cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)
    # # equalize histogram
    cv.EqualizeHist( grayscale,grayscale )

    #parameters to the detection function    
    cascade = cv.Load('haarcascade_frontalface_alt.xml')
    haar_scale = 1.1
    min_neighbors = 3
    haar_flags = cv.CV_HAAR_DO_CANNY_PRUNING
    min_size = (30,30)

    faces = cv.HaarDetectObjects(grayscale, cascade, cv.CreateMemStorage(0),
                                haar_scale, min_neighbors, haar_flags, min_size)

    print faces

    if len(faces) > 0:
        print '=> ' +  str(len(faces)) + ' face detected!'
        for ((x,y,width,height), n) in faces:
            pt1 = (x,y)
            pt2 = (x + width, y + height)
            cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 3, 8, 0) 


if __name__ == '__main__':

    filename = sys.argv[1]
    image = cv.LoadImage(filename,cv.CV_LOAD_IMAGE_COLOR);
    detect_face(image)

    cv.ShowImage("cam", image)
    cv.WaitKey(0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文