Nodes/Face-Aligned Center/Anime Face Detect & Crop
ComfyUI Node

Anime Face Detect & Crop

Anime face detection that actually handles chibi — and the README lies a little

By serhiiyashyn-sf·Created 4 months ago·Updated 4 months ago· 0
Anime Face Detect & Crop
  • images
  • cropped_images
  • face_masks
crop_size512
padding0.30

Sometimes you don't want to generate a face, you want to find one - to crop a reference, to build an inpainting mask, to pull clean face tiles for a face LoRA dataset. That's the job of Anime Face Detect & Crop, and the pack's README undersells it in a way worth knowing before you rely on it.

The README says the node uses lbpcascade_animeface, the classic OpenCV Haar cascade, auto-downloaded on first use. Read the actual code and that's now just the fallback. Since v1.2.1 the primary detector is YOLOv8n-face via ultralytics - the same face-model family ComfyUI-Yolo-Cropper uses - with the Haar cascade reserved for when ultralytics isn't installed or YOLO comes up empty. That's the gap between the docs and the shipped code, and it matters because Haar cascades are famously bad at chibi art, where the head is huge and tilted forward. YOLO is much more reliable there.

How it works

On a batch of images, the node runs the detector and keeps the largest face bbox it finds - one face per image, no multi-face handling. It expands that box to a square (adding your padding margin around it) and crops. Two things show real thought:

  • Rotation-aware Haar fallback. Haar cascades miss tilted chibi heads, so the fallback tries the upright image, then ±15° and ±30° rotations, and maps any bbox found on a rotated frame back to original coordinates. That's a lot of engineering for a "fallback."
  • Honest failure. If no face is detected, you get a center-crop of the original instead of a black frame - but the face_masks output stays empty for that frame, so downstream can tell detection actually failed rather than silently training on a garbage crop.

Both models download to ComfyUI/models/face_detection/ on first use: yolov8n-face.pt (~5MB, from a Hugging Face space) and lbpcascade_animeface.xml (~2MB, from the classic nagadomi repo). First run will stall a bit while it fetches; after that it's cached.

Inputs and outputs

  • crop_size (default 512) - square output crop in pixels.
  • padding (default 0.3) - extra margin around the detected box, as a fraction of its size. Bump it up when you want context around the face for an ID/reference crop; drop it toward 0 for tight face tiles.

Two outputs: cropped_images (the square face crops) and face_masks - a white rectangle at the original image dimensions, marking where the face was. That mask output is the useful one for workflows: wire it into an inpainting pass to regenerate just the face, or into a masked-training setup. The crop, honestly, you could reproduce with a Crop node; the mask at original resolution is the part that saves you time.

Installing

ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/serhiiyashyn-sf/comfyui-face-aligned-center
cd comfyui-face-aligned-center
pip install -r requirements.txt

Restart, and look in the FaceAlignedCenter category. The real dependency note: the pack's requirements.txt pulls in ultralytics, which is a heavy stack - big install, occasional version clashes with other nodes' pinned deps, the usual custom-node hazard the ecosystem warns about. If that's a problem you can live without it; the node degrades gracefully to the Haar cascade, which is exactly why the fallback exists.

Gotchas

  • Anime-specific by design. The Haar cascade is trained on anime faces; YOLO is a general face detector. On stylized/chibi art YOLO usually wins; on real photos it'll still find faces, but that's not what this node is for.
  • Largest face only. Group shots return one crop. Don't feed it a crowd.
  • Empty mask = failed detection. If you're scripting around this node, check face_masks for all-zero frames - that's the designed signal that you got a center-crop placeholder, not a face.

It's a small pack from a single author and the community footprint is essentially zero, so the source is your documentation. But it's MIT, short, and does the one thing - crop an anime face and hand you the mask - without fuss. For face-tile datasets or face-region inpainting it's a handy extra node in the bag.

CategoryFaceAlignedCenter

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
crop_sizeINT51264–4096Output square crop size (pixels).
paddingFLOAT0.300–2Extra margin around the detected bbox (fraction of bbox size).

Outputs (2)

NameTypeDescription
cropped_imagesIMAGE
face_masksMASK