ComfyUI Node

String to BBOX

Turning Qwen's bbox output into pixel coordinates you can actually use

By WingeD123·Created 10 months ago·Updated 4 months ago· 46
String to BBOX
    • center_coordinates
    • bboxes
    string
    width1024
    height1024
    index

    The caption nodes in this pack have a bbox mode that makes Qwen spit out bounding-box coordinates for objects - but those coordinates are normalized to a 0–1000 scale, which nothing downstream can draw or inpaint with directly. String to BBOX is the adapter that fixes that. It takes the model's raw bbox text, converts it to real pixel coordinates, and hands you both the box list and the object center points. In one pipeline: Qwen bbox caption → StringToBbox → region-based editing, grounded in-painting, or SAM-style targeting. If you've only seen the caption nodes, this little utility is the quiet half of the pack's "describe objects with boxes" workflow.

    It lives in WingeD123/ComfyUI_QwenVL_PromptCaption, and it's a pure string-processing node - no model, no GPU, instant.

    How it works

    The Qwen bbox prompt asks the model to output a list of lists like [[250, 150, 450, 500], [600, 700, 800, 950]], where coordinates are normalized so 1000 = 100% of the image (the code calls it 千分比, per-mille). This node's parser is deliberately tolerant: it pulls every [a, b, c, d] array out of whatever text the model produced, ignoring labels and JSON wrappers, so a model that adds prose around the answer still parses. Then it multiplies by your real width and height, floors/ceils the edges (so the box slightly includes the object rather than cutting it), clamps to image bounds, and computes each box's center point. If parsing fails it returns a zeroed box rather than crashing, so your workflow keeps running with something inspectable.

    The inputs that matter

    • string - the model's bbox output, pasted or wired in from a caption node. Multiline.
    • width / height - the actual pixel dimensions of the image the boxes refer to. Get these wrong and the boxes land in the wrong place; wire them from your image's size rather than trusting memory. Defaults are 1024×1024.
    • index - optional. Leave empty to convert every box; enter 0,1,2 to pick specific ones. Handy when the model over-detects and you only want the first object.

    Outputs:

    • bboxes (BBOX) - the pixel boxes as [[x1, y1, x2, y2], ...], top-left then bottom-right corners.
    • center_coordinates (STRING) - a JSON string like [{"x": 350, "y": 325}, ...] with each box's center.

    That center output is the sleeper feature - center points are exactly what point-prompted segmenters and some region tools want, and it's one less node you'd otherwise need to write.

    Install

    There's nothing to configure beyond the pack itself. ComfyUI Manager (search "ComfyUI_QwenVL_PromptCaption") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/WingeD123/ComfyUI_QwenVL_PromptCaption
    

    then restart. No model needed - unlike the rest of the pack this node runs with no downloads and no transformers stack. You can start using it the second ComfyUI comes back up.

    Troubleshooting

    Almost every bug here is a coordinate-format mismatch. If boxes come out in the wrong place, the number-one cause is width/height not matching the actual image - the model thinks in percentages, so wrong dimensions shift everything. If you get a zeroed box, the input wasn't a valid [x1,y1,x2,y2] array - check that you wired a caption node set to bbox lang, not English. And remember the scale is 0–1000, not 0–1: feeding a 0–1 coordinate (like 0.25) into this gives wrong results. Use the pack's Qwen caption nodes' bbox mode and the format matches out of the box.

    Categoryimage/caption

    Inputs (4)

    NameTypeDefaultDescription
    stringSTRING
    widthINT10241–10000
    heightINT10241–10000
    indexSTRING

    Outputs (2)

    NameTypeDescription
    center_coordinatesSTRING
    bboxesBBOX