😺NKD Face Crop
Upright, square, tightly framed
- image
- face
- mask
- face_data
- roll
Every face model - a detailer, a swapper, a face upscaler - wants its input the same way: square, upright, and framed so the head fills most of the frame. Give it a head tilted in a wide shot and you're burning your re-render budget on a diagonal face that barely fills the crop. 😺NKD Face Crop finds the face, rotates it level, and crops it square at exactly the size your model wants, with a mask drawn from the facial landmarks thrown in for free.
It's the first half of a pipeline whose second half is 😺NKD Face Stitch: crop here, run your sampling, stitch back at the original angle. The face_data output carries the geometry so Stitch can put it back exactly where it came from.
How it works
The face detector is OpenCV's own YuNet (~232 KB, MIT, from OpenCV's model zoo) - downloaded once on first use, no segmentation model, no extra download. If you happen to have ultralytics installed, the crop switches to the standard YOLOv8 face detector instead. The landmarks that come with detection are what the mask is drawn from, which is why you get a usable face mask without paying for a segmentation pass.
The inputs that matter
size- side of the square crop, default 512. Set it to whatever your model's native resolution is.padding- how much wider than the face the crop is. 1.0 is the face alone; the default 1.7 leaves room for hair and chin.upright- on by default, and it's the whole point: the crop is rotated so the head is level. Turn it off to crop axis-aligned at the original angle.offset- slides the crop along the face's own axis; negative moves it up to take in more forehead.face_index- which face when there are several, in order of detector confidence. 0 is the surest.mask_region- what the mask covers:face(whole head area),face without features(eyes and mouth left out),skin(eyebrows too),features(just eyes, brows, mouth), ornone.forehead- how far above the brows the mask reaches. The landmarks stop at the brow, so this is an estimate: 1.0 lands near the hairline on most faces.refine_edges- lets the picture decide the last few pixels of the outline so it follows hair and jaw instead of cutting across them. Slower, and it can't see through things held in front of the face.
Outputs
face (the square, upright crop), mask (in the crop's coordinates - feed it to your inpaint or detailer), face_data (the geometry that drives Stitch), and roll - degrees of tilt taken out of the first frame, which is handy for skipping frames you'd rather not touch in a batch.
Install and gotchas
Install via ComfyUI Manager (search ComfyUI-NKD-Basic-Tools) or:
cd ComfyUI/custom_nodes
git clone https://github.com/Nekodificador/ComfyUI-NKD-Basic-Tools
Restart after. This node needs onnxruntime - the pack's real dependency - and if it's missing the face nodes are skipped at startup with a warning while the rest of the pack loads fine. YuNet (~232 KB) downloads itself on first use, so if your first run hangs on a download, that's it. The one workflow mistake to avoid: detail at the cropped resolution first, then upscale - upscaling a mangled face before the detail pass just bakes the damage into more pixels.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| size | INT | 51264–4096 | Side of the square crop, in pixels. |
| padding | FLOAT | 1.701–4 | How much wider than the face the crop is. 1.0 is the face alone; 1.7 leaves room for hair and chin. |
| upright | BOOLEAN | true | Rotate the crop so the head is level. Turn off to keep the original angle and crop axis-aligned. |
| offset | FLOAT | -0.13-0.5–0.5 | Slides the crop along the face's own axis, as a fraction of its size. Negative moves it up, taking in more forehead. |
| face_index | INT | 00–64 | Which face to use when the picture has more than one, in order of how sure the detector is. 0 is the surest. |
| mask_region | COMBO | face | What the mask covers. 'face' is the whole head area, 'face without features' leaves the eyes and mouth out of it, 'skin' also leaves the eyebrows, 'features' is only the eyes, brows and mouth, and 'none' returns an empty mask. |
| forehead | FLOAT | 1.000–2 | How far above the eyebrows the mask reaches. The landmarks stop at the brow, so this is an estimate: 1.0 lands near the hairline on most faces, lower keeps the mask below it, higher takes in more scalp. |
| refine_edges | BOOLEAN | false | Let the picture decide the last few pixels of the outline instead of the polygon, so the edge follows hair and jaw rather than cutting across them. Slower, and it cannot see through anything held in front of the face. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| face | IMAGE | The square, upright crop. |
| mask | MASK | The face mask, in the crop's coordinates. |
| face_data | NKD_FACEDATA | — |
| roll | FLOAT | Degrees of tilt taken out of the first frame, positive clockwise. |