我最近开始学习opencv并编写了一个程序来检测python图像中的人脸并将所有检测到的人脸保存为单独的图像。它适用于某些图像,但无法检测到许多图像中的所有面孔。
它甚至在这个( http://imgur.com/HUh3tIK)简单图像中也失败了。它只检测右脸而不检测左脸。请帮助如何纠正这个以提高准确性?
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...")