OCR engines¶
TactiDiagram reads the printed labels on a diagram with one of three on-device OCR engines. They are tried in a fixed order, and the pipeline reports which one was used (the "ocrEngine" field in the analysis result, also visible in the browser console as an "OCR engine:" message):
- Indra OCR (Datalab, v1.1.0) - opt-in from the "Use Indra OCR" checkbox under Output options. Its preferred path uses the PaddleOCR detector and Indra recognizer; if detection fails, it tries Indra's own detector.
- PaddleOCR (PP-OCRv6 det + PP-OCRv5 English rec, RapidOCR's ONNX conversions) - the default.
- Tesseract.js - the last resort, used only if PaddleOCR itself could not run.
Each stage runs only when the previous one throws or finds no text at all. Selecting Indra changes the recognizer, not the downstream label-processing pipeline.
Using the Indra engine¶
- Prepare the model assets once:
npm ci
npm run vendor
The vendor script downloads the Indra ONNX detector, recognizer, and
character vocabulary into src/models/indra/ alongside the other models.
It is skipped if the files are already present.
- Start the app (
npm run serve, openhttp://localhost:5173). - Check Use Indra OCR under Output options. Changing the checkbox does not start anything; the engine is used the next time you press Start analysis. Leave it unchecked to keep PaddleOCR.
Because the engine change only affects label reading, leader detection, segmentation, layout, checking, and export behave identically either way.
PaddleOCR-guided Indra recognition¶
When Use Indra OCR is enabled, the preferred path combines the two model families by role rather than running two complete OCR engines:
- PaddleOCR's PP-OCRv6 detector locates text regions and returns rotated quadrilateral boxes in original-image coordinates.
- OpenCV perspective-warps each quadrilateral into a rectangular crop, correcting the detected skew while preserving the original region geometry.
- Indra's Latin recognizer reads those crops. The resulting text records use the same shared word/line format as the other OCR paths.
- The original quadrilateral remains attached to each recognized line for spatial traceability; downstream OCR filtering and label grouping continue to use the returned bounding boxes.
If PaddleOCR detection cannot load or run, the app tries Indra's own detector and recognizer. If the Indra path errors or returns no text, the existing PaddleOCR recognizer path runs, followed by Tesseract when PaddleOCR fails. PaddleOCR's recognizer is not run in the normal guided Indra path.
This is detection-guided recognition, not an ensemble or a vote between recognized strings. It adds PaddleOCR detector inference to the Indra path and still loads the Indra model bundle. Perspective correction addresses geometric skew in the detected crop; it does not guarantee correct reading orientation for upside-down, vertical, curved, or severely distorted text. The Indra port does not include the reference package's orientation classifier. These cases require targeted validation before claiming improved recognition.
flowchart TD
A["Source ImageData"] --> B{"Use Indra OCR?"}
B -->|No| P["PaddleOCR detector"]
P --> PR["PaddleOCR recognizer"]
B -->|Yes| D["PaddleOCR text detector"]
D --> Q["Rotated quadrilateral regions"]
Q --> W["Grayscale crop and resize to Indra input"]
W --> I["Indra CTC recognizer"]
I -.->|Any error or empty result| P
PR --> R["Shared OCR word records"]
I --> R
R --> S["Shared OCR filtering, grouping and label correction"]
P -.->|PaddleOCR error or no text| T["Tesseract fallback"]
S --> L["Leader detection and tactile pipeline"]
T --> S
Architecture of the JavaScript port¶
The port follows the same engine contract as the PaddleOCR module
(src/js/paddle.js): it consumes an ImageData, and returns word records
(text, conf, x0, y0, x1, y1, line) accepted unchanged by the
shared post-processing in src/js/ocr.js (filtering, line grouping, label
merging, vocabulary correction). Downstream stages cannot tell which engine
produced the words.
flowchart TD
A["PaddleOCR text regions"] --> B["Grayscale crop and normalize"]
B --> C["Create one-channel ink map"]
C --> D["Resize using rec_height and rec_window"]
D --> E["Pad variable-width batch to multiple of 8"]
E --> F["Recognizer inputs: x and widths"]
F --> G["CTC outputs: ids, conf, lengths"]
G --> H["Decode with meta.json vocabulary"]
H --> I["Convert recognized lines to word records"]
Roles of the vendored files:
| File | Role | Notes |
|---|---|---|
det.onnx (~390 KB) |
DB-style text detection: predicts a probability map of text regions | Post-processed by OpenCV into quadrilateral boxes (threshold, unclip, scale-back) |
rec.onnx (~5 MB) |
Latin script recognizer: CTC-style character sequence over a cropped text line | Run batched over all crops of the image |
meta.json (~212 KB) |
Character vocabulary (and, for the Python package, decoding metadata) | The JS port reads only the vocabulary and the optional blank index |
Everything runs on onnxruntime-web (WASM execution provider) using the same vendored bundle that SlimSAM and PaddleOCR use. No Python, no server, and no network access at run time: the checkbox only changes which locally stored ONNX files are loaded into the same pipeline.
The vendored Tesseract bundle is patched during npm run vendor: its one
Math.random() call (a non-cryptographic task-ID generator in the worker
scheduler) is rewritten to a deterministic counter, so the committed
src/vendor/tesseract/tesseract.esm.min.js carries no insecure-randomness
pattern for Code scanning. This does not change OCR behavior.
Where the port is deliberately conservative¶
The Python reference implementation (pip install indra-ocr) includes
components this port does not use, because they were ambiguous from the model
artifacts alone or clearly out of scope for a first integration:
- Input shape probing. The recognizer's expected tensor shape is not
documented in the model repository, so
src/js/indra.jsprobes a small set of candidate(batch, 3, H, W)shapes once at load time and caches the winner. If probing fails, the engine throws and the chain falls back. - Channel order. Whether the detector was trained on RGB or BGR input
cannot be read from the ONNX file. The choice is a named constant
(
DET_BGR) with instructions, not a silent guess. - Vocabulary parsing.
meta.jsonis written for the Python package; the loader accepts several plausible vocabulary layouts and fails loudly rather than decoding garbage. - Not ported: the multi-script recognizers (
rec_cjk.onnx,rec_rtl.onnx,rec_world.onnx), language-model rescoring (lm.npz), and the orientation and script classifiers (orient.onnx,script.onnx). Tilted pages, handwriting-heavy pages, and non-Latin scripts are better served by the default chain or the Python package; the fallback exists for exactly this reason.
Because of these omissions the checkbox is opt-in and off by default, and the result is treated as experimental until the validation below passes.
Validation methodology¶
Before relying on the checkbox for real transcription work:
- Run the sample diagrams through the reference implementation:
pip install indra-ocr # reference, pinned to a known version
indra-ocr src/samples/heart.png --format json
- Run the same diagram in the app with "Use Indra OCR" checked, and open the What the AI saw tab. Compare per-line text and boxes with the reference JSON.
- discrepancies in boxes usually indicate the DB post-processing
constants; discrepancies in text usually indicate the recognizer
normalization, shape probing, or vocabulary. The console timing record
(
detectTextIndra.lastTiming) reports detector and recognizer phases. - The evaluation harness (
npm run eval, Playwright) recordswindow.__touchsight.analysis.ocrEngine, so an engine-comparison run of the full benchmark is a small addition toscripts/eval.mjsand the right way to decide whether Indra measurably improves label recall on the samples before making it the default.
Licensing and redistribution¶
The models are downloaded from Datalab's official Hugging Face repository
(datalab-to/indra-ocr), pinned
to the v1.1.0 commit, with the repository LICENSE copied alongside
(src/models/indra/LICENSE). As with the other model assets, confirm that
the license keeps the weights redistributable in this GPL-3.0 project (and in
any derived distribution) before shipping builds that include them. If it
does not, delete the src/models/indra/ folder and uncheck the box: the
engine chain degrades gracefully to PaddleOCR, then Tesseract.
Related pages¶
- Models and inference engines for the full model inventory and the PaddleOCR/Tesseract details.
- Pipeline stages for what happens to the words after OCR.
- Evaluation and benchmarks for the harness used to compare engines.