g-ocr 0.1.0__tar.gz

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.
g_ocr-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
g_ocr-0.1.0/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ GOCR
2
+ Copyright (c) 2026 Keyvan Hardani / german-ocr.de
3
+
4
+ Dieses Produkt steht unter der Apache License 2.0 (siehe LICENSE).
5
+
6
+ Drittanbieter / Attribution
7
+ ---------------------------
8
+ GOCRs Erkenner-Linie "KSVTRv3" wird auf eigenen deutschen Daten trainiert.
9
+ Für vortrainierte Modellgewichte können Komponenten unter Apache License 2.0
10
+ zum Einsatz kommen (Text-Detektion vom Typ DB; Text-Erkennung vom Typ SVTR).
11
+ Diese Werke stehen unter Apache-2.0; die jeweiligen Lizenz- und Urheberhinweise
12
+ gelten fort.
g_ocr-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: g-ocr
3
+ Version: 0.1.0
4
+ Summary: GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht für Dokumente (CPU, kein GPU): ganzes Dokument → Text + Position (bbox) als JSON. Bilder + PDF.
5
+ Author: Keyvan Hardani
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://german-ocr.de
8
+ Project-URL: Source, https://github.com/Keyvanhardani/g-ocr
9
+ Keywords: ocr,german,deutsch,document,invoice,rechnung,bbox,onnx,cpu
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ License-File: NOTICE
17
+ Requires-Dist: onnxruntime>=1.16
18
+ Requires-Dist: numpy
19
+ Requires-Dist: opencv-python-headless
20
+ Requires-Dist: Pillow
21
+ Requires-Dist: pyclipper
22
+ Requires-Dist: shapely
23
+ Requires-Dist: huggingface_hub
24
+ Provides-Extra: pdf
25
+ Requires-Dist: pypdfium2>=4; extra == "pdf"
26
+ Provides-Extra: all
27
+ Requires-Dist: pypdfium2>=4; extra == "all"
28
+ Dynamic: license-file
29
+
30
+ # GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht (CPU)
31
+
32
+ Liest ein **ganzes Dokument** zu **Text + Position (bbox)** als strukturiertes JSON —
33
+ **~38 MB, reine CPU, kein GPU**. Gedacht als **OCR-/Vision-Schicht für (text-only) LLM-Pipelines**
34
+ und als **Tooling**: präzise Layout-Boxen + Text rein → dein LLM macht Verständnis/Extraktion.
35
+
36
+ ```bash
37
+ pip install g-ocr # Bilder: png/jpg/webp/tiff/bmp ...
38
+ pip install "g-ocr[pdf]" # + PDF-Support (optionales Plugin)
39
+ ```
40
+ ```python
41
+ import g_ocr
42
+ ocr = g_ocr.from_pretrained()
43
+ res = ocr.read("dokument.png") # ein Bild -> {text, regions:[{text, box, quad, score}]}
44
+ doc = ocr.read_document("rechnung.pdf") # PDF/mehrseitig -> {n_pages, pages:[...], text}
45
+ ```
46
+
47
+ ## Stärken
48
+ - 🎯 **Präzise Bounding-Boxes**, ganzes Dokument, Lesereihenfolge → strukturiertes JSON
49
+ - ⚡ **CPU, bis ~16× schneller als EasyOCR** — kein GPU
50
+ - 📦 **~38 MB** · 🧱 **Fraktur-robust** · on-prem/DSGVO · 🤖 **LLM-ready**
51
+ - 🗂️ **Bilder (png/jpg/webp/tiff/bmp …) + PDF** (bis ~500 Seiten) → ein API-Aufruf, JSON pro Seite
52
+
53
+ ## Benchmarks (anerkannte Sets, CPU)
54
+ ![GOCR Benchmarks](assets/gocr_benchmarks.png)
55
+
56
+ **Scene-Text** (Word Accuracy ↑): IIIT5K **93,2 %** · ICDAR2013 **94,1 %** · ICDAR2015 67,6 % — IIIT5K klar vor EasyOCR (68,2 %).
57
+
58
+ **Dokument-OCR** (CER ↓ / BoW ↓) — Harness [agentic-ai-forge/ocr-benchmark-2025](https://github.com/agentic-ai-forge/ocr-benchmark-2025):
59
+
60
+ | Engine | SROIE CER | FUNSD CER | SROIE BoW | FUNSD BoW |
61
+ |---|--:|--:|--:|--:|
62
+ | PaddleOCR | **15,2** | **20,3** | **25,8** | **50,5** |
63
+ | **GOCR** | 18,9 | 22,4 | 98,9 | 130,3 |
64
+ | EasyOCR | 20,4 | 26,4 | 81,1 | 102,1 |
65
+ | Tesseract | 22,6 | 32,4 | 70,2 | 88,2 |
66
+ | OCR.space | 44,3 | 48,2 | 73,3 | 84,8 |
67
+
68
+ **Einordnung:** Auf Dokument-**CER #2 von 5** — vor EasyOCR, Tesseract & OCR.space, knapp hinter PaddleOCR,
69
+ bei ~38 MB auf reiner CPU. Beim Bag-of-Words liegt GOCR zurück (Wort-Spacing der aktuellen Gewichte — Roadmap).
70
+ Fraktur (NewsEye) ≈3× besser als EasyOCR; bei rein-modernem Deutsch führen Spezial-Engines (Umlaut-Lücke).
71
+ *FUNSD = exakte 25 Referenz-Samples, SROIE = 60er-Stichprobe; gescort mit der `metrics.py` des Referenz-Harness.*
72
+
73
+ ## CLI
74
+ ```bash
75
+ g-ocr dokument.png # JSON (text + box + quad)
76
+ g-ocr rechnung.pdf # PDF -> JSON je Seite (Plugin: g-ocr[pdf])
77
+ g-ocr dokument.png --text-only # nur Text (Lesereihenfolge)
78
+ ```
79
+
80
+ ## Links
81
+ - 🤗 Modell + Card: https://huggingface.co/Keyven/g-ocr
82
+ - 🖥️ Demo: https://huggingface.co/spaces/Keyven/GOCR-Demo
83
+ - 🌐 https://german-ocr.de
84
+
85
+ ## Lizenz
86
+ Apache-2.0 — siehe [`LICENSE`](LICENSE) und [`NOTICE`](NOTICE).
g_ocr-0.1.0/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht (CPU)
2
+
3
+ Liest ein **ganzes Dokument** zu **Text + Position (bbox)** als strukturiertes JSON —
4
+ **~38 MB, reine CPU, kein GPU**. Gedacht als **OCR-/Vision-Schicht für (text-only) LLM-Pipelines**
5
+ und als **Tooling**: präzise Layout-Boxen + Text rein → dein LLM macht Verständnis/Extraktion.
6
+
7
+ ```bash
8
+ pip install g-ocr # Bilder: png/jpg/webp/tiff/bmp ...
9
+ pip install "g-ocr[pdf]" # + PDF-Support (optionales Plugin)
10
+ ```
11
+ ```python
12
+ import g_ocr
13
+ ocr = g_ocr.from_pretrained()
14
+ res = ocr.read("dokument.png") # ein Bild -> {text, regions:[{text, box, quad, score}]}
15
+ doc = ocr.read_document("rechnung.pdf") # PDF/mehrseitig -> {n_pages, pages:[...], text}
16
+ ```
17
+
18
+ ## Stärken
19
+ - 🎯 **Präzise Bounding-Boxes**, ganzes Dokument, Lesereihenfolge → strukturiertes JSON
20
+ - ⚡ **CPU, bis ~16× schneller als EasyOCR** — kein GPU
21
+ - 📦 **~38 MB** · 🧱 **Fraktur-robust** · on-prem/DSGVO · 🤖 **LLM-ready**
22
+ - 🗂️ **Bilder (png/jpg/webp/tiff/bmp …) + PDF** (bis ~500 Seiten) → ein API-Aufruf, JSON pro Seite
23
+
24
+ ## Benchmarks (anerkannte Sets, CPU)
25
+ ![GOCR Benchmarks](assets/gocr_benchmarks.png)
26
+
27
+ **Scene-Text** (Word Accuracy ↑): IIIT5K **93,2 %** · ICDAR2013 **94,1 %** · ICDAR2015 67,6 % — IIIT5K klar vor EasyOCR (68,2 %).
28
+
29
+ **Dokument-OCR** (CER ↓ / BoW ↓) — Harness [agentic-ai-forge/ocr-benchmark-2025](https://github.com/agentic-ai-forge/ocr-benchmark-2025):
30
+
31
+ | Engine | SROIE CER | FUNSD CER | SROIE BoW | FUNSD BoW |
32
+ |---|--:|--:|--:|--:|
33
+ | PaddleOCR | **15,2** | **20,3** | **25,8** | **50,5** |
34
+ | **GOCR** | 18,9 | 22,4 | 98,9 | 130,3 |
35
+ | EasyOCR | 20,4 | 26,4 | 81,1 | 102,1 |
36
+ | Tesseract | 22,6 | 32,4 | 70,2 | 88,2 |
37
+ | OCR.space | 44,3 | 48,2 | 73,3 | 84,8 |
38
+
39
+ **Einordnung:** Auf Dokument-**CER #2 von 5** — vor EasyOCR, Tesseract & OCR.space, knapp hinter PaddleOCR,
40
+ bei ~38 MB auf reiner CPU. Beim Bag-of-Words liegt GOCR zurück (Wort-Spacing der aktuellen Gewichte — Roadmap).
41
+ Fraktur (NewsEye) ≈3× besser als EasyOCR; bei rein-modernem Deutsch führen Spezial-Engines (Umlaut-Lücke).
42
+ *FUNSD = exakte 25 Referenz-Samples, SROIE = 60er-Stichprobe; gescort mit der `metrics.py` des Referenz-Harness.*
43
+
44
+ ## CLI
45
+ ```bash
46
+ g-ocr dokument.png # JSON (text + box + quad)
47
+ g-ocr rechnung.pdf # PDF -> JSON je Seite (Plugin: g-ocr[pdf])
48
+ g-ocr dokument.png --text-only # nur Text (Lesereihenfolge)
49
+ ```
50
+
51
+ ## Links
52
+ - 🤗 Modell + Card: https://huggingface.co/Keyven/g-ocr
53
+ - 🖥️ Demo: https://huggingface.co/spaces/Keyven/GOCR-Demo
54
+ - 🌐 https://german-ocr.de
55
+
56
+ ## Lizenz
57
+ Apache-2.0 — siehe [`LICENSE`](LICENSE) und [`NOTICE`](NOTICE).
@@ -0,0 +1,18 @@
1
+ """GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht (CPU, kein GPU).
2
+
3
+ Ganzes Dokument -> Text + Position (bbox) als strukturiertes JSON.
4
+ Bilder (png/jpg/webp/tiff/bmp ...) und PDF (Plugin: pip install g-ocr[pdf]).
5
+
6
+ import g_ocr
7
+ ocr = g_ocr.from_pretrained() # lädt die GOCR-Gewichte (HF)
8
+ res = ocr.read("dokument.png") # eine Seite
9
+ doc = ocr.read_document("rechnung.pdf") # mehrseitig (PDF/Bild)
10
+ # -> {text, regions:[{text, box:[x0,y0,x1,y1], quad, score}], ...}
11
+ """
12
+ __version__ = "0.1.0"
13
+
14
+ from .pipeline import GOCR, read, read_document # noqa: F401
15
+ from .pretrained import from_pretrained, DEFAULT_HF_REPO # noqa: F401
16
+
17
+ __all__ = ["GOCR", "read", "read_document", "from_pretrained",
18
+ "DEFAULT_HF_REPO", "__version__"]
@@ -0,0 +1,41 @@
1
+ """GOCR CLI: g-ocr datei.(png|jpg|webp|tiff|pdf ...) -> Text + bbox als JSON."""
2
+ import argparse
3
+ import json
4
+
5
+
6
+ def main():
7
+ ap = argparse.ArgumentParser(
8
+ prog="g-ocr",
9
+ description="GOCR — deutsche OCR: Dokument -> Text + Position (bbox). "
10
+ "Bilder (png/jpg/webp/tiff/bmp ...) und PDF.")
11
+ ap.add_argument("path", help="Bild- oder PDF-Pfad")
12
+ ap.add_argument("--repo", default=None, help="HF-Repo der GOCR-Gewichte")
13
+ ap.add_argument("--det", help="Detektor-ONNX (statt --repo)")
14
+ ap.add_argument("--rec", help="Recognizer-ONNX (statt --repo)")
15
+ ap.add_argument("--charset", help="Charset-Datei (statt --repo)")
16
+ ap.add_argument("--drop-score", type=float, default=0.4)
17
+ ap.add_argument("--max-pages", type=int, default=500, help="PDF: max. Seiten")
18
+ ap.add_argument("--dpi", type=int, default=200, help="PDF: Render-DPI")
19
+ ap.add_argument("--text-only", action="store_true", help="nur Text ausgeben")
20
+ a = ap.parse_args()
21
+
22
+ from .pipeline import GOCR
23
+ if a.det and a.rec and a.charset:
24
+ ocr = GOCR(a.det, a.rec, a.charset, drop_score=a.drop_score)
25
+ else:
26
+ from .pretrained import from_pretrained
27
+ ocr = from_pretrained(repo=a.repo, drop_score=a.drop_score)
28
+
29
+ from .formats import is_pdf
30
+ if is_pdf(a.path):
31
+ res = ocr.read_document(a.path, max_pages=a.max_pages, dpi=a.dpi)
32
+ else:
33
+ res = ocr.read(a.path)
34
+
35
+ # Beide Schemata haben ein Top-Level-"text" (Volltext / über alle Seiten).
36
+ print(res["text"] if a.text_only
37
+ else json.dumps(res, ensure_ascii=False, indent=2))
38
+
39
+
40
+ if __name__ == "__main__":
41
+ main()
@@ -0,0 +1,76 @@
1
+ """GOCR-Eingabeformate — pluggbare Loader für Bilder und PDF.
2
+
3
+ Bilder (png/jpg/webp/tiff/bmp/gif ...) laufen über Pillow (Core-Dep).
4
+ PDF ist ein **optionales Plugin**: pip install g-ocr[pdf] (pypdfium2).
5
+
6
+ Erweiterbar: weitere Formate via LOADERS-Registry (Endung -> Loader-Funktion,
7
+ die ein BGR-numpy-Array bzw. einen Seiten-Generator liefert).
8
+ """
9
+ import os
10
+ import numpy as np
11
+
12
+ # Vom Pillow-Decoder abgedeckte Einzelbild-Formate.
13
+ IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".webp", ".tif", ".tiff",
14
+ ".bmp", ".gif", ".ppm", ".pgm", ".jp2"}
15
+ PDF_EXTS = {".pdf"}
16
+
17
+
18
+ def _ext(path):
19
+ return os.path.splitext(path)[1].lower() if isinstance(path, str) else ""
20
+
21
+
22
+ def _pil_to_bgr(im):
23
+ """PIL-Image -> BGR-numpy (wie cv2.imread, RGB->BGR)."""
24
+ arr = np.asarray(im.convert("RGB"))
25
+ return np.ascontiguousarray(arr[:, :, ::-1])
26
+
27
+
28
+ def load_image(path):
29
+ """Bild-Datei -> BGR-numpy. Robust inkl. webp/tiff/bmp/gif (Pillow)."""
30
+ from PIL import Image
31
+ try:
32
+ with Image.open(path) as im:
33
+ return _pil_to_bgr(im)
34
+ except Exception as e: # klare Fehlermeldung statt None
35
+ raise ValueError(f"GOCR: Bild nicht lesbar: {path} ({e})") from e
36
+
37
+
38
+ def is_pdf(path):
39
+ return _ext(path) in PDF_EXTS
40
+
41
+
42
+ def is_image(path):
43
+ return _ext(path) in IMAGE_EXTS
44
+
45
+
46
+ def iter_pdf_pages(path, dpi=200, max_pages=500):
47
+ """PDF -> Generator je Seite: (index, total_seiten, bgr_numpy).
48
+
49
+ Optionales Plugin: pip install g-ocr[pdf] (pypdfium2).
50
+ Sehr große PDFs werden bei max_pages begrenzt (total wird trotzdem gemeldet).
51
+ """
52
+ try:
53
+ import pypdfium2 as pdfium
54
+ except ImportError as e:
55
+ raise ImportError(
56
+ "GOCR: PDF-Support benötigt das optionale Plugin 'pypdfium2'.\n"
57
+ " Installieren: pip install g-ocr[pdf]"
58
+ ) from e
59
+
60
+ pdf = pdfium.PdfDocument(path)
61
+ try:
62
+ total = len(pdf)
63
+ n = min(total, max(0, int(max_pages)))
64
+ scale = dpi / 72.0 # PDF-Basis = 72 DPI
65
+ for i in range(n):
66
+ page = pdf[i]
67
+ bitmap = page.render(scale=scale)
68
+ pil = bitmap.to_pil()
69
+ yield i, total, _pil_to_bgr(pil)
70
+ page.close()
71
+ finally:
72
+ pdf.close()
73
+
74
+
75
+ # Registry: Endung -> ("image"|"pdf"). Für künftige Formate hier erweitern.
76
+ LOADERS = {**{e: "image" for e in IMAGE_EXTS}, **{e: "pdf" for e in PDF_EXTS}}
@@ -0,0 +1,283 @@
1
+ """GOCR-Engine — Detektor (DB) + Recognizer (CTC), reines ONNX / CPU.
2
+
3
+ Eigenständige Inferenz-Pipeline (kein Fremd-OCR-Import):
4
+ ocr = GOCR(det_onnx, rec_onnx, charset)
5
+ ocr.read(img) -> {engine, version, image, text, n_regions, regions[box, quad, score]}
6
+ ocr.read_document(path) -> mehrseitig (PDF/Bild): {n_pages, pages:[...], text}
7
+
8
+ Gewichte/Charset sind konfigurierbar (eigene Modelle werden hier eingehängt).
9
+ """
10
+ import os
11
+ import warnings
12
+
13
+ import numpy as np
14
+ import cv2
15
+ import onnxruntime as ort
16
+
17
+ from .formats import load_image, is_pdf, iter_pdf_pages
18
+
19
+ try:
20
+ import pyclipper
21
+ from shapely.geometry import Polygon
22
+ _HAS_CLIP = True
23
+ except Exception: # pragma: no cover
24
+ _HAS_CLIP = False
25
+
26
+ _MEAN = np.array([0.485, 0.456, 0.406], np.float32)
27
+ _STD = np.array([0.229, 0.224, 0.225], np.float32)
28
+
29
+
30
+ # ----------------------------- Charset / CTC -----------------------------
31
+ def load_charset(path):
32
+ """CTC-Charset: index 0 = blank, dann Dict-Zeilen, am Ende Space."""
33
+ chars = ["<blank>"]
34
+ with open(path, encoding="utf-8") as f:
35
+ for line in f:
36
+ chars.append(line.rstrip("\n"))
37
+ chars.append(" ")
38
+ return chars
39
+
40
+
41
+ def ctc_greedy_decode(probs, charset):
42
+ """probs: [T, C] (softmax). Collapse-Repeats + Blank(0) entfernen."""
43
+ idx = probs.argmax(1)
44
+ conf = probs.max(1)
45
+ out, confs, prev = [], [], -1
46
+ for i, p in zip(idx, conf):
47
+ if i != 0 and i != prev:
48
+ if i < len(charset):
49
+ out.append(charset[i])
50
+ confs.append(p)
51
+ prev = i
52
+ return "".join(out), (float(np.mean(confs)) if confs else 0.0)
53
+
54
+
55
+ # ----------------------------- Detektor (DB) -----------------------------
56
+ def _det_preprocess(img_bgr, limit_side_len=960):
57
+ h, w = img_bgr.shape[:2]
58
+ ratio = min(1.0, limit_side_len / max(h, w))
59
+ rh = max(32, int(round(h * ratio / 32)) * 32)
60
+ rw = max(32, int(round(w * ratio / 32)) * 32)
61
+ resized = cv2.resize(img_bgr, (rw, rh))
62
+ x = resized.astype(np.float32) / 255.0
63
+ x = (x - _MEAN) / _STD
64
+ return x.transpose(2, 0, 1)[None].astype(np.float32), (h, w, rh, rw)
65
+
66
+
67
+ def _order_quad(pts):
68
+ """4 Punkte -> tl, tr, br, bl."""
69
+ pts = pts[np.argsort(pts[:, 0])]
70
+ left = pts[:2][np.argsort(pts[:2, 1])]
71
+ right = pts[2:][np.argsort(pts[2:, 1])]
72
+ return np.array([left[0], right[0], right[1], left[1]], np.float32)
73
+
74
+
75
+ def _unclip(box, ratio):
76
+ poly = Polygon(box)
77
+ if poly.length == 0:
78
+ return None
79
+ dist = poly.area * ratio / poly.length
80
+ off = pyclipper.PyclipperOffset()
81
+ off.AddPath([tuple(p) for p in box], pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
82
+ res = off.Execute(dist)
83
+ return np.array(res[0]) if res else None
84
+
85
+
86
+ def _box_score_slow(prob, contour):
87
+ h, w = prob.shape
88
+ c = contour.reshape(-1, 2).copy()
89
+ xmin = int(np.clip(c[:, 0].min(), 0, w - 1)); xmax = int(np.clip(c[:, 0].max(), 0, w - 1))
90
+ ymin = int(np.clip(c[:, 1].min(), 0, h - 1)); ymax = int(np.clip(c[:, 1].max(), 0, h - 1))
91
+ mask = np.zeros((ymax - ymin + 1, xmax - xmin + 1), np.uint8)
92
+ c[:, 0] -= xmin; c[:, 1] -= ymin
93
+ cv2.fillPoly(mask, [c.astype(np.int32)], 1)
94
+ return cv2.mean(prob[ymin:ymax + 1, xmin:xmax + 1], mask)[0]
95
+
96
+
97
+ def _db_boxes(prob, shape, thresh=0.3, box_thresh=0.6, unclip_ratio=1.5,
98
+ max_candidates=1000, min_size=3):
99
+ h0, w0, rh, rw = shape
100
+ bitmap = (prob > thresh).astype(np.uint8) * 255
101
+ contours, _ = cv2.findContours(bitmap, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
102
+ boxes, scores = [], []
103
+ for contour in contours[:max_candidates]:
104
+ eps = 0.002 * cv2.arcLength(contour, True)
105
+ approx = cv2.approxPolyDP(contour, eps, True).reshape(-1, 2)
106
+ if approx.shape[0] < 4:
107
+ continue
108
+ score = _box_score_slow(prob, contour)
109
+ if score < box_thresh:
110
+ continue
111
+ ub = _unclip(approx, unclip_ratio)
112
+ if ub is None or len(ub) < 4:
113
+ continue
114
+ rect = cv2.minAreaRect(ub.reshape(-1, 2).astype(np.float32))
115
+ if min(rect[1]) < min_size:
116
+ continue
117
+ quad = _order_quad(cv2.boxPoints(rect))
118
+ quad[:, 0] = np.clip(quad[:, 0] / rw * w0, 0, w0)
119
+ quad[:, 1] = np.clip(quad[:, 1] / rh * h0, 0, h0)
120
+ boxes.append(quad)
121
+ scores.append(float(score))
122
+ return boxes, scores
123
+
124
+
125
+ def _reading_order(boxes):
126
+ """Sortiere Boxen oben→unten, links→rechts (Zeilen-tolerant)."""
127
+ if not boxes:
128
+ return []
129
+ idx = list(range(len(boxes)))
130
+ tops = [b[:, 1].min() for b in boxes]
131
+ lefts = [b[:, 0].min() for b in boxes]
132
+ heights = [max(1, b[:, 1].max() - b[:, 1].min()) for b in boxes]
133
+ tol = np.median(heights) * 0.6
134
+ idx.sort(key=lambda i: (round(tops[i] / max(tol, 1)), lefts[i]))
135
+ return idx
136
+
137
+
138
+ def _crop(img, quad):
139
+ quad = quad.astype(np.float32)
140
+ wA = np.linalg.norm(quad[0] - quad[1]); wB = np.linalg.norm(quad[3] - quad[2])
141
+ hA = np.linalg.norm(quad[0] - quad[3]); hB = np.linalg.norm(quad[1] - quad[2])
142
+ W, H = int(max(wA, wB)), int(max(hA, hB))
143
+ if W < 1 or H < 1:
144
+ return None
145
+ dst = np.array([[0, 0], [W, 0], [W, H], [0, H]], np.float32)
146
+ crop = cv2.warpPerspective(img, cv2.getPerspectiveTransform(quad, dst), (W, H))
147
+ if H * 1.0 / W >= 1.5: # hohe Boxen drehen
148
+ crop = np.rot90(crop)
149
+ return crop
150
+
151
+
152
+ # ----------------------------- Recognizer (CTC) --------------------------
153
+ def _rec_preprocess(crop_bgr, img_h=48, max_w=320):
154
+ h, w = crop_bgr.shape[:2]
155
+ rw = min(max_w, max(1, int(round(img_h * w / max(h, 1)))))
156
+ resized = cv2.resize(crop_bgr, (rw, img_h))
157
+ x = (resized.astype(np.float32) / 255.0 - 0.5) / 0.5
158
+ return x.transpose(2, 0, 1)[None].astype(np.float32)
159
+
160
+
161
+ # ----------------------------- GOCR ---------------------------------------
162
+ class GOCR:
163
+ """Deutsche OCR-Engine: Detektor + Recognizer, reines ONNX/CPU."""
164
+
165
+ def __init__(self, det_onnx, rec_onnx, charset, drop_score=0.4,
166
+ limit_side_len=960, rec_h=48, rec_max_w=2000, num_threads=None):
167
+ so = ort.SessionOptions()
168
+ if num_threads:
169
+ so.intra_op_num_threads = int(num_threads)
170
+ prov = ["CPUExecutionProvider"]
171
+ self.det = ort.InferenceSession(det_onnx, sess_options=so, providers=prov)
172
+ self.rec = ort.InferenceSession(rec_onnx, sess_options=so, providers=prov)
173
+ self.det_in = self.det.get_inputs()[0].name
174
+ self.rec_in = self.rec.get_inputs()[0].name
175
+ self.charset = charset if isinstance(charset, list) else load_charset(charset)
176
+ self.drop_score = drop_score
177
+ self.limit_side_len = limit_side_len
178
+ self.rec_h, self.rec_max_w = rec_h, rec_max_w
179
+
180
+ def detect(self, img_bgr):
181
+ x, shape = _det_preprocess(img_bgr, self.limit_side_len)
182
+ prob = self.det.run(None, {self.det_in: x})[0][0, 0]
183
+ boxes, _ = _db_boxes(prob, shape)
184
+ return [boxes[i] for i in _reading_order(boxes)]
185
+
186
+ def recognize(self, crop_bgr):
187
+ x = _rec_preprocess(crop_bgr, self.rec_h, self.rec_max_w)
188
+ probs = self.rec.run(None, {self.rec_in: x})[0][0]
189
+ return ctc_greedy_decode(probs, self.charset)
190
+
191
+ def _to_bgr(self, image):
192
+ """Pfad (Bild) oder numpy -> BGR-numpy. PDF: siehe read_document()."""
193
+ if isinstance(image, str):
194
+ return load_image(image) # robust inkl. webp (Pillow)
195
+ arr = np.asarray(image)
196
+ if arr.ndim == 2: # Graustufen -> 3 Kanäle
197
+ arr = np.stack([arr, arr, arr], -1)
198
+ if arr.shape[2] == 3: # RGB -> BGR (Annahme)
199
+ arr = arr[:, :, ::-1]
200
+ return np.ascontiguousarray(arr)
201
+
202
+ def _ocr_page(self, img_bgr):
203
+ """BGR-numpy -> {image, text, n_regions, regions} (eine Seite)."""
204
+ h, w = img_bgr.shape[:2]
205
+ regions = []
206
+ for quad in self.detect(img_bgr):
207
+ crop = _crop(img_bgr, quad)
208
+ if crop is None:
209
+ continue
210
+ text, score = self.recognize(crop)
211
+ if not text or score < self.drop_score:
212
+ continue
213
+ xs = [int(p[0]) for p in quad]
214
+ ys = [int(p[1]) for p in quad]
215
+ regions.append({
216
+ "id": len(regions),
217
+ "text": text,
218
+ "score": round(score, 3),
219
+ "box": [min(xs), min(ys), max(xs), max(ys)],
220
+ "quad": [[int(x), int(y)] for x, y in quad],
221
+ })
222
+ return {
223
+ "image": {"width": int(w), "height": int(h)},
224
+ "text": "\n".join(r["text"] for r in regions),
225
+ "n_regions": len(regions),
226
+ "regions": regions,
227
+ }
228
+
229
+ def read(self, image):
230
+ """Ein Bild (Pfad/numpy) -> strukturiertes GOCR-JSON (eine Seite).
231
+
232
+ Schema: {engine, version, image:{width,height}, text, n_regions,
233
+ regions:[{id, text, score, box:[x0,y0,x1,y1], quad:[[x,y]x4]}]}
234
+ - box = achsenparalleles Rechteck (kompakt) - quad = 4 Eckpunkte
235
+ - text = Volltext in Lesereihenfolge (direkt fürs LLM)
236
+ Bildformate inkl. webp/tiff/bmp. Für PDF/mehrseitig: read_document().
237
+ """
238
+ page = self._ocr_page(self._to_bgr(image))
239
+ return {"engine": "GOCR", "version": "0.1.0", **page}
240
+
241
+ def read_document(self, source, max_pages=500, dpi=200):
242
+ """Bild ODER PDF (Pfad) -> Dokument-JSON über alle Seiten.
243
+
244
+ Schema: {engine, version, source, n_pages, n_pages_total, truncated,
245
+ text, pages:[{page, image, text, n_regions, regions}]}
246
+ PDF-Support ist ein optionales Plugin: pip install g-ocr[pdf].
247
+ max_pages begrenzt sehr große PDFs (Default 500); truncated +
248
+ n_pages_total zeigen ehrlich, ob abgeschnitten wurde.
249
+ """
250
+ pages = []
251
+ n_total = 1
252
+ if is_pdf(source):
253
+ for i, total, bgr in iter_pdf_pages(source, dpi=dpi, max_pages=max_pages):
254
+ n_total = total
255
+ pages.append({"page": i + 1, **self._ocr_page(bgr)})
256
+ else:
257
+ pages.append({"page": 1, **self._ocr_page(self._to_bgr(source))})
258
+ truncated = n_total > len(pages)
259
+ if truncated:
260
+ warnings.warn(
261
+ f"GOCR: nur {len(pages)}/{n_total} Seiten verarbeitet "
262
+ f"(max_pages={max_pages}).")
263
+ return {
264
+ "engine": "GOCR",
265
+ "version": "0.1.0",
266
+ "source": source if isinstance(source, str) else "<array>",
267
+ "n_pages": len(pages),
268
+ "n_pages_total": n_total,
269
+ "truncated": truncated,
270
+ "text": "\n\n".join(p["text"] for p in pages),
271
+ "pages": pages,
272
+ }
273
+
274
+
275
+ def read(image, det_onnx, rec_onnx, charset, **kw):
276
+ """Komfort-Funktion (ein Bild)."""
277
+ return GOCR(det_onnx, rec_onnx, charset, **kw).read(image)
278
+
279
+
280
+ def read_document(source, det_onnx, rec_onnx, charset, *, max_pages=500, dpi=200, **kw):
281
+ """Komfort-Funktion (Bild/PDF, mehrseitig)."""
282
+ return GOCR(det_onnx, rec_onnx, charset, **kw).read_document(
283
+ source, max_pages=max_pages, dpi=dpi)
@@ -0,0 +1,21 @@
1
+ """GOCR-Gewichte laden (von HuggingFace)."""
2
+ import os
3
+
4
+ from .pipeline import GOCR
5
+
6
+ # HF-Repo mit den GOCR-Gewichten (gocr_det.onnx, gocr_rec.onnx, charset.txt).
7
+ DEFAULT_HF_REPO = os.environ.get("GOCR_HF_REPO", "Keyven/g-ocr")
8
+
9
+
10
+ def from_pretrained(repo=None, det="gocr_det.onnx", rec="gocr_rec.onnx",
11
+ charset="charset.txt", **kwargs):
12
+ """Lädt Detektor + Recognizer + Charset aus dem HF-Repo und baut die GOCR-Engine.
13
+
14
+ kwargs werden an GOCR() durchgereicht (z. B. drop_score, num_threads).
15
+ """
16
+ from huggingface_hub import hf_hub_download
17
+ repo = repo or DEFAULT_HF_REPO
18
+ det_p = hf_hub_download(repo, det)
19
+ rec_p = hf_hub_download(repo, rec)
20
+ cs_p = hf_hub_download(repo, charset)
21
+ return GOCR(det_p, rec_p, cs_p, **kwargs)
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: g-ocr
3
+ Version: 0.1.0
4
+ Summary: GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht für Dokumente (CPU, kein GPU): ganzes Dokument → Text + Position (bbox) als JSON. Bilder + PDF.
5
+ Author: Keyvan Hardani
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://german-ocr.de
8
+ Project-URL: Source, https://github.com/Keyvanhardani/g-ocr
9
+ Keywords: ocr,german,deutsch,document,invoice,rechnung,bbox,onnx,cpu
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ License-File: NOTICE
17
+ Requires-Dist: onnxruntime>=1.16
18
+ Requires-Dist: numpy
19
+ Requires-Dist: opencv-python-headless
20
+ Requires-Dist: Pillow
21
+ Requires-Dist: pyclipper
22
+ Requires-Dist: shapely
23
+ Requires-Dist: huggingface_hub
24
+ Provides-Extra: pdf
25
+ Requires-Dist: pypdfium2>=4; extra == "pdf"
26
+ Provides-Extra: all
27
+ Requires-Dist: pypdfium2>=4; extra == "all"
28
+ Dynamic: license-file
29
+
30
+ # GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht (CPU)
31
+
32
+ Liest ein **ganzes Dokument** zu **Text + Position (bbox)** als strukturiertes JSON —
33
+ **~38 MB, reine CPU, kein GPU**. Gedacht als **OCR-/Vision-Schicht für (text-only) LLM-Pipelines**
34
+ und als **Tooling**: präzise Layout-Boxen + Text rein → dein LLM macht Verständnis/Extraktion.
35
+
36
+ ```bash
37
+ pip install g-ocr # Bilder: png/jpg/webp/tiff/bmp ...
38
+ pip install "g-ocr[pdf]" # + PDF-Support (optionales Plugin)
39
+ ```
40
+ ```python
41
+ import g_ocr
42
+ ocr = g_ocr.from_pretrained()
43
+ res = ocr.read("dokument.png") # ein Bild -> {text, regions:[{text, box, quad, score}]}
44
+ doc = ocr.read_document("rechnung.pdf") # PDF/mehrseitig -> {n_pages, pages:[...], text}
45
+ ```
46
+
47
+ ## Stärken
48
+ - 🎯 **Präzise Bounding-Boxes**, ganzes Dokument, Lesereihenfolge → strukturiertes JSON
49
+ - ⚡ **CPU, bis ~16× schneller als EasyOCR** — kein GPU
50
+ - 📦 **~38 MB** · 🧱 **Fraktur-robust** · on-prem/DSGVO · 🤖 **LLM-ready**
51
+ - 🗂️ **Bilder (png/jpg/webp/tiff/bmp …) + PDF** (bis ~500 Seiten) → ein API-Aufruf, JSON pro Seite
52
+
53
+ ## Benchmarks (anerkannte Sets, CPU)
54
+ ![GOCR Benchmarks](assets/gocr_benchmarks.png)
55
+
56
+ **Scene-Text** (Word Accuracy ↑): IIIT5K **93,2 %** · ICDAR2013 **94,1 %** · ICDAR2015 67,6 % — IIIT5K klar vor EasyOCR (68,2 %).
57
+
58
+ **Dokument-OCR** (CER ↓ / BoW ↓) — Harness [agentic-ai-forge/ocr-benchmark-2025](https://github.com/agentic-ai-forge/ocr-benchmark-2025):
59
+
60
+ | Engine | SROIE CER | FUNSD CER | SROIE BoW | FUNSD BoW |
61
+ |---|--:|--:|--:|--:|
62
+ | PaddleOCR | **15,2** | **20,3** | **25,8** | **50,5** |
63
+ | **GOCR** | 18,9 | 22,4 | 98,9 | 130,3 |
64
+ | EasyOCR | 20,4 | 26,4 | 81,1 | 102,1 |
65
+ | Tesseract | 22,6 | 32,4 | 70,2 | 88,2 |
66
+ | OCR.space | 44,3 | 48,2 | 73,3 | 84,8 |
67
+
68
+ **Einordnung:** Auf Dokument-**CER #2 von 5** — vor EasyOCR, Tesseract & OCR.space, knapp hinter PaddleOCR,
69
+ bei ~38 MB auf reiner CPU. Beim Bag-of-Words liegt GOCR zurück (Wort-Spacing der aktuellen Gewichte — Roadmap).
70
+ Fraktur (NewsEye) ≈3× besser als EasyOCR; bei rein-modernem Deutsch führen Spezial-Engines (Umlaut-Lücke).
71
+ *FUNSD = exakte 25 Referenz-Samples, SROIE = 60er-Stichprobe; gescort mit der `metrics.py` des Referenz-Harness.*
72
+
73
+ ## CLI
74
+ ```bash
75
+ g-ocr dokument.png # JSON (text + box + quad)
76
+ g-ocr rechnung.pdf # PDF -> JSON je Seite (Plugin: g-ocr[pdf])
77
+ g-ocr dokument.png --text-only # nur Text (Lesereihenfolge)
78
+ ```
79
+
80
+ ## Links
81
+ - 🤗 Modell + Card: https://huggingface.co/Keyven/g-ocr
82
+ - 🖥️ Demo: https://huggingface.co/spaces/Keyven/GOCR-Demo
83
+ - 🌐 https://german-ocr.de
84
+
85
+ ## Lizenz
86
+ Apache-2.0 — siehe [`LICENSE`](LICENSE) und [`NOTICE`](NOTICE).
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ NOTICE
3
+ README.md
4
+ pyproject.toml
5
+ g_ocr/__init__.py
6
+ g_ocr/cli.py
7
+ g_ocr/formats.py
8
+ g_ocr/pipeline.py
9
+ g_ocr/pretrained.py
10
+ g_ocr.egg-info/PKG-INFO
11
+ g_ocr.egg-info/SOURCES.txt
12
+ g_ocr.egg-info/dependency_links.txt
13
+ g_ocr.egg-info/entry_points.txt
14
+ g_ocr.egg-info/requires.txt
15
+ g_ocr.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ g-ocr = g_ocr.cli:main
@@ -0,0 +1,13 @@
1
+ onnxruntime>=1.16
2
+ numpy
3
+ opencv-python-headless
4
+ Pillow
5
+ pyclipper
6
+ shapely
7
+ huggingface_hub
8
+
9
+ [all]
10
+ pypdfium2>=4
11
+
12
+ [pdf]
13
+ pypdfium2>=4
@@ -0,0 +1 @@
1
+ g_ocr
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "g-ocr"
7
+ version = "0.1.0"
8
+ description = "GOCR — schnelle, kleine deutsche OCR-/Vision-Schicht für Dokumente (CPU, kein GPU): ganzes Dokument → Text + Position (bbox) als JSON. Bilder + PDF."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ authors = [{ name = "Keyvan Hardani" }]
13
+ keywords = ["ocr", "german", "deutsch", "document", "invoice", "rechnung", "bbox", "onnx", "cpu"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Topic :: Scientific/Engineering :: Image Recognition",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "onnxruntime>=1.16",
21
+ "numpy",
22
+ "opencv-python-headless",
23
+ "Pillow",
24
+ "pyclipper",
25
+ "shapely",
26
+ "huggingface_hub",
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ pdf = ["pypdfium2>=4"]
31
+ all = ["pypdfium2>=4"]
32
+
33
+ [project.urls]
34
+ Homepage = "https://german-ocr.de"
35
+ Source = "https://github.com/Keyvanhardani/g-ocr"
36
+
37
+ [project.scripts]
38
+ g-ocr = "g_ocr.cli:main"
39
+
40
+ [tool.setuptools.packages.find]
41
+ include = ["g_ocr*"]
42
+
43
+ [tool.setuptools.package-data]
44
+ g_ocr = ["assets/*.txt"]
g_ocr-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+