A face (or image) alignment refers to aligning one image (or face in your case) with respect to another (or reference image / face). It is also referred to as image registration. You can do this using either appearance (intensity-based registration) or key points (function-based registration). The second category stems from image motion models, where one image is considered an offset version of another.
In your case, landmarks (3 points for the eyes and nose?) Provide a good set of links for easy feature-based registration. Assuming you have a point set location on both 2D images, x_1 and x_2 you can evaluate the similarity transformation (rotation, translation, scaling), that is, a flat 2D S transformation that maps x_1 to x_2 . You can add to this a reflection, although for individuals this is likely to be superfluous.
Evaluation can be performed by generating normal equations and solving the linear least squares (LS) problem for the system x_1 = Sx_2 using linear regression. For 5 unknown parameters (2 turns, 2 translations, 1 scaling) you will need 3 points (more precisely 2.5) to solve 5 equations. The solution of the above LS can be obtained by direct linear transformation (for example, by applying SVD or matrix pseudo-inversion). For cases of a sufficiently large number of control points (i.e., Automatically detected), a method of the RANSAC type for point filtering and eliminating uncertainty (although this is not your case here).
After evaluating S apply the image transformation on the second image to get the converted grid (pixel) coordinates of the entire image 2 . The conversion will change the location of the pixels, but not their appearance. Inevitably, some of the converted areas of image 2 will be outside the image 1 grid, and you can select values ββfor these zero locations (for example, 0, NaN, etc.).
Read more: R. Seliski, Image Alignment and Stitching : Textbook "(section 4.3" Geometric Registration ")
In OpenCV, see: Geometric transformations of images . cv::getRotationMatrix2D cv::getAffineTransform and cv::warpAffine. Please note that you must evaluate and apply the similarity transformation (a special case of affine) in order to preserve angles and shapes.
source share