简体   繁体   English

使用opencv和python的人脸检测精度

[英]Face detection accuracy using opencv and python

I have recently started learning opencv and written a program to detect faces in an image in python and save all detected faces as separate images. 我最近开始学习opencv,并编写了一个程序来用python检测图像中的面部并将所有检测到的面部保存为单独的图像。 It works fine for some images but fails to detect all the faces in many images. 对于某些图像,它工作正常,但无法检测到许多图像中的所有面部。

It fails in even this( http://imgur.com/HUh3tIK ) simple image. 它无法在连这个( http://imgur.com/HUh3tIK )简单的图像。 It detects only the right face but not the left face. 它仅检测右脸而不检测左脸。 Please help how to correct this to increase accuracy? 请帮助如何纠正此问题以提高准确性?

import cv2.cv as cv
import string
im = cv.LoadImageM("D:\Test\Dia.jpg")
storage = cv.CreateMemStorage()
haar=cv.Load("C:\opencv\data\haarcascades\haarcascade_frontalface_default.xml")
detected = cv.HaarDetectObjects(im, haar, storage, 1.1, 2,cv.CV_HAAR_DO_CANNY_PRUNING,(10,10))
i = 0
if detected:
    for face in detected:
        i = i + 1
        xx = face[0][0]
        yy = face[0][1]
        width = face[0][2]
        height = face[0][3]

        pankaj12 = (width,height)
        cvIm = cv.LoadImage("D:\Test\Dia.jpg")

        cropped = cv.CreateImage(pankaj12,cvIm.depth, cvIm.nChannels)
        src_region = cv.GetSubRect(cvIm, face[0])
        cv.Copy(src_region, cropped)
        cv.SaveImage("D:\Test\Pankaj"+str(i)+".jpg",cropped)

input("Press Enter to continue...")

I had better luck by running the algorithm multiple time using the different haarcascades classifiers provided with OpenCV and then by combining the results. 通过使用OpenCV随附的不同haarcascades分类器多次运行该算法,然后组合结果,我有了更好的运气。

In practice if two classifiers find similar results you can combine them and give to the combined result a higher score value. 在实践中,如果两个分类器找到相似的结果,则可以将它们合并,并为合并后的结果赋予较高的得分值。

To improve the detection even more you can also use the classifiers to detect eyes, noses and mouths. 为了进一步提高检测效率,您还可以使用分类器来检测眼睛,鼻子和嘴巴。 If you find those inside detected faces you can also add more value to those faces. 如果在检测到的面部中发现了这些面部,则还可以为这些面部添加更多的价值。

At the of the process you can get a list of detected faces with score value. 在此过程中,您可以获得具有得分值的检测到的面部列表。 The higher the score the more probable the detection is the correct one. 分数越高,检测出正确的可能性就越大。

hope this may help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM