OCR Foundry
Synthetic OCR training data generator with legacy Khmer/English behavior and
opt-in multilingual whole-line rendering. Use ocr-foundry; existing khocr-gen
commands run the same CLI. The v0.2 distribution ocr-foundry installs both
executables. Python imports remain khocr_gen, and Rust and KHOCR_GEN_*
environment contracts are unchanged.
See branding and compatibility
for migration details. Repository links to https://github.com/0x1d1e/ocr-foundry
are valid now.
Installation
pip install ocr-foundry
pip install ocr-foundry is the v0.2 distribution. It provides both the
ocr-foundry and khocr-gen commands.
The PyPI project khocr-gen is deprecated. Release 0.2.0 contains no code and
depends on this package. khocr-gen==0.1.13 is the last standalone release.
If khocr-gen==0.1.13 is already installed, upgrade or remove it before
installing ocr-foundry, because both distributions would otherwise provide
the khocr-gen command.
The rust extra is not installable from PyPI because khocr-gen-core is not
published. Native use is a source checkout with uv sync --extra dev --extra rust.
Requirements
- Python >= 3.12
- Rust toolchain (
cargo/rustc, edition 2021) - only needed to build the optional acceleration extension
Quick Start
1. Prepare fonts
fonts/
├── khmer/ <- .ttf / .otf Khmer fonts
└── english/ <- .ttf / .otf English fonts
Fonts placed directly in fonts/ (not in a subdirectory) are added to both pools as fallbacks.
2. Prepare corpus
A plain UTF-8 text file, one string per line:
សួស្តី
Hello World
ស្វាគមន៍ Welcome
3. Generate a dataset
ocr-foundry generate --corpus corpus/corpus.txt --fonts fonts --output data --copies 3 --storage lmdb
4. View generated images
# Summary of an LMDB database
ocr-foundry view --lmdb data/train/lmdb
# Extract images
ocr-foundry view --lmdb data/train/lmdb --output-dir extracted
# Show labels only
ocr-foundry view --lmdb data/train/lmdb --labels-only
Multilingual mode and evaluation
--multilingual requires Pillow RAQM and renders horizontal logical Unicode lines using
one covering font by default, with opt-in cluster-aware font fallback (--cluster-font-fallback)
segmenting grapheme clusters, preserving combining marks and Khmer coeng sequences, and aligning
multi-run segments to a shared baseline. Labels retain normalized logical text without visual reordering.
Arbitrary recursive font pools, explicit NFC/no-normalization policies, and auto/ltr/rtl direction are supported.
JSONL manifests ingest rich metadata, emit provenance.jsonl sidecars, and record font hashes in metadata.jsonl.
The source recipe configs/multilingual-realistic.yml includes clean samples, disables rare oversampling
and foreground crops, and enables a measured line-ink height guard, with opt-in binary glyph-mask guards
(--min-glyph-height-for-augmentation) and script/font intensity scaling. Page layout composition
(ocr-foundry layout) adds opt-in whitespace word annotations, native RAQM vertical writing (words and
vertical modes requiring shared libraqm with linked FreeType), and paginated table hierarchy. Rendering
checks are not a universal language-quality claim; see the
capability matrix and
page layout contract.
ocr-foundry evaluate --reference reference.jsonl --predictions predictions.jsonl --normalization NFC
The offline evaluator reports corpus CER, exact-line accuracy and reference-language groups from ID-keyed JSONL. It downloads no model. See the schema and frozen real-document protocol and provenance/migration roadmap.
Configuration
All generation parameters can be specified via CLI flags, a YAML config file, or both (CLI overrides YAML). See CONFIG.md for details. Example: generate.yml
Config loading order (lowest to highest priority):
- argparse built-in defaults
- YAML config file values
- Explicit CLI flags
CLI Reference
See CLI_REFERENCE.md for complete command documentation.
Documentation
- Getting Started for a first dataset.
- GitHub wiki for usage guides and troubleshooting.
- In-repository references for the CLI, configuration, augmentation, and Rust extension.
Acknowledgments
OCR Foundry builds on these open-source libraries:
- khmernormalizer (MIT) - Khmer text normalization
- OpenCV (Apache 2.0) - Image processing and augmentation
- Pillow (HPND) - Font rendering and image creation
- Albumentations (MIT) - Augmentation primitives
- NumPy (BSD-3-Clause) - Numerical operations
- LMDB (OpenLDAP 2.8) - Embedded database for training pipelines
License
MIT
Metadata
Release files for ocr-foundry 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ocr_foundry-0.2.0.tar.gz | 405.0 kB | Without provenance | Details for ocr_foundry-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ocr_foundry-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ocr_foundry-0.2.0-py3-none-any.whl |
Total release size: 565.1 kB
Release files / ocr_foundry-0.2.0.tar.gz
| Download URL | ocr_foundry-0.2.0.tar.gz |
|---|---|
| Size | 405.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a077cf7408ac65e767f342cc09498ea9a82c2aa213d1a9f89a23431d584f3417
|
|
BLAKE2b-256 checksum How to use checksums |
a1f9de45fb6aef9adec645ed54a8fb5acd111a1dce90016c19cc1578f8badac9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ocr_foundry-0.2.0-py3-none-any.whl
| Download URL | ocr_foundry-0.2.0-py3-none-any.whl |
|---|---|
| Size | 160.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd2a86048d94c2d1357338cff7819fcacf0f2da5b832ed4f82f5c7fd272d2d27
|
|
BLAKE2b-256 checksum How to use checksums |
3d8b5f2781d4c7a8538c62aaa73de81217c04ad32222e191ccb4fd1f2818a27b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ocr-foundry 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.