Nodes/ComfyUI-xiaozhuguang/小珠光 Face Align (人脸对齐)
ComfyUI Node

小珠光 Face Align (人脸对齐)

Alignment without the arc of despair

By xiaozhuguang·Created 2 months ago·Updated a day ago· 56
小珠光 Face Align (人脸对齐)
  • target_image
  • reference_image
  • aligned_reference_image
target_frame_index0
padding_modewhite
检测分辨率640

Face-swap and identity workflows have a dirty secret: the alignment step. You want a reference face composited onto a target's position and scale, and doing it by hand - or by an ArcFace embedding pipeline that drags in a model download and a license review - is a project. 小珠光 Face Align (人脸对齐) solves the boring version of the problem: it detects the face in your target image and the face in your reference image, then crops and scales the reference so the face lands at exactly the target's position and size. One node, no models to download.

Where this shines is compositing work that isn't a full identity swap: paste a consistent face onto a character across frames, align a source portrait to a different frame's head position before re-rendering, prep crops for a detail pass. If you need true identity preservation (matching who the face is, not just where it is), you still want a dedicated identity model - this node is about geometry, and it says so on the box.

How it works

It runs face detection on both images, then computes a canvas size from the target's face-relative size and scale, and extracts a window from the reference centered on the reference face so the two line up. Detection is MediaPipe (Apache-2.0) - the license-clean option the detailing docs call out as the swap for AGPL'd YOLO - with a fallback path if no face is found (it uses the whole image as a last resort rather than crashing). 检测分辨率 (detection resolution, default 640) controls the detection image size; 640 is a good balance, and you raise it if tiny faces aren't being found. padding_mode picks white or black for the area outside the extracted window.

The inputs that matter

  • target_image - the image whose face position you want to match.
  • reference_image - the face you're aligning onto the target.
  • target_frame_index - which frame of the target to use (target can be a batch).
  • padding_mode - white or black for the surrounding canvas.
  • 检测分辨率 - detector input resolution.

Output: aligned_reference_image - a single IMAGE, the reference cropped and scaled to the target's face geometry.

Install

From the ComfyUI-xiaozhuguang pack - Manager (search "ComfyUI-xiaozhuguang"), or:

cd ComfyUI/custom_nodes/
git clone https://github.com/xiaozhuguang/ComfyUI-xiaozhuguang.git

Restart. No model downloads. MediaPipe is a listed optional dependency - the pack falls back to whole-image detection if it's missing, but for real face alignment you'll want it: pip install mediapipe in your ComfyUI environment.

Gotchas

Two honest ones. First, MediaPipe's short-range detector is tuned for frontal faces - extreme angles can miss, and the fallback to whole-image detection will happily "align" a nothingburger. Keep faces roughly forward-facing for reliable results. Second, this aligns position and scale, not identity: the output is a crop of your reference, so any color or style mismatch between the two images still needs blending work downstream (the pack's ATR with blur_amount is the natural next hop).

Categoryxiaozhuguang

Inputs (5)

NameTypeDefaultDescription
target_imageIMAGE
reference_imageIMAGE
target_frame_indexINT00–999999
padding_modeCOMBOwhite2 options: white, black
检测分辨率INT640160–2048

Outputs (1)

NameTypeDescription
aligned_reference_imageIMAGE