OCR Location Node
Where exactly is the text? Ask Baidu, then erase it there
- image
- image
- merged_rectangles
- original_rectangles
Before you can erase text you have to know where it is, and that's the whole job of OCR Location Node. It sends your image to Baidu's cloud OCR, gets back per-word bounding boxes, merges nearby ones into readable chunks, and hands you a picture with labeled boxes plus the box data as JSON. It's the "find" half of this pack's find → erase → rewrite pipeline.
Like its sibling Image Erase Node, this one is a cloud call, not a local model. It doesn't care about your VRAM because it doesn't use it. What it does care about is a Baidu AI access token and a working internet connection.
How it works
The node JPEG-encodes your image, base64-encodes it, and POSTs it to Baidu's webimage_loc endpoint (network image OCR with location). Baidu replies with a list of recognized words, each carrying a box in left / top / width / height. The node then runs a merge pass: boxes that overlap and sit close on the same baseline get fused into one bigger box, so a whole line of text becomes a single region instead of a dozen word boxes. Small boxes under a minimum area are dropped.
Finally it draws blue rectangles and white label chips with a red letter on each one - A, B, C, … in reading order - and returns the annotated image alongside the raw data.
Inputs and outputs
Just two inputs: image and access_token. Yes, same token story as the rest of the pack - the default field is a Chinese placeholder, not a real token, and Baidu tokens expire after roughly 30 days. Get a fresh one from the Baidu AI platform console.
The three outputs:
- image - your original with the detected boxes drawn on. This is a preview, not the final product.
- merged_rectangles - JSON list of
{"id": "A", "left": ..., "top": ..., "width": ..., "height": ...}. This is the useful one: it plugs straight into Chat Overlay Node, and the letter ids become the keys for your replacement text ({"A": "New text"}). - original_rectangles - the same boxes, unmerged, as plain
[x, y, w, h]arrays.
Here's the seam nobody warns you about: merged_rectangles does not plug into Image Erase Node, which expects bare [x, y, w, h] arrays rather than dicts. If you want the full auto pipeline you'll transform the JSON (or just read the letters and type the boxes - fine for a handful of regions).
Install and troubleshooting
ComfyUI Manager → search ComfyUI-text-replace, or:
cd ComfyUI/custom_nodes
git clone https://github.com/banqingyuan/ComfyUI-text-replace
Then restart. No model downloads; the dependency list is mostly already-installed stuff (requests, opencv, numpy, Pillow).
If OCR fails, the node prints OCR识别失败 in the console and hands back the original image with two empty JSON arrays - so an empty merged_rectangles means the call failed, not that there's no text. Check your token expiry first, then Baidu's free-tier quota, which burns surprisingly fast on busy images.
One honest caveat: Baidu's OCR is trained primarily for clean Chinese and English text. Straight-on photos of signs and screenshots come back great; stylized comic lettering and low-contrast text will come back missing pieces. For those, you're better off drawing the boxes yourself or using a whole-image edit model.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| access_token | STRING | 请输入您的百度AI平台access token | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| merged_rectangles | STRING | — |
| original_rectangles | STRING | — |