Ask Your Question
0

How to grab pixel coordinates of detected face/eyes?

asked 2017-02-20 21:38:51 -0600

xanatos gravatar image

I've got face and eye detection/tracking running and I'm interested in having OpenCV provide the coordinates of the initial cv2.rectangle corner coordinates. The rectangle is built using frame:

 cv2.rectangle(frame, (rect[0], rect[1]), (rect[2], rect[3]), (0, 255, 0), 2)

Is rect[0], rect[1] the "upper left" corner of the rectangle, and rect[3], rect[4] the "lower right" corner?

My goal is to have these parameters drive servos that will keep the moving face "centered" by having the camera move based on these variable values (as a relative position to center image coordinates less rectangle dimension offset).

Thanks for your help,

Dave

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-02-22 12:49:19 -0600

(rect[0], rect[1]) yes those are exactly upper left and,.. , (rect[2], rect[3]) are the lower left corners..

you can just do the following

xFaceCenter=(rect[2]-rect[0])/2
yFaceCenter=(rect[3]-rect[1])/2

and now you have the height and width of the image frame lets say h,w then you can easily use

dy=(h/2)-yFaceCenter
dx=(w/2)-xFaceCenter

So you now just have to make these dy and dx values to be zero by changing the horizontal and vertical servo angle accordingly

edit flag offensive delete link more
0

answered 2017-02-21 03:37:23 -0600

As stated by yourself, the coordinates of the bounding box of any returned face/eye detection is of the form x_upper_left_corner y_upper_left_corner width height keeping in mind that the origin of OpenCV is at the upper left image corner.

You can easily use these parameters to apply some normalization of faces, as discussed in OpenCV 3 Blueprints, chapter 6, and as seen in the code for that chapter, right here.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-02-20 21:38:51 -0600

Seen: 3,402 times

Last updated: Feb 22 '17