ocr-foundry 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- khocr_gen/__init__.py +11 -0
- khocr_gen/_pil_compat.py +25 -0
- khocr_gen/_rust_accel.py +204 -0
- khocr_gen/augmentation.py +1193 -0
- khocr_gen/benchmark.py +888 -0
- khocr_gen/benchmark_cmd.py +103 -0
- khocr_gen/cli.py +246 -0
- khocr_gen/combine.py +214 -0
- khocr_gen/combine_cmd.py +125 -0
- khocr_gen/config.py +1474 -0
- khocr_gen/config_loader.py +157 -0
- khocr_gen/corpus.py +621 -0
- khocr_gen/data_generator.py +1160 -0
- khocr_gen/errors.py +33 -0
- khocr_gen/evaluate_cmd.py +50 -0
- khocr_gen/evaluation.py +259 -0
- khocr_gen/fonts.py +316 -0
- khocr_gen/generate.py +227 -0
- khocr_gen/layout.py +1028 -0
- khocr_gen/layout_cmd.py +371 -0
- khocr_gen/layout_degradation.py +128 -0
- khocr_gen/layout_mesh.py +200 -0
- khocr_gen/layout_shaping.py +264 -0
- khocr_gen/layout_transform.py +238 -0
- khocr_gen/layout_warp.py +473 -0
- khocr_gen/line_height.py +127 -0
- khocr_gen/lmdb_pack.py +132 -0
- khocr_gen/logging.py +25 -0
- khocr_gen/normalizer.py +221 -0
- khocr_gen/parallel.py +366 -0
- khocr_gen/provenance.py +328 -0
- khocr_gen/rendering.py +1607 -0
- khocr_gen/text_support.py +429 -0
- khocr_gen/verify.py +471 -0
- khocr_gen/viewer.py +172 -0
- ocr_foundry-0.2.0.dist-info/METADATA +174 -0
- ocr_foundry-0.2.0.dist-info/RECORD +40 -0
- ocr_foundry-0.2.0.dist-info/WHEEL +4 -0
- ocr_foundry-0.2.0.dist-info/entry_points.txt +3 -0
- ocr_foundry-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ocr-foundry
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: OCR Foundry - synthetic OCR training data with Khmer/English and opt-in multilingual rendering
|
|
5
|
+
Project-URL: Homepage, https://github.com/0x1d1e/ocr-foundry
|
|
6
|
+
Project-URL: Issues, https://github.com/0x1d1e/ocr-foundry/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/0x1d1e/ocr-foundry/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Kosal Seng
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: data-generation,image-generation,khmer,ocr,synthetic-data,text-recognition
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Requires-Dist: albumentations>=1.3.0
|
|
18
|
+
Requires-Dist: fonttools>=4.0.0
|
|
19
|
+
Requires-Dist: khmernormalizer>=0.0.4
|
|
20
|
+
Requires-Dist: lmdb>=1.4.0
|
|
21
|
+
Requires-Dist: numpy>=1.24.0
|
|
22
|
+
Requires-Dist: opencv-python-headless>=4.8.0
|
|
23
|
+
Requires-Dist: pillow>=10.0.0
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Requires-Dist: regex>=2023.0.0
|
|
26
|
+
Requires-Dist: tqdm>=4.64.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ty>=0.0.1a1; extra == 'dev'
|
|
32
|
+
Provides-Extra: rust
|
|
33
|
+
Requires-Dist: khocr-gen-core; extra == 'rust'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# OCR Foundry
|
|
37
|
+
|
|
38
|
+
Synthetic OCR training data generator with legacy Khmer/English behavior and
|
|
39
|
+
opt-in multilingual whole-line rendering. Use `ocr-foundry`; existing `khocr-gen`
|
|
40
|
+
commands run the same CLI. The v0.2 distribution `ocr-foundry` installs both
|
|
41
|
+
executables. Python imports remain `khocr_gen`, and Rust and `KHOCR_GEN_*`
|
|
42
|
+
environment contracts are unchanged.
|
|
43
|
+
|
|
44
|
+
See [branding and compatibility](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/BRANDING.md)
|
|
45
|
+
for migration details. Repository links to `https://github.com/0x1d1e/ocr-foundry`
|
|
46
|
+
are valid now.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install ocr-foundry
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`pip install ocr-foundry` is the v0.2 distribution. It provides both the
|
|
55
|
+
`ocr-foundry` and `khocr-gen` commands.
|
|
56
|
+
|
|
57
|
+
The PyPI project `khocr-gen` is deprecated. Release 0.2.0 contains no code and
|
|
58
|
+
depends on this package. `khocr-gen==0.1.13` is the last standalone release.
|
|
59
|
+
If `khocr-gen==0.1.13` is already installed, upgrade or remove it before
|
|
60
|
+
installing `ocr-foundry`, because both distributions would otherwise provide
|
|
61
|
+
the `khocr-gen` command.
|
|
62
|
+
|
|
63
|
+
The `rust` extra is not installable from PyPI because `khocr-gen-core` is not
|
|
64
|
+
published. Native use is a source checkout with `uv sync --extra dev --extra rust`.
|
|
65
|
+
|
|
66
|
+
### Requirements
|
|
67
|
+
|
|
68
|
+
- Python >= 3.12
|
|
69
|
+
- Rust toolchain (`cargo`/`rustc`, edition 2021) - only needed to build the optional acceleration extension
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
### 1. Prepare fonts
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
fonts/
|
|
77
|
+
├── khmer/ <- .ttf / .otf Khmer fonts
|
|
78
|
+
└── english/ <- .ttf / .otf English fonts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Fonts placed directly in `fonts/` (not in a subdirectory) are added to both pools as fallbacks.
|
|
82
|
+
|
|
83
|
+
### 2. Prepare corpus
|
|
84
|
+
|
|
85
|
+
A plain UTF-8 text file, one string per line:
|
|
86
|
+
|
|
87
|
+
```text
|
|
88
|
+
សួស្តី
|
|
89
|
+
Hello World
|
|
90
|
+
ស្វាគមន៍ Welcome
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 3. Generate a dataset
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
ocr-foundry generate --corpus corpus/corpus.txt --fonts fonts --output data --copies 3 --storage lmdb
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 4. View generated images
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Summary of an LMDB database
|
|
103
|
+
ocr-foundry view --lmdb data/train/lmdb
|
|
104
|
+
|
|
105
|
+
# Extract images
|
|
106
|
+
ocr-foundry view --lmdb data/train/lmdb --output-dir extracted
|
|
107
|
+
|
|
108
|
+
# Show labels only
|
|
109
|
+
ocr-foundry view --lmdb data/train/lmdb --labels-only
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Multilingual mode and evaluation
|
|
113
|
+
|
|
114
|
+
`--multilingual` requires Pillow RAQM and renders horizontal logical Unicode lines using
|
|
115
|
+
one covering font by default, with opt-in cluster-aware font fallback (`--cluster-font-fallback`)
|
|
116
|
+
segmenting grapheme clusters, preserving combining marks and Khmer coeng sequences, and aligning
|
|
117
|
+
multi-run segments to a shared baseline. Labels retain normalized logical text without visual reordering.
|
|
118
|
+
Arbitrary recursive font pools, explicit NFC/no-normalization policies, and auto/ltr/rtl direction are supported.
|
|
119
|
+
JSONL manifests ingest rich metadata, emit `provenance.jsonl` sidecars, and record font hashes in `metadata.jsonl`.
|
|
120
|
+
|
|
121
|
+
The source recipe `configs/multilingual-realistic.yml` includes clean samples, disables rare oversampling
|
|
122
|
+
and foreground crops, and enables a measured line-ink height guard, with opt-in binary glyph-mask guards
|
|
123
|
+
(`--min-glyph-height-for-augmentation`) and script/font intensity scaling. Page layout composition
|
|
124
|
+
(`ocr-foundry layout`) adds opt-in whitespace word annotations, native RAQM vertical writing (words and
|
|
125
|
+
vertical modes requiring shared libraqm with linked FreeType), and paginated table hierarchy. Rendering
|
|
126
|
+
checks are not a universal language-quality claim; see the
|
|
127
|
+
[capability matrix](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/MULTILINGUAL.md) and
|
|
128
|
+
[page layout contract](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/PAGE_LAYOUT.md).
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
ocr-foundry evaluate --reference reference.jsonl --predictions predictions.jsonl --normalization NFC
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The offline evaluator reports corpus CER, exact-line accuracy and reference-language
|
|
135
|
+
groups from ID-keyed JSONL. It downloads no model. See the
|
|
136
|
+
[schema and frozen real-document protocol](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/EVALUATION.md)
|
|
137
|
+
and [provenance/migration roadmap](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/MULTILINGUAL_ROADMAP.md).
|
|
138
|
+
|
|
139
|
+
## Configuration
|
|
140
|
+
|
|
141
|
+
All generation parameters can be specified via CLI flags, a YAML config file, or both (CLI overrides YAML).
|
|
142
|
+
See [CONFIG.md](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/CONFIG.md) for details.
|
|
143
|
+
Example: [generate.yml](https://github.com/0x1d1e/ocr-foundry/blob/main/configs/generate.yml)
|
|
144
|
+
|
|
145
|
+
Config loading order (lowest to highest priority):
|
|
146
|
+
1. argparse built-in defaults
|
|
147
|
+
2. YAML config file values
|
|
148
|
+
3. Explicit CLI flags
|
|
149
|
+
|
|
150
|
+
## CLI Reference
|
|
151
|
+
|
|
152
|
+
See [CLI_REFERENCE.md](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/CLI_REFERENCE.md) for complete command documentation.
|
|
153
|
+
|
|
154
|
+
## Documentation
|
|
155
|
+
|
|
156
|
+
- [Getting Started](https://github.com/0x1d1e/ocr-foundry/wiki/Getting-Started) for a first dataset.
|
|
157
|
+
- [GitHub wiki](https://github.com/0x1d1e/ocr-foundry/wiki) for usage guides and troubleshooting.
|
|
158
|
+
- [In-repository references](https://github.com/0x1d1e/ocr-foundry/blob/main/docs/README.md) for
|
|
159
|
+
the CLI, configuration, augmentation, and Rust extension.
|
|
160
|
+
|
|
161
|
+
## Acknowledgments
|
|
162
|
+
|
|
163
|
+
OCR Foundry builds on these open-source libraries:
|
|
164
|
+
|
|
165
|
+
- [khmernormalizer](https://github.com/seanghay/khmernormalizer) (MIT) - Khmer text normalization
|
|
166
|
+
- [OpenCV](https://opencv.org/) (Apache 2.0) - Image processing and augmentation
|
|
167
|
+
- [Pillow](https://python-pillow.org/) (HPND) - Font rendering and image creation
|
|
168
|
+
- [Albumentations](https://albumentations.ai/) (MIT) - Augmentation primitives
|
|
169
|
+
- [NumPy](https://numpy.org/) (BSD-3-Clause) - Numerical operations
|
|
170
|
+
- [LMDB](https://www.symas.com/lmdb) (OpenLDAP 2.8) - Embedded database for training pipelines
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
khocr_gen/__init__.py,sha256=UYucRIwwXp5sUXIfcRNjgWmuuQb1kroH5MUpXMntw_4,312
|
|
2
|
+
khocr_gen/_pil_compat.py,sha256=j5LuJbnlh6SBvlLoo1EeXs_1nmxbIIT98W_xzQfm-UM,678
|
|
3
|
+
khocr_gen/_rust_accel.py,sha256=4JsXBqu8RWgFqKdbSsHvaTrgkvmd6k93BTdt6J3J0Mg,6676
|
|
4
|
+
khocr_gen/augmentation.py,sha256=yzLKOLsEZC7T8tK3MdB-eQifTkzbV1JNRUVMPf0Ogrg,41046
|
|
5
|
+
khocr_gen/benchmark.py,sha256=Z2bvMUFMZr1RHcW3ERmIRZ1LgMRFJDL7PPVN0N14sFA,35121
|
|
6
|
+
khocr_gen/benchmark_cmd.py,sha256=Kaos2hoLPIThALS4RqzP2S1dHTrkDXH5eMjZ2oBXMJE,3905
|
|
7
|
+
khocr_gen/cli.py,sha256=UX0f629-OdIkRUiY7XlHcbA9O25hW51j9F0HjO4pZx8,7156
|
|
8
|
+
khocr_gen/combine.py,sha256=IcSQdXbjtLzGMVdy067eyh0EKNrKc9EY_Aawd8RrRTE,7484
|
|
9
|
+
khocr_gen/combine_cmd.py,sha256=mE_1aeJXbxJlS9Zr0PyL9qdYHowwjbuzriTvWDC3Lb8,3844
|
|
10
|
+
khocr_gen/config.py,sha256=esJg9apHRvATsFP4zSTKsm1amDWFDqfWnMQ4kn3wjLI,57929
|
|
11
|
+
khocr_gen/config_loader.py,sha256=uWsYWCJ-f2SrUVkLrMVeV-l0kTeJ8X4KLB4Ghn39M-k,5018
|
|
12
|
+
khocr_gen/corpus.py,sha256=39lVr3fsr7DuGTCPjHBIv1AnuIxGxtW1H58_2s8veHY,20906
|
|
13
|
+
khocr_gen/data_generator.py,sha256=EOt9I3akpYj0UJLNq1SdYDcSYKBppM_i5JmkYrlR2Kc,48784
|
|
14
|
+
khocr_gen/errors.py,sha256=u54q1i-9FqBA7_UQjqlK4YYebQcx9IrzYWmVRyvBwZE,801
|
|
15
|
+
khocr_gen/evaluate_cmd.py,sha256=cQRGxu7PMwgR5pHtnpG7O5HPqDjJb2aQqBNXwjRakwo,1454
|
|
16
|
+
khocr_gen/evaluation.py,sha256=Lhcr613dhquqbD9-sG4Ej8jRbz_U1JWjx8Mu8Y0aH50,10164
|
|
17
|
+
khocr_gen/fonts.py,sha256=FAlQ9QIY6JLPejPoYFixO4pTYaosJJ6YhYvQSDiPIkw,12782
|
|
18
|
+
khocr_gen/generate.py,sha256=x5vpJFk0AERsh0I-SLmqk1a5E9PqDYZIqzfpdVTZNJ8,8390
|
|
19
|
+
khocr_gen/layout.py,sha256=m3nBbIQQh33a3BBku4r-YYB3F242eeQfmxSyepbXINc,41756
|
|
20
|
+
khocr_gen/layout_cmd.py,sha256=WPhryKADF-ZMOXFXwCaREEEO9OX9c_fH4mOWrS2Gp4Q,12757
|
|
21
|
+
khocr_gen/layout_degradation.py,sha256=1qPnUO1N0F6qX4JQVaddSo8lmRKJQQOEWvy5ngGznGg,5589
|
|
22
|
+
khocr_gen/layout_mesh.py,sha256=2LDPUPW8ubWumPzgmd86w0MY56T1W4QoZORpoxGvOr4,8633
|
|
23
|
+
khocr_gen/layout_shaping.py,sha256=SCItKjSLesCU3yH4NvIa7qDiHPpGNQWkPrUnJsWRpvM,13723
|
|
24
|
+
khocr_gen/layout_transform.py,sha256=ZmGyadDesm74ktVC0Wlb0NFnbBY7v5p0TZazndv6tg4,10193
|
|
25
|
+
khocr_gen/layout_warp.py,sha256=hHh0JF797WIUscU7CTUn4Yvq_gfaLVTMLanKYdFXpW8,20264
|
|
26
|
+
khocr_gen/line_height.py,sha256=t35p_Tzc-kL0P4IkLpsgvhe3NSfBag5LCMhoul0ADic,5021
|
|
27
|
+
khocr_gen/lmdb_pack.py,sha256=wCExePR3Tdy8XWAPMqHqPIDXK0a41Ayt9WlLUQw1oww,4449
|
|
28
|
+
khocr_gen/logging.py,sha256=vC38AkARPePIjs9HMdYSINiSoCb9GohgqNJEEoLYleQ,748
|
|
29
|
+
khocr_gen/normalizer.py,sha256=uSRXrkdPSXv-QgMLoUggTSvGOrHjQtTohLN3jH4iPdo,7721
|
|
30
|
+
khocr_gen/parallel.py,sha256=0K3Ah9l6paAlEcMe_uCyDge1COpuDb4TOmhvD2imroE,13388
|
|
31
|
+
khocr_gen/provenance.py,sha256=1psCifMcnEotbIqJfsBBsPsVXF4_8bpONlQSRwfotms,11945
|
|
32
|
+
khocr_gen/rendering.py,sha256=_YLT_QL97ltsxVSd4qkDtjubO68SYIWffAfWpsXwm8o,67532
|
|
33
|
+
khocr_gen/text_support.py,sha256=_-_nmrSuNVPQQ9hWzIczbXnecjbAMh4uHoX0W-ep59Y,15144
|
|
34
|
+
khocr_gen/verify.py,sha256=y5ZQQAmiEMhHa_5hnMqUEsGl-pWpNIpxiwEmkRxiock,18141
|
|
35
|
+
khocr_gen/viewer.py,sha256=PJXrwq7NEqZMC8Jxldf9bop52XHl9yh6uUQ__o7SOJE,5941
|
|
36
|
+
ocr_foundry-0.2.0.dist-info/METADATA,sha256=IaZpXOt2we6_zwCiRbOTCRAm7xKdml8ozamG0iljdXo,7036
|
|
37
|
+
ocr_foundry-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
38
|
+
ocr_foundry-0.2.0.dist-info/entry_points.txt,sha256=sGOvPPH7m4LUwGeqKN5qWht2M-rU1IKYh955NE9XpVk,82
|
|
39
|
+
ocr_foundry-0.2.0.dist-info/licenses/LICENSE,sha256=AfRrnYSoa0M3RC3d-0nKjH_Ch9EwOnmLp2e4nYmpBbA,1067
|
|
40
|
+
ocr_foundry-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kosal Seng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|