Metadata-Version: 2.5
Name: khocr-gen
Version: 0.1.9
Summary: Synthetic OCR training data generator for mixed Khmer/English text
Project-URL: Homepage, https://github.com/LazyGreed/khocr-gen
Project-URL: Issues, https://github.com/LazyGreed/khocr-gen/issues
Project-URL: Changelog, https://github.com/LazyGreed/khocr-gen/blob/main/CHANGELOG.md
Author: Kosal Seng
License-Expression: MIT
License-File: LICENSE
Keywords: data-generation,image-generation,khmer,ocr,synthetic-data,text-recognition
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Python: >=3.12
Requires-Dist: albumentations>=1.3.0
Requires-Dist: khmernormalizer>=0.0.4
Requires-Dist: lmdb>=1.4.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: opencv-python-headless>=4.8.0
Requires-Dist: pillow>=10.0.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: tqdm>=4.64.0
Provides-Extra: dev
Requires-Dist: khocr-gen-core; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Requires-Dist: ty>=0.0.1a1; extra == 'dev'
Provides-Extra: rust
Requires-Dist: khocr-gen-core; extra == 'rust'
Description-Content-Type: text/markdown

# khocr-gen

Synthetic OCR training data generator for mixed Khmer/English text.

## Installation

```bash
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

```text
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:

```text
សួស្តី
Hello World
ស្វាគមន៍ Welcome
```

### 3. Generate a dataset

```bash
khocr-gen generate --corpus corpus/corpus.txt --fonts fonts --output data --copies 3 --storage lmdb
```

### 4. View generated images

```bash
# 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](https://github.com/LazyGreed/khocr-gen/blob/main/docs/CONFIG.md) for details.
Example: [generate.yml](https://github.com/LazyGreed/khocr-gen/blob/main/configs/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](https://github.com/LazyGreed/khocr-gen/blob/main/docs/CLI_REFERENCE.md) for complete command documentation.

## Acknowledgments

khocr-gen builds on excellent open-source libraries:

- [khmernormalizer](https://github.com/seanghay/khmernormalizer) (MIT) - Khmer text normalization
- [OpenCV](https://opencv.org/) (Apache 2.0) - Image processing and augmentation
- [Pillow](https://python-pillow.org/) (HPND) - Font rendering and image creation
- [Albumentations](https://albumentations.ai/) (MIT) - Augmentation primitives
- [NumPy](https://numpy.org/) (BSD-3-Clause) - Numerical operations
- [LMDB](https://www.symas.com/lmdb) (OpenLDAP 2.8) - Embedded database for training pipelines

## License

MIT
