khocr-gen
Synthetic OCR training data generator for mixed Khmer/English text.
Installation
pip install khocr-gen
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
khocr-gen generate --corpus corpus/corpus.txt --fonts fonts --output data --copies 3 --storage lmdb
4. View generated images
# Summary of an LMDB database
khocr-gen view --lmdb data/train/lmdb
# Extract images
khocr-gen view --lmdb data/train/lmdb --output-dir extracted
# Show labels only
khocr-gen view --lmdb data/train/lmdb --labels-only
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 (highest priority wins):
- argparse built-in defaults
- YAML config file values
- Explicit CLI flags
CLI Reference
See CLI_REFERENCE.md for complete command documentation.
Acknowledgments
khocr-gen builds on excellent 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 khocr-gen 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| khocr_gen-0.1.9.tar.gz | 136.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| khocr_gen-0.1.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 212.8 kB
Release files / khocr_gen-0.1.9.tar.gz
| Download URL | khocr_gen-0.1.9.tar.gz |
|---|---|
| Size | 136.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0002f9fa66370f6e570c612d87c9b8c1307e3658b9d0716d5b78e7fc4982e175
|
|
BLAKE2b-256 checksum How to use checksums |
96cbdd863902919f42f2d49518adbf0cca5edd8f679486feebb0993b67228aa4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / khocr_gen-0.1.9-py3-none-any.whl
| Download URL | khocr_gen-0.1.9-py3-none-any.whl |
|---|---|
| Size | 76.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2216b0c44bdf6c523cca47b1f1ed07a2b87bb2ee165e9b4aa5148ab3e241fcb8
|
|
BLAKE2b-256 checksum How to use checksums |
9225d83b42b06defea5a9d360f6eab8e7451fe39165e96bcf3084d485d101027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|