BBox to Central Point (JSON)
Turn detection boxes into SAM2 point prompts — the glue between YOLO and SAM
- bboxes
- points_json
Detectors give you boxes; segmenters want points. Somewhere between "there's a person at these coordinates" and "give me a clean mask of that person," somebody has to do the translation. AnotherBBoxToPoints is that translator - it takes bounding boxes from a detection pass and emits the center point of each one as JSON, ready to feed into a SAM2 point-prompt node.
This is the kind of utility that makes the detect-then-segment pattern actually pleasant to build. You get a lot of mileage out of chaining a YOLO-style detector to a SAM2 segmenter in ComfyUI: the detector is cheap and finds objects, SAM2 is precise and cuts them out. The bridge between the two is a bbox-to-point conversion like this one.
How it works
The math is one line per box: center_x = x1 + (x2 - x1) / 2, center_y = y1 + (y2 - y1) / 2. For every box in the input it appends {"x": cx, "y": cy} to a list and serializes the whole thing to JSON. That's it. No thresholding, no filtering, no dedup - every box becomes a point, every point becomes a prompt.
One quirk worth knowing: it handles batches by taking the first image's boxes. If you feed it a nested batch of detections, it uses bboxes[0] and ignores the rest. For single-image workflows - which is what this is designed for - that's fine. For multi-image batches, it's a silent limitation you should know about before building something on it.
Inputs and outputs
bboxes(BBOX) - bounding boxes from a detection node. In this pack, that's the output ofAnotherYOLOInference(which returns aBBOX), orSEGStoBBoxif you're coming from Impact Pack SEGS. The format is lists of[x1, y1, x2, y2].- Output
points_json(STRING) - a JSON array like[{"x": 100.0, "y": 200.0}, ...].
That JSON string is exactly the format AnotherSAM2Inference expects for its points_pos input, and it's the same shape PointCollectorSAM2 produces - so the plumbing lines up across the pack without conversion headaches.
Installing it
It ships in the AnotherUtils pack:
cd ComfyUI/custom_nodes
git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
Restart ComfyUI, or install via ComfyUI Manager (search "AnotherUtils"). No dependencies beyond what the pack already pulls in.
Gotchas
The center-point shortcut is the main thing to keep in mind. A bbox center is usually a decent positive prompt for SAM2 - the middle of a detection tends to be inside the object - but it can land badly for donut-shaped or L-shaped subjects, where the center of the box is actually background. If your masks come out wrong in those cases, that's the reason, and it's why the manual point-collector nodes exist for the hard cases.
Also remember: no confidence filtering here. If your detector fires off ten overlapping boxes at the same object, you're sending ten center points to SAM2 and it'll merge them into one blob. If that bothers you, filter the detections upstream. For the common case - detect a few objects, feed their centers to SAM2 - this node is exactly the bridge you wanted.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| bboxes | BBOX | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| points_json | STRING | — |