accsify-tesseract 1.0.5.1__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.
Files changed (56) hide show
  1. accsify_tesseract-1.0.5.1/LICENSE +79 -0
  2. accsify_tesseract-1.0.5.1/MANIFEST.in +8 -0
  3. accsify_tesseract-1.0.5.1/PKG-INFO +361 -0
  4. accsify_tesseract-1.0.5.1/README.md +326 -0
  5. accsify_tesseract-1.0.5.1/accsify_tesseract/__init__.py +182 -0
  6. accsify_tesseract-1.0.5.1/accsify_tesseract/cli.py +316 -0
  7. accsify_tesseract-1.0.5.1/accsify_tesseract/core.py +367 -0
  8. accsify_tesseract-1.0.5.1/accsify_tesseract/engine.py +409 -0
  9. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/01_basic_ocr.py +78 -0
  10. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/02_multilingual_bidi_ocr.py +92 -0
  11. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/03_layout_and_json.py +92 -0
  12. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/04_batch_and_export_formats.py +107 -0
  13. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/05_memory_and_pil_buffer.py +86 -0
  14. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/06_model_catalog_and_flavors.py +73 -0
  15. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/07_cli_tool_integration.py +69 -0
  16. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/README.md +275 -0
  17. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/__init__.py +70 -0
  18. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/sample_bilingual_doc.png +0 -0
  19. accsify_tesseract-1.0.5.1/accsify_tesseract/examples/sample_receipt_mixed.png +0 -0
  20. accsify_tesseract-1.0.5.1/accsify_tesseract/exceptions.py +39 -0
  21. accsify_tesseract-1.0.5.1/accsify_tesseract/iterator.py +102 -0
  22. accsify_tesseract-1.0.5.1/accsify_tesseract/layout.py +146 -0
  23. accsify_tesseract-1.0.5.1/accsify_tesseract/lib/x64/tesseract_cli.exe +0 -0
  24. accsify_tesseract-1.0.5.1/accsify_tesseract/lib/x64/tesseract_engine.dll +0 -0
  25. accsify_tesseract-1.0.5.1/accsify_tesseract/lib/x64/tesseract_engine.lib +0 -0
  26. accsify_tesseract-1.0.5.1/accsify_tesseract/lib/x86/tesseract_cli.exe +0 -0
  27. accsify_tesseract-1.0.5.1/accsify_tesseract/lib/x86/tesseract_engine.dll +0 -0
  28. accsify_tesseract-1.0.5.1/accsify_tesseract/lib/x86/tesseract_engine.lib +0 -0
  29. accsify_tesseract-1.0.5.1/accsify_tesseract/models.py +194 -0
  30. accsify_tesseract-1.0.5.1/accsify_tesseract/osd.py +41 -0
  31. accsify_tesseract-1.0.5.1/accsify_tesseract/py.typed +1 -0
  32. accsify_tesseract-1.0.5.1/accsify_tesseract/sample_generator.py +478 -0
  33. accsify_tesseract-1.0.5.1/accsify_tesseract/types.py +103 -0
  34. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/PKG-INFO +361 -0
  35. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/SOURCES.txt +55 -0
  36. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/dependency_links.txt +1 -0
  37. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/entry_points.txt +2 -0
  38. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/not-zip-safe +1 -0
  39. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/requires.txt +1 -0
  40. accsify_tesseract-1.0.5.1/accsify_tesseract.egg-info/top_level.txt +1 -0
  41. accsify_tesseract-1.0.5.1/pyproject.toml +43 -0
  42. accsify_tesseract-1.0.5.1/setup.cfg +60 -0
  43. accsify_tesseract-1.0.5.1/setup.py +205 -0
  44. accsify_tesseract-1.0.5.1/tests/__init__.py +6 -0
  45. accsify_tesseract-1.0.5.1/tests/conftest.py +49 -0
  46. accsify_tesseract-1.0.5.1/tests/test_01_lifecycle.py +71 -0
  47. accsify_tesseract-1.0.5.1/tests/test_02_models.py +72 -0
  48. accsify_tesseract-1.0.5.1/tests/test_03_sample_generation.py +52 -0
  49. accsify_tesseract-1.0.5.1/tests/test_04_ocr_basic.py +71 -0
  50. accsify_tesseract-1.0.5.1/tests/test_05_multilingual_bidi.py +66 -0
  51. accsify_tesseract-1.0.5.1/tests/test_06_image_inputs.py +79 -0
  52. accsify_tesseract-1.0.5.1/tests/test_07_layout_analysis.py +59 -0
  53. accsify_tesseract-1.0.5.1/tests/test_08_export_formats.py +81 -0
  54. accsify_tesseract-1.0.5.1/tests/test_09_parameters_and_variables.py +56 -0
  55. accsify_tesseract-1.0.5.1/tests/test_10_native_cli.py +66 -0
  56. accsify_tesseract-1.0.5.1/tests/test_all.py +30 -0
