0
我是OpenCV人臉檢測器的新人。人臉檢測工作正常,但我想使用生成的矩形使框架在臉部周圍,並將其剪切以將臉部保存在新的存檔中。我一直使用getSubRect和「haarcascade_frontalface_default」(左,上,寬,高)返回的值。據推測,GetSubRect的參數是(圖像,(左,上,右,下),但它不起作用,因爲結果圖像沒有得到面部中心。代碼是下一個:cvGetSubRect沒有納入框架
import sys
import cv
imcolor = cv.LoadImage('C:\\Temp\\camera_test2.jpg') # input image
# loading the classifier
haarFace = cv.Load('c:\opencv\data\haarcascades\haarcascade_frontalface_default.xml')
# running the classifier
storage = cv.CreateMemStorage()
detectedFace = cv.HaarDetectObjects(imcolor, haarFace, storage, 1.1)
if detectedFace:
arg1 = detectedFace[0][0][0]
arg2 = detectedFace[0][0][1]
arg3 = detectedFace[0][0][2]
arg4 = detectedFace[0][0][3]
Izq = arg1 - arg3/10
Sup = arg2 - arg4/6
Der = arg1 + arg3 #+ (arg3/10)
Inf = arg2 + arg4 +(arg4/6)
print detectedFace
print Izq
print Sup
print Der
print Inf
imcolor2 = cv.GetSubRect(imcolor,(Izq, Sup, Der, Inf))
cv.SaveImage('C:\\temp\\test_1.JPG', imcolor2)
cv.WaitKey()
'cv2'代表OpenCV v2並且包含v1作爲'cv2.cv'。 「HaarDetectObjects」的後續版本有[documentation](http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html)和[tutorial](http://docs.opencv.org/ doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html#cascade-classifier)。 (在Python中它的工作原理是一樣的) –
是的Malthaeus,我做出了改變並且工作正常。唯一的問題是opencv不能用作Web應用程序。謝謝。 –