0

I have a problem to align faces using opencv. I detect the face then I use flandmarks and calculate the angle of rotation. I use this function to rotate the image :

cv::Mat rotate(cv::Mat src, double angle)
{
    cv::Mat dst;
    cv::Point2f pt(src.cols/2., src.rows/2.);
    cv::Mat r = getRotationMatrix2D(pt, angle, 1.0);
    cv::warpAffine(src, dst, r, cv::Size(src.cols, src.rows));
    return dst;
}

I want to find the new position of eyes after rotation to crop the face based on the eyes center.

Tyranitar
  • 37
  • 1
  • 7
  • Are you performing eye detection BEFORE alignment and going to find that corresponding region after rotation, or are you going to just perform eye detection AFTER rotation? –  Jul 23 '15 at 11:50
  • I detect the eyes then rotate based on the eyes position ... after that I want to find the new position of eyes to crop the face – Tyranitar Jul 23 '15 at 12:03

1 Answers1

0

For rotating(counterclockwise by an angle θ) a point (x,y) around another point (p,q) you need to use:

x′ = (x−p)cos(θ)−(y−q)sin(θ)+p,
y′ = (x−p)sin(θ)+(y−q)cos(θ)+q.

where x',y' are coordinates after rotation. In your case (p,q) is the center of the image if you rotated around center. Detailed Explanation could be found here: https://math.stackexchange.com/questions/270194/how-to-find-the-vertices-angle-after-rotation

So if you have eyes segmented as some areas you need to perform that operation on each pixel from area detected as eyes.

Community
  • 1
  • 1
Springfield762
  • 221
  • 1
  • 11