Ask Your Question
1

How to Find the angle at which the face and eyes are detected?

asked 2015-02-10 12:30:53 -0600

Muhammad Ghawas gravatar image

I am using "facedetect.py" for the detection of face and eyes. Now I want to calculate the angle (angle of elevation) at which face and eyes are detected. Can anyone Please help me in that.

edit retag flag offensive close merge delete

Comments

Can you explain your problem with a sample image?

Balaji R gravatar imageBalaji R ( 2015-02-10 23:22:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-02-11 04:19:59 -0600

If it is basically a face alignment that you want to achieve, then use this code snippet

double eyeXdis = eye_r.x - eye_l.x;
double eyeYdis = eye_r.y - eye_l.y;
double angle   = atan(eyeYdis/eyeXdis);
double degree  = angle*180/CV_PI;
double desired_eye_distance = 44.0;
double scale   = desired_eye_distance / eyeXdis; 

Mat res;
Point2f center(test.cols/2, test.rows/2);
Mat rot = getRotationMatrix2D(center, degree, scale);
warpAffine(test, res, rot, Size(), INTER_CUBIC, BORDER_CONSTANT, Scalar(127));

// probably crop this again from center

Credits to @berak for posting it in another topic this week.

edit flag offensive delete link more

Comments

@StevenPuttemans The "test" variable described in your solution is the image matrix, right? It's possible to apply the same solution to a set of points, i.e. If I have an matrix 2xn where each elements in row 1 represent the X coordinate of a vector and each element in row represents a Y coordinate.

chr0x gravatar imagechr0x ( 2015-07-22 12:13:11 -0600 )edit

Yep that is the image matrix indeed. As far as I know you could indeed get a transformation matrix if you give it 2 sets of points. However this is not done the same way as above. Look at the documentation of warpAffine. It has a sample where you calculate the transformation based on 2 groups of 3 points in space.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-23 02:50:58 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-10 12:30:53 -0600

Seen: 2,154 times

Last updated: Feb 11 '15