Nodes/ComfyUI-CenterNode/Bounding Box Crop Node
ComfyUI Node

Bounding Box Crop Node

Turn any bounding box into a fixed-size, centered crop

By alessandrozonta·Created 2 years ago·Updated 2 years ago· 7
Bounding Box Crop Node
    • INT
    • INT
    left0
    top0
    right100
    bottom100
    crop_width50
    crop_height50

    Say a face detector hands you a bounding box. Sometimes it's 60×60 pixels, sometimes it's 140×95, because faces in a frame aren't all the same size. But the node downstream - a detailer, a face model, whatever - wants a fixed size, every single time, say 512×512. That mismatch is the whole reason BBoxCrop exists: give it a box of any size and it hands back the top-left coordinates of a crop of the exact size you asked for, centered on that box.

    It's a small node - the whole pack is basically this one idea - but it's also exactly the thing people go looking for on r/comfyui without knowing the name of what they want yet. "How do I get the x/y of the center of a face and crop to a size I need?" is a real, recurring question, and this node is a direct, if obscure, answer to it.

    How it works

    Feed it the four corners of a box - left, top, right, bottom - and it finds the center the obvious way: average the two x's and the two y's. Then, using the crop_width and crop_height you actually want, it works out where the top-left corner of a rectangle that size, centered on that same point, would land. That's the entire job. It doesn't touch pixels - no image goes in or out - it's pure coordinate math, one calculation, six number fields.

    The inputs and outputs that matter

    All six inputs are required INTs, nothing optional:

    • left, top, right, bottom - the source bounding box in pixel coordinates. You're rarely typing these by hand; they usually come off a detector node upstream - a face or object bbox, a SEGS output from something like Impact Pack.
    • crop_width, crop_height - the size of the crop you actually want, independent of however big the source box happened to be.

    The two INT outputs are the resulting crop's top-left x and y. They're not individually labeled in the node schema - both just come through as INT - but that's what the math produces, in the order the README describes: center first, then the top-left corner of your target size. Wire them into an image-crop node's x/y inputs alongside your own crop_width/crop_height, and check the result once so you know which output landed where.

    How to install it

    Small enough that Manager barely has to do anything. Search ComfyUI-CenterNode in ComfyUI Manager and install, or do it by hand:

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

    Restart ComfyUI and that's the whole install - no models, no non-trivial Python dependencies. It lands in the generic "Custom" category rather than its own submenu, so if you're hunting for it visually, search by its title ("Bounding Box Crop Node") instead of browsing categories.

    One thing worth knowing before you build a graph around it: the README's own example workflow additionally needs ComfyUI-Impact-Pack installed, because that's where the sample's bounding boxes and the actual crop node come from. BBoxCrop itself doesn't depend on Impact Pack - it's just what the demo leans on, and realistically also the most common real source of the boxes you'll feed into this thing in the first place, since Impact Pack's detectors are the default way most people get a bbox at all.

    Common issues & troubleshooting

    Nothing visibly happens when you run it. That's expected - this node only outputs two integers, it doesn't produce or preview an image. If you were expecting a cropped picture out the other side, you're missing a step: take the x/y this node gives you, plus your own crop_width/crop_height, and feed them into an actual image-crop node (Impact Pack has a few that take exactly this shape of input, and ComfyUI's own basic crop nodes work too).

    Coordinates land off the edge of the image, sometimes negative. If your requested crop_width or crop_height is bigger than the space around the detected box, the computed top-left corner can end up outside the frame. The node doesn't clamp anything - it's a straight formula, not a safety check - so sanity-check the output against your actual image dimensions before wiring it into a crop node that can't handle an out-of-range coordinate.

    The crop looks off-center or wrong. This almost always traces back to the input box itself, not this node - if a detector (or a manually typed test value) hands you left > right or top > bottom, the "center" comes out wrong and everything downstream inherits the mistake. Worth a quick print or a Reroute check on the raw bbox values if a crop looks strange.

    CategoryCustom

    Inputs (6)

    NameTypeDefaultDescription
    leftINT0
    topINT0
    rightINT100
    bottomINT100
    crop_widthINT50
    crop_heightINT50

    Outputs (2)

    NameTypeDescription
    INTINT
    INTINT