私はOpenCV顔検出器を使用するのは初めてです。顔検出は正常に機能しますが、生成された長方形を使用して顔の周囲にフレームを作成し、それをカットして新しいアーカイブに顔を保存しようとしています。「haarcascade_frontalface_default」によって返される値(左、上、幅、高さ)でgetSubRectを使用しています。GetSubRectのパラメータは(image、(left、upper、right、bottom))であると想定されていますが、結果の画像が顔の中央に配置されないため、機能しません。私の間違いは何ですか?
コードは次のとおりです。
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()