Nodes/Vevor Mask Union/Surya JSON → OCR JSON (after PDF-Tools)
ComfyUI Node

Surya JSON → OCR JSON (after PDF-Tools)

Your Surya OCR Is Fine — Its Output Just Doesn't Fit The Rest Of The Graph

By rexqin·Created about a month ago·Updated 19 days ago· 0
Surya JSON → OCR JSON (after PDF-Tools)
  • image
  • ocr_json
  • mask
◄full_data_json—►

Here's a familiar shape of problem. You found an OCR node you like - Surya through the PDF-Tools nodes, in this case - it works, it's accurate, and its output format is nobody else's. The next node in your pipeline wants a labelme document and a mask batch and has no idea what a text_lines array is.

VevorSuryaJsonToOcrJson is a pure adapter. It takes Surya's full_data_json string and emits the exact same two outputs the pack's own OCR nodes emit: labelme JSON plus a per-region mask batch. No OCR happens inside it. It's a format translator, and it's the sort of node that saves you writing forty lines of Python in a Script node every single time.

How the conversion actually works

The mechanism is worth knowing because it explains every quirk.

The node takes your image - used only for its width and height, and only frame 0 - and json.loads your full_data_json. It then walks data["ocr"], a list of pages, and inside each page the text_lines list. For every line with non-empty text it takes a box: bbox if present, otherwise the min/max of the polygon corners. That box plus the text becomes one region.

Then each region becomes a labelme shapes entry - a rectangle with points: [[x1, y1], [x2, y2]] and a label of the form text:0.9000 - and one frame of the mask batch, a filled rectangle in that box, clipped to the image bounds.

Two consequences fall straight out of that code:

Every region gets score 0.9. Surya's confidence, if it's in the payload at all, is thrown away. The 0.9 is hardcoded on purpose - it means "trust this, downstream" - but it also means any confidence filter you build later is filtering a constant. If you need real scores, do that before this node.

Coordinates are taken as-is, in pixels. Whatever resolution Surya saw the page at is what you must feed as image. Render a PDF page at 300 dpi for Surya and pass a 1024-px-wide ComfyUI image and every box lands in the wrong place, usually clustered at the top-left. The width/height are only used for the labelme header and for clipping the mask.

Inputs and outputs

  • image - IMAGE. Supplies canvas dimensions. Frame 0 only.
  • full_data_json - STRING, and it's marked as a connect-only input, so you can't paste JSON into it. Wire it from the Surya node's full_data_json output and nowhere else. That's a deliberate choice: the payload is far too long to hand-edit.

Outputs are ocr_json (labelme, one document in a list) and mask ((N, H, W), one rectangle per text line). The mask goes through VevorMaskBatchUnion before any composite; the JSON goes into VevorOcrGuard or VevorTextRender.

Full wiring, as the author describes it:

SuryaOCRLayout (PDF-Tools) full_data_json → VevorSuryaJsonToOcrJson → VevorMaskBatchUnion → ...

Install

The adapter itself ships with the pack - ComfyUI Manager, search Vevor Mask Union, or:

cd ComfyUI/custom_nodes
git clone https://github.com/rexqin/comfyui-vevor-mask-union
# restart ComfyUI

Nothing to download, no extra pip steps; the pack declares no Python dependencies and this node only needs json, numpy and torch. Surya's own model weights are the PDF-Tools pack's problem, not this one's.

Where people get burned

A failed Surya pass produces an empty result, not an error. If the payload carries an error key the node raises it properly, which is good. But a payload with an empty ocr list - or text_lines that all came back blank - gives you a mask batch of shape (0, H, W). VevorMaskBatchUnion passes empty batches straight through by design, so nothing complains, nothing composites, and your image comes out unchanged. When a run does nothing, check the region count before you touch the sampler.

One page at a time. The labelme side only ever writes a single document, and the mask batch has one canvas height and width. Multi-page PDFs give you every page's lines stacked into one mask on one canvas. Convert per page, and render that page as your image.

No text cleanup. Hyphenation, running headers, page numbers, the same disclaimer three times - all of it comes through as regions. That's what VevorOcrGuard is for.

If Surya is your OCR engine of choice - and for dense spec-sheet or PDF-sourced artwork it often is - this is the cheapest possible bridge into a mask-and-JSON pipeline. Small node, no opinions, does exactly one thing.

Categoryvevor/ocr

Inputs (2)

NameTypeDefaultDescription
imageIMAGE—
full_data_jsonSTRING—

Outputs (2)

NameTypeDescription
ocr_jsonJSON—
maskMASK—