ComfyUI Node

ToolYoloCropper

Stop hand-cropping ControlNet references — let YOLO find and square the subject

By tooldigital·Created 2 years ago·Updated 2 years ago· 16
ToolYoloCropper
  • image
  • bounding box
  • image yolo detections
  • image original crop
  • image square crop
  • mask original crop
  • mask square crop
object
padding0

Every serious ComfyUI workflow eventually hits the same chore: your ControlNet or IP-Adapter model wants a 1:1 input, usually 1024×1024, but your reference photo has a person standing in the middle of a whole scene. So you crop the subject by hand, eyeball it square, and hope you didn't clip an ear. ToolYoloCropper is the one node that does that boring step for you - point it at an image, tell it what to look for, and it detects the subject, crops to it, and spits out a square crop plus masks, all ready to wire into conditioning.

It's from the single-node pack tooldigital/ComfyUI-Yolo-Cropper, and it's as simple as it gets: no API, no key, no install-time model downloads. Everything happens locally.

How it works

Under the hood it's YOLOv8 (Ultralytics), running two different models depending on what you ask for. Choose face and it loads a small face-detector (yolov8n-face.pt, the deepface weights). Choose anything else - and it's a full COCO 80-object list, from person and car down to toothbrush - and it loads the big general-purpose yolov8l.pt and filters detections down to your chosen class. When several objects match, it keeps the largest bounding box by area. That's the whole design: biggest hit wins, because for a square crop you want the main subject, not the tiny background extra.

Then the math that gives the node its name: it takes that box and expands the short side so the crop is square, centered on the original box's center. The padding input grows that box before squaring - so padding: 64 gives you a little breathing room around the subject, useful because tight crops are what make detailers and IP-Adapter fidgety. Note the padding only affects the square crop, not the "original" box crop.

Inputs and outputs that matter

Three inputs, and only one really needs thought:

  • image - any IMAGE tensor; it's an RGB image from a Load Image node in the vast majority of workflows.
  • object - the dropdown. This is the one you actually set. face and person cover most real use.
  • padding - pixels of extra room on the square crop. Start at 0, add 32–64 if the subject feels clipped.

You get six outputs, and three do the heavy lifting:

  • image square crop - the money output; feed this into ControlNet's image input or an IP-Adapter reference and it just works at 1:1.
  • mask square crop / mask original crop - black-and-white masks of the crop region, at full image resolution. These are your inpainting region or your compositing aid. Same playbook as ADetailer's detect-then-mask idea, just manual.
  • image yolo detections - the input with every detected box drawn on it. Ignore it in the final graph, but keep a preview around while tuning; it's how you see what the detector actually found.
  • bounding box - the crop coordinates as x, y, w, h. Handy if some other node wants a box.

Installing it

The README's documented path is plain git clone:

cd ComfyUI/custom_nodes
git clone https://github.com/tooldigital/ComfyUI-Yolo-Cropper.git

Then restart ComfyUI. ComfyUI-Manager can find it too, but no special handling there.

Here's the thing the README doesn't tell you: this pack ships no requirements.txt, yet the node does from ultralytics import YOLO at load time. Torch, numpy, PIL all come with ComfyUI, but ultralytics almost certainly doesn't. If the node fails to load with a module error, that's it:

# Windows (ComfyUI portable):
ComfyUI\python_embeded\python.exe -m pip install ultralytics
# Linux/Mac (venv):
/path/to/comfyui/venv/bin/pip install ultralytics

Model files - about 230 MB for yolov8l.pt, much less for the face model - download automatically on first run into ComfyUI/models/yolov8/. First run will feel hung while that happens; it isn't.

Where people get burned

  • Nothing detected. If the object list has no hit, the node doesn't error - it returns the entire un-cropped image for every crop/mask output, and a bbox of [0, 0, 0]. If your crop comes back identical to the input, that's what happened. Check the image yolo detections preview.
  • The face detector is small. face routes to the nano model, so face crops are fast but noticeably less robust than the l model on a person's shoulders or weird angles. If face detection keeps missing, try person.
  • Objects near the frame edge. The square gets clamped at the image border, so a subject hugging the edge yields a crop that's nudged off-center. Give it padding or re-frame the shot.
  • No license file in the repo - fine for personal use, but don't fold it into a commercial product without asking.

It won't change your life, but it kills a fiddly manual step that used to cost a few minutes per reference image. For ControlNet or FaceID prep, that's worth it.

CategoryToolYoloCropper

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
objectCOMBO81 options: face, person, bicycle, car, motorcycle, airplane, +75
paddingINT00–10000

Outputs (6)

NameTypeDescription
bounding boxBBOX
image yolo detectionsIMAGE
image original cropIMAGE
image square cropIMAGE
mask original cropMASK
mask square cropMASK