Dumar Linares
Dumar Linares

Reputation: 21

cvGetSubRect doesn't put in frame

I am new in working with OpenCV face detector. Face detection works fine but I am trying to use the rectangle generated to make a frame arround the face and cut it to save the face in a new archive. I have been using getSubRect with the values returned by "haarcascade_frontalface_default" (left, upper, width, height). It is supposed that the that the parameteres of GetSubRect are (image, (left, upper, right, bottom) but it doesn't work because resulting image doesn't get the face centered. What is my mistake?

The code is the next:

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()

Upvotes: 1

Views: 366

Answers (1)

Brandlingo
Brandlingo

Reputation: 3162

cv.GetSubRect expects (x, y, width, height):

for face, neighbors in detectedFace:
    im_face = cv.GetSubRect(imcolor, face)

Also see the documentation and the OpenCV Cookbook.

That said, why don't you use cv2?

Upvotes: 0

Related Questions