Manual ROI OCR — Public Documentation

v0.5 User manual · Tools · Methods · Logic Live app: earthlab.space/roi-ocr App: earthlab.space/roi-ocr Listing: earthlab.space/public/documentation

1. User manual

What this app does

Upload a form or label image (PNG/JPG), draw rectangles over text regions, and OCR fills a 6-field data grid. All recognition runs in your browser; images are not sent to a server for OCR.

Quick start

  1. Upload an image in the workspace.
  2. Turn Draw mode: ON and draw a box around each value you need.
  3. Click a grid field (F1–F6) to set the active target for new OCR results.
  4. Set each field’s constraint (default: Instrument code for values like STA.PP3, BT24).
  5. Choose Printed or Handwriting OCR as needed.
  6. Optionally enable Line detect and TTA vote for harder images.
  7. Export CSV or Export XLSX when finished.

Text modes

ModeBehavior
Continuous text Each ROI appends into the active field. Multi-line boxes may be joined with spaces when line detect splits them.
Separate word/number Each text line gets its own row in the active field. Tall boxes can span several lines; use Line detect or automatic row splitting.

Auto OCR vs manual

SettingBehavior
Auto OCR: ON After you draw a new box, OCR runs automatically (one box at a time, queued).
Auto OCR: OFF Draw boxes, then use the control on each box to run OCR.

Grid and data

Recommended settings

TaskSuggested settings
Typed instrument codesPrinted, Instrument code constraint, TTA ON if misreads persist
Numbers onlyNumeric constraint
Mixed codesAlphanumeric constraint
Free notesFree text constraint + Text cleanup ON
Handwritten labelsHandwriting (TrOCR, ~63 MB on first use)
Tall box, several printed linesLine detect ON + Separate mode

Export

CSV and XLSX export the grid: one row per line index, columns F1–F6.

2. Tools reference

Toolbar controls and grid options available in the live app.

ToolPurpose
Draw modeON: draw and edit ROI boxes. OFF: pan/zoom without creating boxes.
Auto OCRRun recognition when a new ROI is created.
Continuous / SeparateHow results map to grid rows (see User manual).
PrintedPP-OCRv4 English — typed and printed text.
HandwritingTrOCR small handwritten model (lazy-loaded).
Line detectPP-OCR DB splits multi-line ROIs before recognition. Disabled if det model is missing.
TTA voteMultiple preprocess variants per box; picks best by confidence. Slower, often more accurate.
Text cleanupSpacing and light corrections for free-text fields only.
Export CSV / XLSXDownload grid data.
Field constraint (grid dropdown)Limits allowed characters during decode and post-process.
→ on ROIManual OCR when Auto OCR is OFF.
Upload / Clear imageWorkspace image controls.

The toolbar hint line shows the active field (F1–F6), its constraint, OCR engine, and whether Line detect / TTA are active.

3. Methods

OCR engines, preprocessing, and accuracy techniques used under the hood (all client-side).

Recognition engines

EngineModelBest for
Printeden_PP-OCRv4_rec.onnx + dictionaryEnglish printed text, forms, instrument codes
HandwritingTrOCR small handwritten ONNXHandwritten English
Line detecten_PP-OCRv3_det.onnxFinding text lines inside a large ROI

Preprocessing (printed)

  1. Ink bbox trim — remove empty margins, add white padding.
  2. Enhancement — optional binarization (Sauvola/Otsu) and deskew by OCR profile.
  3. Resize — height 48 px, variable width; pad with 0 for the ONNX input tensor.

Line segmentation

With Line detect ON, the DB detector finds text boxes in the ROI, sorts them, and crops each line. If detection fails, ink projection fallback splits lines. Each line is recognized separately; results merge according to text mode.

Character constraints

ConstraintTypical use
Instrument codeLetters, digits, ., -, space — e.g. STA.PP3, PZ 62
AlphanumericLetters and digits
NumericDigits and decimal separators
Free textFull dictionary; pair with Text cleanup

Test-time augmentation (TTA)

When enabled, ~4 image variants are recognized per box; the worker selects the best result by confidence and agreement.

Decoding and confidence

Runtime

4. Logic

How data moves from image upload to grid export.

Pipeline

Upload image → Draw ROI on canvas (stored in canvas + native image coordinates) → Snip pixels from source image at native resolution → [Optional] Segment into lines (DB detector or ink projection) → Preprocess → ONNX inference (PP-OCR or TrOCR) → [Optional] TTA vote across variants → Constraint post-process + optional text cleanup → Assign to grid field / row → Export CSV or XLSX

Coordinates

ROI rectangles live in canvas space and are mapped to native image pixels before cropping. Snips always use the original upload resolution, not the zoomed display size.

Grid assignment

OCR queue

New boxes are processed one at a time in a promise queue so the worker stays stable and row order stays predictable.

Worker messages

MessageRole
INITLoad PP-OCR recognition (+ optional detection) models
INIT_TROCRLazy-load TrOCR encoder and decoder
DETECT_LINESRun DB detector on a snip
RUN_OCRRecognize one patch (printed or handwriting, optional TTA + constraint)

UI layout

┌─────────────────────────────────────────────────────────────┐ │ Header — title, ROI count, OCR engine status │ ├─────────────────────────────────────────────────────────────┤ │ Toolbar — draw, auto OCR, text mode, engines, line/TTA, export│ ├──────────────────────┬──────────────────────────────────────┤ │ Data grid (6 fields) │ Image workspace — upload, draw ROIs │ │ Quick manual │ │ ├──────────────────────┴──────────────────────────────────────┤ │ Footer — version, documentation link │ └─────────────────────────────────────────────────────────────┘

5. Privacy and limits