Skip to content
LazyGreed edited this page Nov 11, 2026 · 4 revisions

OCR Foundry

PyPI License: MIT

Synthetic OCR training data with Khmer/English and opt-in multilingual rendering.

Use ocr-foundry for new commands. Existing khocr-gen commands use the same CLI; the v0.2 ocr-foundry distribution installs both executables and keeps khocr_gen Python imports. v0.2.0 is the ocr-foundry release, and khocr-gen on PyPI is the deprecated redirect. See branding and compatibility for the technical identities and version output.

khocr-gen 0.2.0 contains no code and depends on ocr-foundry. khocr-gen==0.1.13 is the last standalone release. If 0.1.13 is installed, upgrade or remove it before installing ocr-foundry, because both distributions would otherwise provide the khocr-gen command. See the v0.2 release plan.

OCR Foundry renders corpus lines onto canvases with per-span font selection, variable heights and optional text effects. Generation selects at most one augmentation from a 27-method registry per image; the calibrated multilingual recipe also emits clean samples. Raw images, LMDB, or both can be written.

UTF-8 corpus                                                       training data
text lines  ──▶  font selection ──▶  render ──▶  decorate/effect ──▶  ≤1 augmentation ──▶  images + labels.txt (+ LMDB)
                  (Khmer/English)     (clean     (per line,          (27 methods,
                                       canvas)     optional)          isolated)

Quick start

# 1. Install
pip install ocr-foundry

# 2. Lay out fonts and a corpus
#    fonts/khmer/*.ttf     fonts/english/*.ttf
#    corpus/corpus.txt     (one UTF-8 string per line)

# 3. Generate
ocr-foundry generate --corpus corpus/corpus.txt --fonts fonts --output data --copies 3 --storage lmdb

# 4. Inspect what you built
ocr-foundry view --lmdb data/train/lmdb --summary

# 5. Eyeball the augmentations
ocr-foundry verify --fonts fonts --output verify_output

New here? Start with Getting Started.

Feature overview

Area What you get
Rendering Mixed-script (Khmer + English) line rendering with per-span font selection
Fonts khmer/ and english/ font pools, real bold/italic variant detection, glyph-coverage checks
Variable line height fixed / variable / bucketed canvas heights with proportional font sizing and random padding; glyphs are never clipped
Text decorations Per-line color, underline, subscript/superscript, italic, bold; combinable
Text effects Canva-style huge/tiny, transparent, shadow, glow, outline, hollow, echo, background, neon, glitch, pixel; mutually exclusive
Backgrounds 6 colour palettes (paper tones, pastels, dark mode, gradient, random) and 8 procedural paper textures
Augmentation 27 methods in one registry, one effect per image, configurable [min, max] intensity
Rust acceleration 21/27 augmentation methods plus font glyph checking via a native PyO3 extension, with pure-Python fallback
Throughput Multiprocess generation with auto worker/chunk sizing
Storage Raw images, LMDB, or both; n-way dataset merging with combine
Text handling Khmer normalization, filtering by length, rare-character oversampling, seeded splitting and per-sample rendering

With a fixed corpus, fonts, configuration and runtime, generate --seed 42 (the default) seeds per-sample rendering and augmentation independently of worker count. Seeded augmentation uses Python methods in place of native Rust. See Configuration for the calibrated multilingual recipe and Corpus and Normalization for split and seed limits.

benchmark is an offline scorer, not a recognizer. The tracked real_doc_v1 suite has 103 reference lines from six declared documents (one digital render) and a Tesseract prediction baseline; its crop paths contain placeholder bytes, not usable images. A separate Model Version 6 experiment reported results on 757 real crops with a pretrained-model baseline. See Evaluation for commands and the distinction between cohorts.

Documentation map

Using it

Page Contents
Getting Started Install → fonts → corpus → first dataset, end to end
Installation PyPI, source, uv, Rust toolchain, optional extras
CLI Reference Commands and flags: generate, combine, layout, verify, view, evaluate, benchmark
Evaluation Offline scoring, tracked benchmark lock, and the separate Model Version 6 report
Configuration YAML recipes, precedence rules, full key reference
Corpus and Normalization Corpus format, filtering, splits, rare-character oversampling
Fonts Directory layout, script selection, bold/italic variants, coverage checks
Variable Line Height Height modes, proportional font sizing, padding, metadata sidecar
Text Decorations and Effects All --text-deco-* and --text-effect-* options
Augmentation The 27 methods, selection rules, intensity → physical-unit mapping
Output and Storage Dataset layout, labels.txt, vocab.json, metadata.jsonl, LMDB, combine

Understanding and extending it

Page Contents
Architecture Module map, generation pipeline, parallelism model
Rust Acceleration What is accelerated, how the extension is built, how to iterate on rust/
Page Layout Document pages, tables, transforms and geometry annotations
Development Dev setup, lint/test/type-check, CI, releasing
FAQ Common questions answered briefly
Troubleshooting Symptom → cause → fix

Project links

Requirements

  • Python ≥ 3.12
  • Rust toolchain (cargo / rustc, edition 2021), only to build the optional acceleration extension
  • No GPU required; generation is CPU-bound image work

License

MIT. See LICENSE.

Clone this wiki locally