Expand description
Face alignment via affine warp using 5 facial landmarks.
Given 5 landmarks (left_eye, right_eye, nose, left_mouth, right_mouth) detected by YuNet or other face detectors, computes a similarity transform that maps them to canonical ArcFace reference positions, then warps the source image to produce an aligned face crop.
Supports arbitrary output sizes:
- 112x112 for ArcFace recognition (default)
- 128x128 for inswapper face swapping
- any custom size (reference points are scaled proportionally)
The algorithm used is a simplified Umeyama estimator for 2D similarity transforms (rotation + uniform scale + translation).
Reference: S. Umeyama, “Least-Squares Estimation of Transformation Parameters Between Two Point Patterns”, IEEE TPAMI, 1991.
Constants§
- ALIGNED_
FACE_ SIZE - Default aligned face size (112x112, same as
ARCFACE_FACE_SIZE). - ARCFACE_
FACE_ SIZE - Output size for ArcFace recognition (112x112).
- INSWAPPER_
FACE_ SIZE - Output size for inswapper face swapping (128x128).
Functions§
- align_
face - Aligns a face by warping the source image using 5 detected landmarks.
- align_
face_ sized - Aligns a face by warping the source image to an arbitrary output size.