Prepare BBoxes for SAM2
The adapter between boxes and segmentation
- jsonBbox
- bboxes
- All sam2_bboxes
- sam2_bboxe1
- sam2_bboxe2
- sam2_bboxe3
SAM2 (Segment Anything 2) doesn't find objects on its own - it segments given a prompt, typically a box or a point. Something upstream has to actually supply that box: a detector node, a vision-language model asked to locate an object, or a box you built by hand. This node is the plumbing between "a box from somewhere" and the specific shape SAM2's ComfyUI nodes expect it in.
Why the plural type matters
Look closely at the types here and there's a real detail worth flagging: every output on this node is BBOXES - plural - while KY_BBoxPosition and KY_ImageCropByBBox elsewhere in this pack use the singular BBOX. That's not a typo, it's a distinct type, almost certainly matching SAM2's own convention of working with a set of boxes (potentially one per tracked object, or one per frame for video segmentation) rather than a single region. Don't expect to wire a singular BBOX straight into something expecting BBOXES without going through a converter like this one first.
Inputs and outputs
Both inputs are optional: jsonBbox (a JSON string) and bboxes (typed BBOX, with an odd nested-empty-array default of [[[]]], which itself hints that BBOX here is really a list-of-lists structure under the hood). Neither is required, which means you need to actually feed one of them - don't assume the node has a sensible default behavior if you leave both empty.
Four outputs, all BBOXES: All sam2_bboxes (the full bundle) plus sam2_bboxe1, sam2_bboxe2, sam2_bboxe3 - the first three boxes broken out individually. That's convenient if your downstream SAM2 setup wants distinct box prompts for up to three separate objects rather than one bundled collection.
Where this fits in a real workflow
This is the literal "ground it with a VLM, derive the mask from the bbox" pattern: something (a vision-language model, an object detector) locates a region and describes it as a box, and SAM2 turns that box into an actual pixel mask you can use for inpainting, removal, or isolation - without ever painting a mask by hand. KY_JSONToBBox, elsewhere in this same pack, is built to take exactly the kind of JSON a vision-LLM might return and turn it into a BBOX - feeding that straight into this node's bboxes input, or piping the raw JSON directly into jsonBbox, is the intended chain.
Installing it
ComfyUI Manager: search ComfyUI-KYNode, install, restart. Or git clone https://github.com/yorkane/ComfyUI-KYNode into custom_nodes and restart. Note this node only prepares the boxes - it doesn't include SAM2 itself, which is a separate model/node pack you'll need installed alongside it.
Common issues
Since neither input is required, an empty run with both jsonBbox and bboxes left blank is likely to produce an empty or no-op result rather than an error - make sure you're actually feeding one of them.
Which SAM2 wrapper you're feeding into matters: there are a few competing SAM2 node packs in the ComfyUI ecosystem, and their exact expected input shape for a set of boxes isn't guaranteed to match this node's BBOXES output one-for-one. Check compatibility before assuming a plug-and-play connection, and be ready to insert your own conversion step if the downstream node complains about the shape.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| jsonBboxopt | JSON | — | |
| bboxesopt | BBOX | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| All sam2_bboxes | BBOXES | — |
| sam2_bboxe1 | BBOXES | — |
| sam2_bboxe2 | BBOXES | — |
| sam2_bboxe3 | BBOXES | — |