Skip to main content

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):

  1. argparse built-in defaults
  2. YAML config file values
  3. 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.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for khocr-gen 0.1.6
File Size Uploaded
khocr_gen-0.1.6.tar.gz 125.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for khocr-gen 0.1.6
File Interpreter ABI Platform
khocr_gen-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 196.8 kB

Release files / khocr_gen-0.1.6.tar.gz

Download URL khocr_gen-0.1.6.tar.gz
Size 125.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8ef844423d0e70772f4b5c97f52cfefdf45abcf56b2cc6529b8578274d0dca1e
BLAKE2b-256 checksum
How to use checksums
26480bd310664fc5c7c33634f219d5b891b6c17f207e9c3e98a0df2419d3cfbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.6-py3-none-any.whl

Download URL khocr_gen-0.1.6-py3-none-any.whl
Size 70.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aae513ff95754e44bcf8b3c83b2080fd54ad09fe8938f2419b14b73cbbdbb500
BLAKE2b-256 checksum
How to use checksums
aea2cdad736290935e5b7010c759c293aaed9dd42758642c7b7069537bc2d23d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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 history Release notifications | RSS feed

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

This release

0.1.6 This release

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page