OCR Foundry
Synthetic OCR training data generator with legacy Khmer/English behavior and
opt-in multilingual whole-line rendering. It provides the ocr-foundry CLI,
the ocr_foundry Python package, optional ocr-foundry-core Rust acceleration,
and the OCR_FOUNDRY_* environment namespace.
See branding
for package and contract details. Repository links point to
https://github.com/0x1d1e/ocr-foundry.
Installation
pip install ocr-foundry
pip install ocr-foundry installs the ocr-foundry CLI and ocr_foundry Python package.
The rust extra is not installable from PyPI because ocr-foundry-core is not
published on PyPI. 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 - Node.js + Playwright Chromium - optional, only needed for server-side 66-template Document Synthesis in
ocr-foundry web
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
5. Launch the Web UI (OCR Foundry Studio)
ocr-foundry web --workspace ./output --open
The built-in studio provides the Line & Verify Lab, Layout Composer, LMDB/Combine/Eval/Benchmark suite, Three.js 3D Capture Lab, and 31-band Spectrify Physics Lab out of the box. Server-side 66-template Document Synthesis activates automatically when Node.js, web/ dependencies, and Playwright Chromium are available (--doc-synth-dir ./web). See WEB_UI.md.
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.2
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.2.tar.gz | 2.6 MB | Without provenance | Details for ocr_foundry-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ocr_foundry-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for ocr_foundry-0.2.2-py3-none-any.whl |
Total release size: 4.8 MB
Release files / ocr_foundry-0.2.2.tar.gz
| Download URL | ocr_foundry-0.2.2.tar.gz |
|---|---|
| Size | 2.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7b2082f497c36071d83ada07f4d50c63ac1ab98b954c9b08aad4f6acdeace82
|
|
BLAKE2b-256 checksum How to use checksums |
762f52ff5dbbc10f294feae6bb106276a8a125dba0ded1d2fa1c150036e32585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.2-py3-none-any.whl
| Download URL | ocr_foundry-0.2.2-py3-none-any.whl |
|---|---|
| Size | 2.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
271b62a38ebdb07333a3454c0a1787ea74f1b176f2158394ac4b7044a2b1fd7a
|
|
BLAKE2b-256 checksum How to use checksums |
f52f0363d9e6c28d6f4d4682808bd83ba3b7b3c3be4af9c7b265feb231dc06cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.2
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.