@@ -0,0 +1,79 @@
1
+ ACCOSIFY TESSERACT - MULTI-LICENSE & THIRD-PARTY ATTRIBUTION NOTICE
2
+ ================================================================================
3
+
4
+ This software is released under the MIT License by Accsify.
5
+ It statically links and incorporates upstream components under their respective
6
+ permissive open-source licenses (Apache-2.0, BSD-2-Clause, and Public Domain).
7
+
8
+ --------------------------------------------------------------------------------
9
+ 1. ACCSIFY TESSERACT LICENSE (MIT)
10
+ --------------------------------------------------------------------------------
11
+ Copyright (c) 2026 accsify. All rights reserved.
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+
31
+ --------------------------------------------------------------------------------
32
+ 2. TESSERACT OCR LICENSE (Apache License 2.0)
33
+ --------------------------------------------------------------------------------
34
+ Copyright (C) 2006-2024 Google LLC, Ray Smith, and Tesseract contributors.
35
+
36
+ Licensed under the Apache License, Version 2.0 (the "License");
37
+ you may not use this file except in compliance with the License.
38
+ You may obtain a copy of the License at
39
+
40
+ http://www.apache.org/licenses/LICENSE-2.0
41
+
42
+ Unless required by applicable law or agreed to in writing, software
43
+ distributed under the License is distributed on an "AS IS" BASIS,
44
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45
+ See the License for the specific language governing permissions and
46
+ limitations under the License.
47
+
48
+ --------------------------------------------------------------------------------
49
+ 3. LEPTONICA LICENSE (BSD 2-Clause)
50
+ --------------------------------------------------------------------------------
51
+ Copyright (C) 2001-2024 Leptonica (Dan Bloomberg). All rights reserved.
52
+
53
+ Redistribution and use in source and binary forms, with or without
54
+ modification, are permitted provided that the following conditions are met:
55
+
56
+ 1. Redistributions of source code must retain the above copyright notice,
57
+ this list of conditions and the following disclaimer.
58
+ 2. Redistributions in binary form must reproduce the above copyright notice,
59
+ this list of conditions and the following disclaimer in the documentation
60
+ and/or other materials provided with the distribution.
61
+
62
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
63
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
66
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
67
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
68
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
69
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
70
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
71
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
72
+ POSSIBILITY OF SUCH DAMAGE.
73
+
74
+ --------------------------------------------------------------------------------
75
+ 4. STB_IMAGE (Public Domain / MIT)
76
+ --------------------------------------------------------------------------------
77
+ Developed by Sean Barrett (nothings.org).
78
+ This software is in the public domain. Where public domain is not recognized,
79
+ it is licensed under the MIT License.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ include setup.cfg
5
+ recursive-include accsify_tesseract *.py py.typed
6
+ recursive-include accsify_tesseract/lib *.dll *.exe *.lib
7
+ recursive-include accsify_tesseract/examples *.py *.png *.md
8
+ recursive-include tests *.py
@@ -0,0 +1,361 @@
1
+ Metadata-Version: 2.4
2
+ Name: accsify-tesseract
3
+ Version: 1.0.5.1
4
+ Summary: Official Python SDK and CLI for the Accsify Monolithic Tesseract OCR Engine
5
+ Home-page: https://github.com/accsify/tesseract
6
+ Author: accsify
7
+ Author-email: accsify <contact@accsify.com>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/accsify/tesseract
10
+ Project-URL: Documentation, https://github.com/accsify/tesseract#readme
11
+ Project-URL: Repository, https://github.com/accsify/tesseract.git
12
+ Project-URL: Issues, https://github.com/accsify/tesseract/issues
13
+ Keywords: ocr,tesseract,text-recognition,computer-vision,accsify,layout-analysis
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Programming Language :: Python :: 3.15
26
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: pillow>=9.0.0
31
+ Dynamic: author
32
+ Dynamic: home-page
33
+ Dynamic: license-file
34
+ Dynamic: requires-python
35
+
36
+ # accsify-tesseract
37
+
38
+ Official high-performance Python package and CLI for the **Accsify Tesseract OCR Engine**.
39
+
40
+ [![PyPI version](https://img.shields.io/badge/pypi-v5.5.0.1-blue.svg)](https://pypi.org/project/accsify-tesseract/)
41
+ [![Python Versions](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue.svg)](https://pypi.org/)
42
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
43
+ [![Platform](https://img.shields.io/badge/platform-Windows%20x64%20%7C%20x86-green.svg)](https://microsoft.com)
44
+
45
+ ---
46
+
47
+ ## 1. Overview
48
+
49
+ `accsify-tesseract` is a modern, object-oriented Python SDK built on top of the monolithic `tesseract_engine.dll` Windows dynamic link library. It provides thread-safe OCR recognition, structured document layout hierarchy, native Windows WinHTTP streaming model downloads, multi-image batch processing, and multi-language support.
50
+
51
+ ### Key Highlights
52
+ * **Zero Runtime External Dependencies**: The underlying native engine is statically linked with `/MT` (MSVC C/C++ Static Runtime). No Visual C++ Redistributable or external DLLs are needed.
53
+ * **Structured JSON & Dictionary Outputs**: Extract full page layout, words, confidences, bounding boxes, textline orders, and writing directions (LTR, RTL, TTB) directly into typed Python dictionaries or JSON.
54
+ * **Concurrent Model Flavors**: Download and store both **fast** (`tessdata_fast`) and **best** (`tessdata_best`) models simultaneously in separated subdirectories without file collisions.
55
+ * **Multi-Language OCR**: Seamlessly combine languages with `+` (e.g. `ara+eng`), with automatic downloading of missing language components.
56
+ * **Multi-Image Batch Processing**: High-throughput processing of image lists with unified structured results via `recognize_batch()`.
57
+ * **Native WinHTTP Downloader**: Download traineddata models with real-time progress callbacks and cancel tokens directly from official repositories over HTTPS.
58
+ * **Universal Image Support**: Directly load file paths (`str`, `Path`), raw encoded bytes (`bytes`, `bytearray`), PIL Images (`PIL.Image`), and NumPy image arrays (OpenCV `ndarray`).
59
+
60
+ ---
61
+
62
+ ## 2. Installation
63
+
64
+ ### From PyPI
65
+ ```bash
66
+ pip install accsify-tesseract
67
+ ```
68
+
69
+ ### From Local Source (Editable Mode)
70
+ ```bash
71
+ cd d:\projects\c++\tesseract\python
72
+ pip install -e .
73
+ ```
74
+
75
+ The package automatically discovers and loads `tesseract_engine.dll` from `dist/x64/`, `dist/x86/`, `bin/`, or standard Windows search paths based on whether you are running a 64-bit or 32-bit Python interpreter.
76
+
77
+ ---
78
+
79
+ ## 3. Quickstart
80
+
81
+ ### One-Liner Recognition
82
+ ```python
83
+ import accsify_tesseract as tess
84
+
85
+ # Extract plain text
86
+ text = tess.image_to_string("invoice.png", lang="eng")
87
+ print(text)
88
+
89
+ # Extract structured JSON string
90
+ json_str = tess.image_to_json("document.png", lang="eng")
91
+
92
+ # Extract structured dictionary with words and bounding boxes
93
+ data = tess.image_to_dict("document.png", lang="eng")
94
+ print(f"Mean confidence: {data['mean_confidence']}%")
95
+ for word in data["words"]:
96
+ print(f"Word: {word['text']}, Box: {word['bbox']}, Conf: {word['confidence']}%")
97
+ ```
98
+
99
+ ---
100
+
101
+ ## 4. Object-Oriented Engine Interface
102
+
103
+ The primary interface is `TesseractEngine`, implemented as a thread-safe context manager.
104
+
105
+ ```python
106
+ from pathlib import Path
107
+ from accsify_tesseract import TesseractEngine, PageSegMode, ModelType
108
+
109
+ # Open engine with specific language and model flavor
110
+ with TesseractEngine(language="eng", flavor=ModelType.FAST) as engine:
111
+ engine.set_page_seg_mode(PageSegMode.AUTO)
112
+
113
+ # Load image from file path, bytes, PIL Image, or OpenCV ndarray
114
+ engine.set_image(Path("document.png"))
115
+
116
+ # Run recognition pipeline
117
+ engine.recognize()
118
+
119
+ # Retrieve outputs
120
+ text = engine.get_text()
121
+ mean_conf = engine.get_mean_confidence()
122
+ hocr = engine.get_hocr(page_num=0)
123
+ tsv = engine.get_tsv(page_num=0)
124
+
125
+ print(f"Confidence: {mean_conf}%")
126
+ print(text)
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 5. Structured JSON & Dictionary Extraction
132
+
133
+ `TesseractEngine.get_json()` and `TesseractEngine.get_structured_dict()` return deep structured layout information natively generated by the C++ engine:
134
+
135
+ ```python
136
+ with TesseractEngine(language="eng") as engine:
137
+ engine.set_image("sample.png")
138
+
139
+ # Get Python dictionary
140
+ doc = engine.get_structured_dict()
141
+
142
+ print(f"Total Text: {doc['text']}")
143
+ print(f"Mean Confidence: {doc['mean_confidence']}%")
144
+ print(f"PSM: {doc['psm']}")
145
+
146
+ for w in doc["words"]:
147
+ print(f"Word: {w['text']:<20} Conf: {w['confidence']:<6.1f} Box: {w['bbox']} Direction: {w['direction']}")
148
+ ```
149
+
150
+ ### JSON Schema Specification
151
+ ```json
152
+ {
153
+ "text": "Full extracted UTF-8 document text...",
154
+ "mean_confidence": 94,
155
+ "psm": 3,
156
+ "words": [
157
+ {
158
+ "text": "Accsify",
159
+ "confidence": 98.4,
160
+ "bbox": [120, 45, 230, 78],
161
+ "direction": "LeftToRight",
162
+ "order": "LTR",
163
+ "deskew_angle": 0.00012
164
+ }
165
+ ]
166
+ }
167
+ ```
168
+
169
+ ---
170
+
171
+ ## 6. Multi-Image Batch Processing
172
+
173
+ Process dozens or hundreds of images in a single session without recreating the engine:
174
+
175
+ ```python
176
+ from accsify_tesseract import TesseractEngine
177
+
178
+ images = ["page1.png", "page2.png", "page3.png"]
179
+
180
+ with TesseractEngine(language="eng") as engine:
181
+ batch_results = engine.recognize_batch(images)
182
+
183
+ for res in batch_results:
184
+ print(f"\n--- Result for: {res.image_path} ---")
185
+ print(f"Confidence: {res.mean_confidence}% | Words: {res.words_count}")
186
+ print(res.text[:150]) # preview first 150 chars
187
+
188
+ # Export individual image result to JSON or dict
189
+ json_payload = res.to_json(indent=2)
190
+ ```
191
+
192
+ ---
193
+
194
+ ## 7. Multi-Language Combination & Auto-Download
195
+
196
+ You can combine multiple languages using the `+` operator. With `auto_download=True`, the engine automatically verifies and downloads any missing language before initializing:
197
+
198
+ ```python
199
+ from accsify_tesseract import TesseractEngine, ModelType
200
+
201
+ # Combined Arabic and English recognition with auto-downloading
202
+ with TesseractEngine(language="ara+eng", flavor=ModelType.BEST, auto_download=True) as engine:
203
+ engine.set_image("bilingual_contract.png")
204
+ engine.recognize()
205
+ print(engine.get_text())
206
+ ```
207
+
208
+ ---
209
+
210
+ ## 8. Model Management & Storage Organization
211
+
212
+ Accsify Tesseract organizes models into structured subdirectories under the active `tessdata/` path to prevent collisions between different versions of the same language:
213
+
214
+ ```
215
+ tessdata/
216
+ ├── fast/ # Compact models (~1-5 MB)
217
+ │ ├── eng.traineddata
218
+ │ └── ara.traineddata
219
+ ├── best/ # High-accuracy full LSTM models (~15-40 MB)
220
+ │ ├── eng.traineddata
221
+ │ └── ara.traineddata
222
+ ├── script/ # Script-specific models
223
+ │ └── Arabic.traineddata
224
+ └── standard/ # Standard release models
225
+ ```
226
+
227
+ ### Querying Catalog & Downloading
228
+ ```python
229
+ from accsify_tesseract import ModelManager, ModelType
230
+
231
+ # 1. Inspect installed models
232
+ installed = ModelManager.list_installed()
233
+ print("Installed models:", installed)
234
+
235
+ # 2. Query available catalog models
236
+ catalog = ModelManager.list_catalog(ModelType.FAST)
237
+ for m in catalog:
238
+ print(f"{m.name:<15} {m.display_name:<30} {m.file_size_mb:.1f} MB (Installed: {m.is_installed})")
239
+
240
+ # 3. Live progress callback
241
+ def my_progress(name, model_type, downloaded, total, pct, status):
242
+ print(f"\rDownloading {name}: {pct:.1f}% ({downloaded / 1024 / 1024:.2f} MB)", end="")
243
+ return True # return False to cancel download
244
+
245
+ # 4. Download fast Arabic model
246
+ ModelManager.download("ara", model_type=ModelType.FAST, progress_callback=my_progress)
247
+
248
+ # 5. Download best Arabic model (stored in tessdata/best/ara.traineddata without overwriting fast!)
249
+ ModelManager.download("ara", model_type=ModelType.BEST, progress_callback=my_progress)
250
+
251
+ # 6. Download multiple models in one call
252
+ ModelManager.download_many(["eng", "fra", "deu"], model_type=ModelType.FAST)
253
+
254
+ # 7. Configure custom storage directory
255
+ ModelManager.set_path("D:/my_models/tessdata")
256
+ print("Active path:", ModelManager.get_path())
257
+ ```
258
+
259
+ ---
260
+
261
+ ## 9. Layout Analysis & Bounding Boxes
262
+
263
+ Analyze the full page geometry across 5 hierarchy levels: `BLOCK`, `PARA`, `TEXTLINE`, `WORD`, `SYMBOL`.
264
+
265
+ ```python
266
+ from accsify_tesseract import TesseractEngine, PageIteratorLevel, WritingDirection
267
+
268
+ with TesseractEngine(language="ara+eng") as engine:
269
+ engine.set_image("mixed_layout.png")
270
+ layout = engine.analyse_layout(level=PageIteratorLevel.WORD)
271
+
272
+ print(f"Discovered {len(layout.words)} words, {len(layout.lines)} lines")
273
+
274
+ for word in layout.words:
275
+ b = word.bbox
276
+ is_rtl = word.writing_direction == WritingDirection.RIGHT_TO_LEFT
277
+ dir_label = "RTL (Arabic)" if is_rtl else "LTR (Latin)"
278
+
279
+ print(f"[{b.left}, {b.top}, {b.right}, {b.bottom}] {word.text:<25} Conf: {word.confidence:.1f}% Dir: {dir_label}")
280
+
281
+ # Export full layout to JSON
282
+ json_layout = layout.to_json(indent=2)
283
+ ```
284
+
285
+ ---
286
+
287
+ ## 10. Orientation and Script Detection (OSD)
288
+
289
+ Detect page rotation degrees (0°, 90°, 180°, 270°) and identify the primary script:
290
+
291
+ ```python
292
+ from accsify_tesseract import TesseractEngine, PageSegMode
293
+
294
+ with TesseractEngine(language="osd") as engine:
295
+ engine.set_page_seg_mode(PageSegMode.OSD_ONLY)
296
+ engine.set_image("scanned_page.png")
297
+
298
+ osd = engine.detect_orientation_and_script()
299
+ print(f"Orientation : {osd.orientation_deg}° (Confidence: {osd.orientation_confidence})")
300
+ print(f"Script : {osd.script_name} (Confidence: {osd.script_confidence})")
301
+ print(f"Is Upright : {osd.is_upright}")
302
+
303
+ # Export to dict or JSON
304
+ print(osd.to_dict())
305
+ ```
306
+
307
+ ---
308
+
309
+ ## 11. Command-Line Interface (CLI)
310
+
311
+ The package provides the `accsify-tesseract` console script:
312
+
313
+ ```bash
314
+ # 1. OCR a single image
315
+ accsify-tesseract ocr invoice.png -l eng
316
+
317
+ # 2. Batch OCR multiple images to structured JSON
318
+ accsify-tesseract ocr page1.png page2.png page3.png -l eng --format json -o batch_result.json
319
+
320
+ # 3. Multi-language OCR with high-accuracy 'best' model
321
+ accsify-tesseract ocr contract.png -l "ara+eng" --flavor best
322
+
323
+ # 4. Detailed layout inspection
324
+ accsify-tesseract layout document.png -l eng --format json
325
+
326
+ # 5. Detect page orientation and script
327
+ accsify-tesseract osd scanned.png
328
+
329
+ # 6. List and download models
330
+ accsify-tesseract models list --type fast
331
+ accsify-tesseract models download ara --type best
332
+ accsify-tesseract models installed
333
+ accsify-tesseract models path --set-path "D:\tessdata"
334
+ ```
335
+
336
+ ---
337
+
338
+ ## 12. Exception Hierarchy
339
+
340
+ ```python
341
+ from accsify_tesseract import (
342
+ TesseractError, # Base exception for all errors
343
+ EngineInitError, # Failed to initialize engine (missing traineddata, invalid path)
344
+ ImageLoadError, # Image file missing or corrupted
345
+ RecognitionError, # OCR recognition failure
346
+ ModelDownloadError, # Network / WinHTTP download failure
347
+ ModelNotFoundError # Requested model not found in catalog
348
+ )
349
+
350
+ try:
351
+ with TesseractEngine(language="nonexistent") as engine:
352
+ engine.set_image("sample.png")
353
+ except EngineInitError as e:
354
+ print(f"Initialization error for {e.language} in {e.datapath}: {e}")
355
+ ```
356
+
357
+ ---
358
+
359
+ ## 13. License
360
+
361
+ Distributed under the **MIT License**. Copyright (C) 2026 **accsify**. All rights reserved.