Repository navigation
Home
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)
# 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_outputNew here? Start with Getting Started.
| 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.
| 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
|
| 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 |
- Repository: https://github.com/0x1d1e/ocr-foundry
- Issues: https://github.com/0x1d1e/ocr-foundry/issues
- PyPI: https://pypi.org/project/ocr-foundry/
- Changelog: CHANGELOG.md
- 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
MIT. See LICENSE.
OCR Foundry — synthetic OCR training data with Khmer/English and opt-in multilingual rendering · MIT · Repository · Issues · PyPI · Changelog
Using OCR Foundry
Data controls
- Corpus and Normalization
- Fonts
- Variable Line Height
- Text Decorations and Effects
- Augmentation
- Output and Storage
- Page Layout
Internals
Help