Tyranitar
Tyranitar

Reputation: 37

face alignment for face recognition

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.

Upvotes: 0

Views: 782

Answers (1)

Springfield762
Springfield762

Reputation: 231

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.

Upvotes: 0

Related Questions