I am developing a face recognition system but I am having some problems when rotating the face to align it vertically and horizontally to its rectangle.
The face rectangle is not rotated by default, and it covers all the face. Here in this image you can see it.
My algorithm is really easy:
1. Get the face rotation angle (i.e. **20 degrees**)
2. Rotate each landmark of the face **-20degrees** using the center of the rectangle as pivot point.
If you know JavaScript you can see the code here:
The problem is that, sometimes, some parts of the rotated face are outside the rectangle. Does anybody knows what I am doing bad in my algorithm? I think the pivot point shouldn't be the one I choose but it makes sense on my mind.
Thank you.
I haven't looked at your code but based on your picture, it looks like what you essentially need to compute is a homography.
In general, this will not transform rectangles to rectangles but in most cases (unless you transform to points at infinity), you should be fine simply considing a larger rectangle within which the transformed rectangle will fit.