Skip to main content

Module face_alignment

Module face_alignment 

Source
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.