1 | initial version |
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.