BBOX to Bounding Box KJ
The tiny bridge between KJNodes crop boxes and core ComfyUI
- bbox
- bounding_box
ComfyUI has two box types that are almost the same thing and refuse to talk to each other. KJNodes hands you a BBOX - a raw tuple of four numbers. Core nodes like Crop Image want a BOUNDING_BOX, a dict with x, y, width, height keys. This node is the one-line adapter: it takes a KJNodes BBOX and hands back the native dict. No image processing, no math you need to understand, just a format converter that sits between two halves of a workflow that never agreed on a convention.
Why you'll actually need it
The main source of a BBOX inside KJNodes is ImageTransformKJ, the pack's crop/resize workhorse, which outputs a bbox list alongside its cropped images and masks. If you crop with that and then want the exact same region handed to a core ComfyUI node - crop-and-upscale chains, feeding a region into a focused pass, whatever - you hit a type mismatch that won't connect on the canvas. This node is the fix. It's also handy if some other pack or a hand-typed box shows up in the old tuple format and a newer node only accepts the dict.
Honest counterpoint: if you're going KJNodes-to-KJNodes all the way through, you don't need it at all. It exists for the moments the graph crosses into native territory.
How it works
The converter is deliberately tolerant about what it eats. It flattens whatever comes in - a single tuple, a list of boxes, even a nested per-frame list of boxes or an already-native dict - into plain 4-tuples, then rebuilds one of them as a {"x", "y", "width", "height"} dict. If you tell it the incoming format is xyxy (corner coordinates), it normalizes so the box is always well-formed regardless of how the corners were ordered.
The inputs and outputs that matter
- bbox - the BBOX from any KJNodes node. Single or a list; both accepted.
- bbox_format - how the incoming numbers are laid out.
xywh(default) meansx, y, width, height; switch toxyxyif your producer emits corners instead. - index - when the input holds multiple boxes, which one to output. Clamped to the last box, so you can't index out of range.
- Output: bounding_box - the native
BOUNDING_BOXdict, ready for Crop Image and friends.
Installing KJNodes
The pack is a grab-bag of utility and QoL nodes from kijai, and this one ships inside it. Easiest path is ComfyUI Manager: search for KJNodes and install. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
cd ComfyUI-KJNodes
pip install -r requirements.txt
Then restart ComfyUI. The dependencies are refreshingly light for a pack this size - pillow, opencv, matplotlib and a couple of small helpers. No model files to download.
Where people get burned
The classic failure is a box that crops the wrong region, and nine times out of ten that's the bbox_format flag, not the node. If your box lands skewed or backwards, flip xywh ↔ xyxy. The other gotcha is feeding a multi-box list into something expecting one box - that's what index is for. Neither is dramatic; this node is boring in the best way, and boring is exactly what you want from a type adapter.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| bbox | BBOX | BBOX from any KJNodes node. Single boxes and lists of boxes are both accepted. | |
| bbox_format | COMBO | xywh | Layout of the incoming values. |
| index | INT | 00–4096 | When the input holds multiple boxes, pick which one to output. Clamped to the last box. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| bounding_box | BOUNDING_BOX | — |