RapidOCR JSON Polygon To Mask
RapidOCR polygons straight to a ComfyUI mask
- image
- mask
RapidOCR hands back polygons, not just boxes - each text region as a four-point quad that follows the actual skew of the text. This node rasterizes those polygons into a proper ComfyUI MASK, so your mask hugs the glyphs instead of the enclosing rectangle. If you're masking angled or rotated text, that's the difference between a clean inpaint and one that bleeds over the surrounding pixels.
It's the mask-making end of the pack's RapidOCR polygon family: RapidOCR Detect Text (or any tool) produces JSON with polygon per detection, and this turns that JSON into a mask. Coordinates are pixels by default - the coord_base default here is 0, unlike the DeepSeek nodes' 1000 - because RapidOCR output is already in source-image pixels.
How it works
The node accepts a top-level detection list or a nested RapidOCR wrapper with detections plus batch metadata. Each item needs a polygon (a list of [x, y] points); a compatible points key is also accepted. It fills each polygon interior to 1 on a float32 [batch, height, width] mask, 0 elsewhere, in ComfyUI's standard format - ready for VAE Encode (for Inpainting).
Dimensions can come from three places, in this order of convenience: the optional image input, width/height metadata inside the JSON wrapper, or the image_width/image_height fields. If none are set, the node errors rather than guessing, which is a genuinely helpful failure mode.
Inputs
json_data- the detection JSON, from a STRING socket.image_width/image_height- leave both0if you connectimageor the JSON carries dimensions.coord_base-0for pixels (the default). Only touch it if your JSON uses a normalized base.invert_mask- flips selected/unselected.image(optional) - supplies width, height, and batch size; pixels are not modified or returned.
Output: the single mask.
Installing
Part of comfyui-dsocr-bbox. ComfyUI Manager (search "dsocr") or:
cd ComfyUI/custom_nodes
git clone https://github.com/maomaozi/comfyui-dsocr-bbox
restart, then install the pack's one dependency if the RapidOCR nodes will be used:
pip install -r custom_nodes/comfyui-dsocr-bbox/requirements.txt
Mask rasterization itself is pure geometry, but the JSON usually comes from the pack's RapidOCR nodes, which need that package.
Gotchas
The most common stumble is feeding in JSON that isn't quite the expected shape - items without a polygon key are silently skipped, so a mask with missing regions usually means a shape mismatch, not a detection miss. And keep an eye on the coord_base: everything else in the RapidOCR family defaults to pixels, so if you copied a coord_base=1000 habit from the DeepSeek nodes over here, your polygons will render as a dot in the corner.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| json_data | STRING | — | |
| image_width | INT | 00–100000 | — |
| image_height | INT | 00–100000 | — |
| coord_base | INT | 00–100000 | — |
| invert_mask | BOOLEAN | false | — |
| imageopt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |