@qvac/ocr-ggml 0.0.1 → 0.1.1

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 (57) hide show
  1. package/LICENSE +179 -0
  2. package/NOTICE +63 -0
  3. package/README.md +330 -0
  4. package/addonLogging.d.ts +7 -0
  5. package/addonLogging.js +4 -0
  6. package/binding.js +21 -0
  7. package/index.d.ts +145 -0
  8. package/index.js +383 -0
  9. package/lib/error.js +80 -0
  10. package/ocr-ggml.js +121 -0
  11. package/package.json +96 -7
  12. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.0_1.so +0 -0
  13. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.2_1.so +0 -0
  14. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.2_2.so +0 -0
  15. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.6_1.so +0 -0
  16. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv9.0_1.so +0 -0
  17. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv9.2_1.so +0 -0
  18. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv9.2_2.so +0 -0
  19. package/prebuilds/android-arm64/qvac__ocr-ggml.bare +0 -0
  20. package/prebuilds/darwin-arm64/qvac__ocr-ggml.bare +0 -0
  21. package/prebuilds/darwin-arm64/qvac__ocr-ggml.bare.exports +4277 -0
  22. package/prebuilds/darwin-x64/qvac__ocr-ggml.bare +0 -0
  23. package/prebuilds/darwin-x64/qvac__ocr-ggml.bare.exports +4322 -0
  24. package/prebuilds/ios-arm64/qvac__ocr-ggml.bare +0 -0
  25. package/prebuilds/ios-arm64/qvac__ocr-ggml.bare.exports +4262 -0
  26. package/prebuilds/ios-arm64-simulator/qvac__ocr-ggml.bare +0 -0
  27. package/prebuilds/ios-arm64-simulator/qvac__ocr-ggml.bare.exports +4262 -0
  28. package/prebuilds/ios-x64-simulator/qvac__ocr-ggml.bare +0 -0
  29. package/prebuilds/ios-x64-simulator/qvac__ocr-ggml.bare.exports +4311 -0
  30. package/prebuilds/linux-arm64/qvac__ocr-ggml.bare +0 -0
  31. package/prebuilds/linux-x64/qvac__ocr-ggml.bare +0 -0
  32. package/prebuilds/win32-x64/qvac__ocr-ggml.bare +0 -0
  33. package/prebuilds/win32-x64/qvac__ocr-ggml.bare.exports +0 -0
  34. package/test/integration/canvas-size.test.js +75 -0
  35. package/test/integration/doctr-basic.test.js +124 -0
  36. package/test/integration/doctr-clinical-chemistry.test.js +64 -0
  37. package/test/integration/doctr-ct-scan.test.js +66 -0
  38. package/test/integration/doctr-lab-results.test.js +65 -0
  39. package/test/integration/doctr-liver-function.test.js +67 -0
  40. package/test/integration/doctr-models.test.js +132 -0
  41. package/test/integration/doctr-param-validation.test.js +83 -0
  42. package/test/integration/error-handling.test.js +302 -0
  43. package/test/integration/full-coverage.test.js +292 -0
  44. package/test/integration/full-ocr-suite.test.js +83 -0
  45. package/test/integration/image-formats.test.js +168 -0
  46. package/test/integration/large-images.test.js +81 -0
  47. package/test/integration/lifecycle.test.js +269 -0
  48. package/test/integration/ocr-basic.test.js +70 -0
  49. package/test/integration/param-validation.test.js +86 -0
  50. package/test/integration/pipeline.test.js +61 -0
  51. package/test/integration/run-internal-ordering.test.js +75 -0
  52. package/test/integration/run-tests.sh +43 -0
  53. package/test/integration/run-with-exit.js +71 -0
  54. package/test/integration/utils.js +694 -0
  55. package/test/mobile/integration-runtime.cjs +71 -0
  56. package/test/mobile/integration.auto.cjs +102 -0
  57. package/test/mobile/test-groups.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,179 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Tether Data, S.A. de C.V.
package/NOTICE ADDED
@@ -0,0 +1,63 @@
1
+ @qvac/ocr-ggml
2
+ Copyright (C) Tether Operations Limited
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"). You may
5
+ obtain a copy of the License at:
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ License for the specific language governing permissions and limitations
13
+ under the License.
14
+
15
+ ----------------------------------------------------------------------
16
+ Third-party components and provenance
17
+ ----------------------------------------------------------------------
18
+
19
+ This package incorporates source code lifted, with adaptation, from the
20
+ following projects. Each component retains its own license; the project
21
+ links cited below contain the canonical license text.
22
+
23
+ 1. EasyOCR (Apache License 2.0)
24
+ https://github.com/JaidedAI/EasyOCR
25
+ The detection (CRAFT) and recognition (CRNN gen-2) pipeline shape,
26
+ pre/post-processing math, and language tables in
27
+ `addon/src/pipeline/*` and `addon/src/easyocr-ggml/*` are derived
28
+ from the upstream EasyOCR Python reference.
29
+
30
+ 2. EasyOcr-ggml (Apache License 2.0)
31
+ https://github.com/tetherto/easy-ocr-ggml
32
+ The GGML graph builders, GGUF weight loaders, and BN-folded weight
33
+ tables in `addon/src/ggml/*` and `addon/src/easyocr-ggml/*` are
34
+ lifted verbatim (with minor namespace adjustments) from this sibling
35
+ project.
36
+
37
+ 3. ggml (MIT License)
38
+ https://github.com/ggml-org/ggml
39
+ Consumed at build time via `qvac-fabric`'s vcpkg port. The dynamic
40
+ backend shared libraries shipped under `prebuilds/` (CPU, Vulkan,
41
+ OpenCL, …) are ggml's outputs and inherit ggml's MIT license.
42
+
43
+ 4. OpenCV (Apache License 2.0)
44
+ https://github.com/opencv/opencv
45
+ Consumed at build time via vcpkg's `opencv4` port. Used for image
46
+ decode, geometric transforms, and connected-component analysis in
47
+ the detection / bounding-box pipeline.
48
+
49
+ 5. @qvac/inference-addon-cpp (Apache License 2.0)
50
+ https://github.com/tetherto/qvac-lib-inference-addon-cpp
51
+ Provides the `IModel`, `JsInterface`, and output-handler base
52
+ classes that the C++ side of this addon inherits from.
53
+
54
+ 6. @qvac/translation-nmtcpp (Apache License 2.0)
55
+ https://github.com/tetherto/qvac/tree/main/packages/translation-nmtcpp
56
+ Build / vcpkg / triplet / bare-module plumbing in this package is
57
+ adapted from the sibling translation addon.
58
+
59
+ 7. @qvac/ocr-onnx (Apache License 2.0)
60
+ https://github.com/tetherto/qvac/tree/main/packages/ocr-onnx
61
+ The JS-side public surface (constructor shape, image-decode
62
+ convention, output row schema) is modelled after this sibling so
63
+ downstream callers can swap engines transparently.
package/README.md ADDED
@@ -0,0 +1,330 @@
1
+ # @qvac/ocr-ggml
2
+
3
+ GGML-backed OCR addon for [QVAC](https://github.com/tetherto/qvac).
4
+ Provides two inference pipelines on **`ggml` / `.gguf`** — no Python, no
5
+ PyTorch, and no ONNX Runtime at runtime:
6
+
7
+ | Pipeline | Detector | Recognizer | Notes |
8
+ |---|---|---|---|
9
+ | `easyocr` (default) | CRAFT | CRNN gen-2 (English / Latin) | Port of [EasyOCR](https://github.com/JaidedAI/EasyOCR) |
10
+ | `doctr` | DBNet (MobileNetV3-Large) | CRNN (MobileNetV3-Small) | Port of [doctr](https://github.com/mindee/doctr) |
11
+
12
+ Select the pipeline at construction time via `params.pipelineType`
13
+ (default `'easyocr'`). Both pipelines emit the same output shape.
14
+
15
+ Sibling of [`@qvac/ocr-onnx`](../ocr-onnx). Same input/output shape, same
16
+ public surface — only the inference engine differs.
17
+
18
+ | | `@qvac/ocr-onnx` | `@qvac/ocr-ggml` |
19
+ |---|---|---|
20
+ | Inference backend | ONNX Runtime | GGML |
21
+ | Weight format | `.onnx` | `.gguf` |
22
+ | Pre/post-processing | C++ + OpenCV (EasyOCR) | C++ + OpenCV (EasyOCR + doctr, lifted) |
23
+ | Quantization | per-EP (limited) | block-quantized (Q8_0, Q4_K, …) out of the box |
24
+ | Pipelines | EasyOCR | EasyOCR + Doctr |
25
+
26
+ The C++ implementation is lifted from
27
+ [`EasyOcr-ggml`](https://github.com/tetherto/easy-ocr-ggml); GGML is pulled
28
+ from `qvac-fabric` (instead of the upstream submodule), matching how the
29
+ sibling `translation-nmtcpp` addon consumes ggml.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ npm install @qvac/ocr-ggml
35
+ ```
36
+
37
+ The package ships a Bare addon. Build prerequisites (clang-22, libc++,
38
+ vcpkg, bare-make) match the rest of the QVAC monorepo — see the
39
+ [root README](../../README.md) for the canonical setup.
40
+
41
+ ```bash
42
+ cd packages/ocr-ggml
43
+ npm install
44
+ bare-make generate
45
+ bare-make build
46
+ bare-make install # produces prebuilds/
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ```js
52
+ const { OcrGgml } = require('@qvac/ocr-ggml')
53
+
54
+ const ocr = new OcrGgml({
55
+ params: {
56
+ pathDetector: '/abs/path/craft_mlt_25k.gguf',
57
+ pathRecognizer: '/abs/path/english_g2.gguf',
58
+ langList: ['en'],
59
+ magRatio: 1.5
60
+ },
61
+ opts: { stats: true }
62
+ })
63
+
64
+ await ocr.load()
65
+
66
+ const response = await ocr.run({
67
+ path: '/abs/path/photo.jpg',
68
+ options: { paragraph: false }
69
+ })
70
+
71
+ response.onUpdate(rows => {
72
+ for (const [box, text, conf] of rows) {
73
+ console.log(`[${conf.toFixed(2)}] ${text}`, box)
74
+ }
75
+ })
76
+
77
+ const stats = await response.await()
78
+ console.log(stats)
79
+
80
+ await ocr.unload()
81
+ ```
82
+
83
+ ### Quickstart example
84
+
85
+ ```bash
86
+ bare examples/quickstart.js \
87
+ --image samples/english.png \
88
+ --detector models/craft_mlt_25k.gguf \
89
+ --recognizer models/english_g2.gguf \
90
+ --lang en
91
+ ```
92
+
93
+ ## API
94
+
95
+ ### `new OcrGgml({ params, opts?, logger? })`
96
+
97
+ | Field | Type | Required | Default | Description |
98
+ |---|---|:-:|---|---|
99
+ | `params.pathDetector` | `string` | ✓ | — | detector `.gguf` (CRAFT for `easyocr`, DBNet for `doctr`) |
100
+ | `params.pathRecognizer` | `string` | ✓ | — | recognizer `.gguf` (`english_g2`/`latin_g2` for `easyocr`, doctr CRNN for `doctr`) |
101
+ | `params.langList` | `string[]` | ✓ | — | language codes (`['en']`, `['en','fr']`, …) — used by `easyocr`, ignored by `doctr` |
102
+ | `params.pipelineType` | `'easyocr'` \| `'doctr'` | | `'easyocr'` | which pipeline backs the addon |
103
+ | `params.magRatio` | `number` | | `1.5` | CRAFT input-image magnification (`easyocr` only) |
104
+ | `params.defaultRotationAngles` | `number[]` | | `[90, 270]` | rotations tried on low-confidence boxes (`easyocr` only) |
105
+ | `params.contrastRetry` | `boolean` | | `false` | retry low-confidence boxes with contrast adjustment (`easyocr` only) |
106
+ | `params.lowConfidenceThreshold` | `number` | | `0.4` | retry threshold (`easyocr` only) |
107
+ | `params.recognizerBatchSize` | `number` | | `32` | recognizer batch size (`easyocr` only) |
108
+ | `params.nThreads` | `number` | | `0` (auto) | CPU thread count for GGML; `<0` leaves the GGML default |
109
+ | `params.backendsDir` | `string` | | `<package>/prebuilds` | directory holding `libggml-*.so` backend shared libs |
110
+ | `opts.stats` | `boolean` | | `false` | emit timing stats on `finish` |
111
+ | `logger` | `Object` | | `null` | optional `{ info, warn, error, debug }` — receives C++ log lines |
112
+
113
+ ### Methods
114
+
115
+ - `load(): Promise<void>` — loads both models, registers ggml backends, activates the addon
116
+ - `run(input): Promise<QvacResponse>` — serialised; one job at a time
117
+ - `unload(): Promise<void>` — frees the addon (destroys ggml contexts + backends)
118
+ - `destroy(): Promise<void>` — marks the instance as destroyed (no further use)
119
+ - `getState(): InferenceClientState`
120
+ - `OcrGgml.getModelKey(): string` — `"ocr-ggml"`, used by the inference manager
121
+
122
+ ### `run(input)` shape
123
+
124
+ ```ts
125
+ {
126
+ path: string, // JPEG / PNG / BMP file
127
+ options?: {
128
+ paragraph?: boolean, // merge nearby boxes
129
+ boxMarginMultiplier?: number, // padding around boxes
130
+ rotationAngles?: number[] // override defaults for this call
131
+ }
132
+ }
133
+ ```
134
+
135
+ Output rows (delivered via `response.onUpdate`):
136
+
137
+ ```ts
138
+ type InferredText = [
139
+ [[number, number], [number, number], [number, number], [number, number]], // 4-point box
140
+ string, // text
141
+ number // confidence [0..1]
142
+ ]
143
+ ```
144
+
145
+ This is byte-for-byte the same shape `@qvac/ocr-onnx` returns.
146
+
147
+ ### Stats (when `opts.stats=true`)
148
+
149
+ ```ts
150
+ {
151
+ totalTime: number, // seconds
152
+ detectionTime: number, // seconds (CRAFT inference)
153
+ recognitionTime: number, // seconds (CRNN inference)
154
+ numBoxes: number // total boxes (aligned + unaligned)
155
+ }
156
+ ```
157
+
158
+ ## Models
159
+
160
+ The addon consumes GGUF weight files. Each pipeline expects its own
161
+ detector + recognizer pair:
162
+
163
+ ### EasyOCR pipeline (`pipelineType: 'easyocr'`)
164
+
165
+ | GGUF | Role |
166
+ |---|---|
167
+ | `craft_mlt_25k.gguf` / `*_q8_0.gguf` / `*_q4_k.gguf` | CRAFT detector |
168
+ | `english_g2.gguf` / `*_q8_0.gguf` / `*_q4_k.gguf` | English recognizer (gen-2) |
169
+ | `latin_g2.gguf` | Latin-script recognizer (gen-2; fr/de/it/es/pt/…) |
170
+
171
+ Use the converter in the upstream
172
+ [`tetherto/easy-ocr-ggml`](https://github.com/tetherto/easy-ocr-ggml/blob/main/scripts/pth_to_gguf.py)
173
+ repo (`scripts/pth_to_gguf.py`) to produce these from EasyOCR PyTorch
174
+ `.pth` checkpoints.
175
+
176
+ This first release ships the **gen-2 recognizer family only** (English /
177
+ Latin). Other language groups (Arabic, Bengali, Cyrillic, Devanagari, CJK)
178
+ will land as GGUFs are produced.
179
+
180
+ ### Doctr pipeline (`pipelineType: 'doctr'`)
181
+
182
+ | GGUF | Role |
183
+ |---|---|
184
+ | `db_mobilenet_v3_large.gguf` | DBNet detector (MobileNetV3-Large backbone) |
185
+ | `crnn_mobilenet_v3_small.gguf` | doctr recognizer (MobileNetV3-Small backbone) |
186
+
187
+ Doctr is language-agnostic: it recognises any Latin-script text the
188
+ underlying CRNN was trained on, so it ignores `langList`, `magRatio` and
189
+ the contrast-retry / rotation knobs.
190
+
191
+ ### CI distribution
192
+
193
+ CI pulls pinned snapshots of both the EasyOCR and Doctr GGUFs from S3
194
+ (see [`.github/workflows/integration-test-ocr-ggml.yml`](../../.github/workflows/integration-test-ocr-ggml.yml))
195
+ and exposes them to the integration suite via the
196
+ `OCR_GGML_DETECTOR` + `OCR_GGML_RECOGNIZER` env vars (EasyOCR) and
197
+ `OCR_GGML_DOCTR_DETECTOR` + `OCR_GGML_DOCTR_RECOGNIZER` env vars
198
+ (Doctr). Both pipelines are exercised end-to-end on every PR.
199
+
200
+ ## CLI
201
+
202
+ A development-time CLI ships at the package root, `ocr-ggml-cli`, modelled
203
+ on `@qvac/translation-nmtcpp`'s `nmt-cli`. It is **not** included in the
204
+ npm artifact (same convention as `nmt-cli`); run it directly from the
205
+ repository checkout:
206
+
207
+ ```bash
208
+ # Default: OCR samples/english.png with bundled English weights (easyocr)
209
+ bare ocr-ggml-cli
210
+
211
+ # Doctr pipeline (DBNet detector + doctr recognizer)
212
+ bare ocr-ggml-cli --pipeline-type doctr \
213
+ --detector models/db_mobilenet_v3_large.gguf \
214
+ --recognizer models/crnn_mobilenet_v3_small.gguf \
215
+ --image /tmp/photo.jpg
216
+
217
+ # Detail mode (index + confidence + box per recognised line)
218
+ bare ocr-ggml-cli --detail 1
219
+
220
+ # JSON output (matches EasyOCR Python's readtext shape)
221
+ bare ocr-ggml-cli --output-format json | jq .
222
+
223
+ # Custom image + Q8_0 quantized EasyOCR models
224
+ bare ocr-ggml-cli --image /tmp/photo.jpg \
225
+ --detector models/craft_mlt_25k_q8_0.gguf \
226
+ --recognizer models/english_g2_q8_0.gguf
227
+
228
+ # Force a specific CPU thread count, with verbose C++ logs
229
+ bare ocr-ggml-cli --n-threads 8 --verbose
230
+
231
+ # Show help / version
232
+ bare ocr-ggml-cli --help
233
+ bare ocr-ggml-cli --version
234
+ ```
235
+
236
+ The CLI is functionally equivalent to upstream `EasyOcr-ggml`'s `ocr-cli`
237
+ binary — same flag surface (`--image`, `--detector`, `--recognizer`,
238
+ `--lang`, `--paragraph`, `--mag-ratio`, `--detail`, `--output-format`,
239
+ `--n-threads`) plus `--pipeline-type {easyocr,doctr}` for the second
240
+ pipeline, and the `nmt-cli` ergonomics (env-var fallbacks
241
+ `OCR_GGML_{IMAGE,DETECTOR,RECOGNIZER,PIPELINE_TYPE}`, `-h/--help`,
242
+ `-v/--version`, `--verbose` for C++ log forwarding). One deliberate
243
+ omission for v1: `--debug-png` (annotated overlay) — print boxes via
244
+ `--detail 1` or `--output-format json` and render externally instead.
245
+
246
+ ## Scripts
247
+
248
+ | Script | Purpose |
249
+ |---|---|
250
+ | [`scripts/check_ggml_backends.sh`](./scripts/check_ggml_backends.sh) | Probe shipped ggml backends + BLAS/Vulkan/OpenCL paths in `prebuilds/` |
251
+
252
+ Full usage in [`scripts/README.md`](./scripts/README.md). For weight
253
+ conversion (PyTorch `.pth` → GGUF), use the upstream converter in
254
+ [`tetherto/easy-ocr-ggml`](https://github.com/tetherto/easy-ocr-ggml/blob/main/scripts/pth_to_gguf.py).
255
+
256
+ ## Testing
257
+
258
+ ```bash
259
+ npm run lint
260
+ npm run test:unit # JS unit tests (no models required)
261
+ npm run test:integration # end-to-end smoke; soft-skips when models absent
262
+ npm run test:cpp # C++ GoogleTest (BUILD_TESTING=ON)
263
+ ```
264
+
265
+ The integration smoke test reads the following env vars and runs each
266
+ case only when the corresponding GGUFs are present on disk:
267
+
268
+ | Env var | Pipeline | Required for which test |
269
+ |---|---|---|
270
+ | `OCR_GGML_DETECTOR` | EasyOCR | EasyOCR case |
271
+ | `OCR_GGML_RECOGNIZER` | EasyOCR | EasyOCR case (CI uses `latin_g2.gguf`) |
272
+ | `OCR_GGML_DOCTR_DETECTOR` | Doctr | Doctr case |
273
+ | `OCR_GGML_DOCTR_RECOGNIZER` | Doctr | Doctr case |
274
+ | `OCR_GGML_IMAGE` | — | overrides the default sample image |
275
+
276
+ CI sets these automatically; locally you can:
277
+
278
+ ```bash
279
+ OCR_GGML_DETECTOR=$PWD/models/craft_mlt_25k.gguf \
280
+ OCR_GGML_RECOGNIZER=$PWD/models/latin_g2.gguf \
281
+ npm run test:integration
282
+ ```
283
+
284
+ ## Repository layout
285
+
286
+ ```
287
+ packages/ocr-ggml/
288
+ ├── package.json # @qvac/ocr-ggml (bare addon)
289
+ ├── CMakeLists.txt # bare_module(ocr-ggml), links ggml + opencv4
290
+ ├── vcpkg.json # ggml from qvac-fabric, opencv4, inference-addon-cpp
291
+ ├── vcpkg-configuration.json
292
+ ├── vcpkg/ # custom triplets + toolchains
293
+ ├── ocr-ggml-cli # dev-time CLI (mirrors nmt-cli), not shipped to npm
294
+ ├── binding.js # require.addon() entry
295
+ ├── index.js, index.d.ts # public JS surface (OcrGgml class)
296
+ ├── ocr-ggml.js # thin wrapper over the bare binding
297
+ ├── addonLogging.{js,d.ts} # setLogger / releaseLogger surface
298
+ ├── lib/error.js # QvacErrorAddonOcrGgml + ERR_CODES
299
+ ├── examples/quickstart.js # JS code example
300
+ ├── samples/ # sample fixture images (english.png, …)
301
+ ├── scripts/ # check_ggml_backends.sh diagnostic
302
+ ├── test/{unit,integration}
303
+ └── addon/src/
304
+ ├── js-interface/binding.cpp # BARE_MODULE entry
305
+ ├── addon/AddonJs.hpp # createInstance / runJob / output handler
306
+ ├── model-interface/
307
+ │ ├── OcrTypes.hpp # shared OcrInput/OcrConfig + PipelineMode enum
308
+ │ └── Pipeline.{hpp,cpp} # unified IModel adapter (EasyOCR + DocTR via mode)
309
+ ├── ggml/ # gguf_loader, ops, craft, crnn, weights (lifted)
310
+ ├── pipeline/ # lang, steps, step_* (EasyOCR; lifted)
311
+ ├── easyocr-ggml/ # headers for the EasyOCR lifted code
312
+ └── doctr-ggml/ # MobileNetGraph + DBNet/CRNN steps
313
+ ```
314
+
315
+ ## Provenance
316
+
317
+ - **C++ pipeline + GGML graph code** lifted from
318
+ [`tetherto/easy-ocr-ggml`](https://github.com/tetherto/easy-ocr-ggml)
319
+ (Apache-2.0).
320
+ - **Build / addon plumbing** modelled on
321
+ [`@qvac/translation-nmtcpp`](../translation-nmtcpp) (ggml from
322
+ `qvac-fabric`, `cmake-bare` + `cmake-vcpkg`, `inference-addon-cpp` base
323
+ classes).
324
+ - **Public JS surface** modelled on
325
+ [`@qvac/ocr-onnx`](../ocr-onnx) so callers can swap engines transparently.
326
+
327
+ ## License
328
+
329
+ Apache-2.0 (matches upstream EasyOCR, `EasyOcr-ggml`, `@qvac/ocr-onnx`, and
330
+ `@qvac/translation-nmtcpp`).
@@ -0,0 +1,7 @@
1
+ export interface AddonLogging {
2
+ setLogger(callback: (priority: number, message: string) => void): void
3
+ releaseLogger(): void
4
+ }
5
+
6
+ declare const addonLogging: AddonLogging
7
+ export default addonLogging
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ get setLogger () { return require('./binding').setLogger },
3
+ get releaseLogger () { return require('./binding').releaseLogger }
4
+ }
package/binding.js ADDED
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ try {
4
+ module.exports = require.addon()
5
+ } catch (e) {
6
+ const c = e && e.cause
7
+ console.log('[OCR-DLOPEN-DEBUG] error:', e && e.message)
8
+ console.log('[OCR-DLOPEN-DEBUG] error.code:', e && e.code)
9
+ console.log('[OCR-DLOPEN-DEBUG] cause:', c)
10
+ console.log('[OCR-DLOPEN-DEBUG] cause.message:', c && c.message)
11
+ console.log('[OCR-DLOPEN-DEBUG] cause.code:', c && c.code)
12
+ console.log('[OCR-DLOPEN-DEBUG] cause.errno:', c && c.errno)
13
+ console.log('[OCR-DLOPEN-DEBUG] cause.path:', c && c.path)
14
+ console.log('[OCR-DLOPEN-DEBUG] cause.syscall:', c && c.syscall)
15
+ console.log('[OCR-DLOPEN-DEBUG] cause.stack:', c && c.stack)
16
+ try {
17
+ console.log('[OCR-DLOPEN-DEBUG] cause.keys:', c && Object.getOwnPropertyNames(c))
18
+ console.log('[OCR-DLOPEN-DEBUG] cause.JSON:', c && JSON.stringify(c, Object.getOwnPropertyNames(c)))
19
+ } catch (_) {}
20
+ throw e
21
+ }