@imagowave/vision-ocr 0.0.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 (65) hide show
  1. package/NitroVisionOcr.podspec +32 -0
  2. package/README.md +38 -0
  3. package/android/CMakeLists.txt +31 -0
  4. package/android/build.gradle +143 -0
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  9. package/android/src/main/java/com/margelo/nitro/visionocr/NitroVisionOcrPackage.kt +18 -0
  10. package/android/src/main/java/com/margelo/nitro/visionocr/VisionOcr.kt +120 -0
  11. package/ios/Bridge.h +8 -0
  12. package/ios/VisionOCR.swift +137 -0
  13. package/nitro.json +19 -0
  14. package/nitrogen/generated/.gitattributes +1 -0
  15. package/nitrogen/generated/android/NitroVisionOcr+autolinking.cmake +81 -0
  16. package/nitrogen/generated/android/NitroVisionOcr+autolinking.gradle +27 -0
  17. package/nitrogen/generated/android/NitroVisionOcrOnLoad.cpp +41 -0
  18. package/nitrogen/generated/android/NitroVisionOcrOnLoad.hpp +34 -0
  19. package/nitrogen/generated/android/c++/JHybridVisionOCRSpec.cpp +87 -0
  20. package/nitrogen/generated/android/c++/JHybridVisionOCRSpec.hpp +63 -0
  21. package/nitrogen/generated/android/c++/JOcrBlock.hpp +91 -0
  22. package/nitrogen/generated/android/c++/JOcrBox.hpp +69 -0
  23. package/nitrogen/generated/android/c++/JOcrLine.hpp +93 -0
  24. package/nitrogen/generated/android/c++/JOcrOptions.hpp +95 -0
  25. package/nitrogen/generated/android/c++/JOcrResult.hpp +89 -0
  26. package/nitrogen/generated/android/c++/JOcrWord.hpp +68 -0
  27. package/nitrogen/generated/android/c++/JRLevel.hpp +58 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/HybridVisionOCRSpec.kt +55 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/NitroVisionOcrOnLoad.kt +35 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrBlock.kt +61 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrBox.kt +66 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrLine.kt +66 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrOptions.kt +71 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrResult.kt +56 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrWord.kt +61 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/RLevel.kt +23 -0
  37. package/nitrogen/generated/ios/NitroVisionOcr+autolinking.rb +62 -0
  38. package/nitrogen/generated/ios/NitroVisionOcr-Swift-Cxx-Bridge.cpp +44 -0
  39. package/nitrogen/generated/ios/NitroVisionOcr-Swift-Cxx-Bridge.hpp +286 -0
  40. package/nitrogen/generated/ios/NitroVisionOcr-Swift-Cxx-Umbrella.hpp +72 -0
  41. package/nitrogen/generated/ios/c++/HybridVisionOCRSpecSwift.cpp +11 -0
  42. package/nitrogen/generated/ios/c++/HybridVisionOCRSpecSwift.hpp +108 -0
  43. package/nitrogen/generated/ios/swift/HybridVisionOCRSpec.swift +56 -0
  44. package/nitrogen/generated/ios/swift/HybridVisionOCRSpec_cxx.swift +149 -0
  45. package/nitrogen/generated/ios/swift/OcrBlock.swift +64 -0
  46. package/nitrogen/generated/ios/swift/OcrBox.swift +44 -0
  47. package/nitrogen/generated/ios/swift/OcrLine.swift +82 -0
  48. package/nitrogen/generated/ios/swift/OcrOptions.swift +113 -0
  49. package/nitrogen/generated/ios/swift/OcrResult.swift +53 -0
  50. package/nitrogen/generated/ios/swift/OcrWord.swift +58 -0
  51. package/nitrogen/generated/ios/swift/RLevel.swift +40 -0
  52. package/nitrogen/generated/shared/c++/HybridVisionOCRSpec.cpp +21 -0
  53. package/nitrogen/generated/shared/c++/HybridVisionOCRSpec.hpp +71 -0
  54. package/nitrogen/generated/shared/c++/OcrBlock.hpp +98 -0
  55. package/nitrogen/generated/shared/c++/OcrBox.hpp +95 -0
  56. package/nitrogen/generated/shared/c++/OcrLine.hpp +102 -0
  57. package/nitrogen/generated/shared/c++/OcrOptions.hpp +103 -0
  58. package/nitrogen/generated/shared/c++/OcrResult.hpp +91 -0
  59. package/nitrogen/generated/shared/c++/OcrWord.hpp +94 -0
  60. package/nitrogen/generated/shared/c++/RLevel.hpp +76 -0
  61. package/package.json +111 -0
  62. package/react-native.config.js +16 -0
  63. package/src/index.ts +21 -0
  64. package/src/specs/VisionOCR.nitro.ts +11 -0
  65. package/src/types.ts +41 -0
@@ -0,0 +1,91 @@
1
+ ///
2
+ /// OcrResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `OcrBlock` to properly resolve imports.
32
+ namespace margelo::nitro::visionocr { struct OcrBlock; }
33
+
34
+ #include <string>
35
+ #include "OcrBlock.hpp"
36
+ #include <vector>
37
+ #include <optional>
38
+
39
+ namespace margelo::nitro::visionocr {
40
+
41
+ /**
42
+ * A struct which can be represented as a JavaScript object (OcrResult).
43
+ */
44
+ struct OcrResult final {
45
+ public:
46
+ std::string text SWIFT_PRIVATE;
47
+ std::optional<std::vector<OcrBlock>> blocks SWIFT_PRIVATE;
48
+
49
+ public:
50
+ OcrResult() = default;
51
+ explicit OcrResult(std::string text, std::optional<std::vector<OcrBlock>> blocks): text(text), blocks(blocks) {}
52
+
53
+ public:
54
+ friend bool operator==(const OcrResult& lhs, const OcrResult& rhs) = default;
55
+ };
56
+
57
+ } // namespace margelo::nitro::visionocr
58
+
59
+ namespace margelo::nitro {
60
+
61
+ // C++ OcrResult <> JS OcrResult (object)
62
+ template <>
63
+ struct JSIConverter<margelo::nitro::visionocr::OcrResult> final {
64
+ static inline margelo::nitro::visionocr::OcrResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
65
+ jsi::Object obj = arg.asObject(runtime);
66
+ return margelo::nitro::visionocr::OcrResult(
67
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text"))),
68
+ JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrBlock>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blocks")))
69
+ );
70
+ }
71
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::visionocr::OcrResult& arg) {
72
+ jsi::Object obj(runtime);
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::string>::toJSI(runtime, arg.text));
74
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "blocks"), JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrBlock>>>::toJSI(runtime, arg.blocks));
75
+ return obj;
76
+ }
77
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
78
+ if (!value.isObject()) {
79
+ return false;
80
+ }
81
+ jsi::Object obj = value.getObject(runtime);
82
+ if (!nitro::isPlainObject(runtime, obj)) {
83
+ return false;
84
+ }
85
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
86
+ if (!JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrBlock>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blocks")))) return false;
87
+ return true;
88
+ }
89
+ };
90
+
91
+ } // namespace margelo::nitro
@@ -0,0 +1,94 @@
1
+ ///
2
+ /// OcrWord.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `OcrBox` to properly resolve imports.
32
+ namespace margelo::nitro::visionocr { struct OcrBox; }
33
+
34
+ #include <string>
35
+ #include "OcrBox.hpp"
36
+ #include <optional>
37
+
38
+ namespace margelo::nitro::visionocr {
39
+
40
+ /**
41
+ * A struct which can be represented as a JavaScript object (OcrWord).
42
+ */
43
+ struct OcrWord final {
44
+ public:
45
+ std::string text SWIFT_PRIVATE;
46
+ std::optional<OcrBox> box SWIFT_PRIVATE;
47
+ std::optional<double> confidence SWIFT_PRIVATE;
48
+
49
+ public:
50
+ OcrWord() = default;
51
+ explicit OcrWord(std::string text, std::optional<OcrBox> box, std::optional<double> confidence): text(text), box(box), confidence(confidence) {}
52
+
53
+ public:
54
+ friend bool operator==(const OcrWord& lhs, const OcrWord& rhs) = default;
55
+ };
56
+
57
+ } // namespace margelo::nitro::visionocr
58
+
59
+ namespace margelo::nitro {
60
+
61
+ // C++ OcrWord <> JS OcrWord (object)
62
+ template <>
63
+ struct JSIConverter<margelo::nitro::visionocr::OcrWord> final {
64
+ static inline margelo::nitro::visionocr::OcrWord fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
65
+ jsi::Object obj = arg.asObject(runtime);
66
+ return margelo::nitro::visionocr::OcrWord(
67
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text"))),
68
+ JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "box"))),
69
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))
70
+ );
71
+ }
72
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::visionocr::OcrWord& arg) {
73
+ jsi::Object obj(runtime);
74
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::string>::toJSI(runtime, arg.text));
75
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "box"), JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::toJSI(runtime, arg.box));
76
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "confidence"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.confidence));
77
+ return obj;
78
+ }
79
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
80
+ if (!value.isObject()) {
81
+ return false;
82
+ }
83
+ jsi::Object obj = value.getObject(runtime);
84
+ if (!nitro::isPlainObject(runtime, obj)) {
85
+ return false;
86
+ }
87
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
88
+ if (!JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "box")))) return false;
89
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))) return false;
90
+ return true;
91
+ }
92
+ };
93
+
94
+ } // namespace margelo::nitro
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// RLevel.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::visionocr {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (RLevel).
30
+ */
31
+ enum class RLevel {
32
+ FAST SWIFT_NAME(fast) = 0,
33
+ ACCURATE SWIFT_NAME(accurate) = 1,
34
+ } CLOSED_ENUM;
35
+
36
+ } // namespace margelo::nitro::visionocr
37
+
38
+ namespace margelo::nitro {
39
+
40
+ // C++ RLevel <> JS RLevel (union)
41
+ template <>
42
+ struct JSIConverter<margelo::nitro::visionocr::RLevel> final {
43
+ static inline margelo::nitro::visionocr::RLevel fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
44
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
45
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
46
+ case hashString("fast"): return margelo::nitro::visionocr::RLevel::FAST;
47
+ case hashString("accurate"): return margelo::nitro::visionocr::RLevel::ACCURATE;
48
+ default: [[unlikely]]
49
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum RLevel - invalid value!");
50
+ }
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::visionocr::RLevel arg) {
53
+ switch (arg) {
54
+ case margelo::nitro::visionocr::RLevel::FAST: return JSIConverter<std::string>::toJSI(runtime, "fast");
55
+ case margelo::nitro::visionocr::RLevel::ACCURATE: return JSIConverter<std::string>::toJSI(runtime, "accurate");
56
+ default: [[unlikely]]
57
+ throw std::invalid_argument("Cannot convert RLevel to JS - invalid value: "
58
+ + std::to_string(static_cast<int>(arg)) + "!");
59
+ }
60
+ }
61
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
62
+ if (!value.isString()) {
63
+ return false;
64
+ }
65
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
66
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
67
+ case hashString("fast"):
68
+ case hashString("accurate"):
69
+ return true;
70
+ default:
71
+ return false;
72
+ }
73
+ }
74
+ };
75
+
76
+ } // namespace margelo::nitro
package/package.json ADDED
@@ -0,0 +1,111 @@
1
+ {
2
+ "name": "@imagowave/vision-ocr",
3
+ "version": "0.0.1",
4
+ "description": "A React Native module for performing OCR using the Vision framework on iOS and ML Kit on Android.",
5
+ "main": "lib/index",
6
+ "module": "lib/index",
7
+ "types": "lib/types.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "react-native.config.js",
13
+ "lib",
14
+ "nitrogen",
15
+ "android/build.gradle",
16
+ "android/gradle.properties",
17
+ "android/fix-prefab.gradle",
18
+ "android/CMakeLists.txt",
19
+ "android/src",
20
+ "cpp",
21
+ "ios/**/*.h",
22
+ "ios/**/*.m",
23
+ "ios/**/*.mm",
24
+ "ios/**/*.cpp",
25
+ "ios/**/*.swift",
26
+ "app.plugin.js",
27
+ "nitro.json",
28
+ "*.podspec",
29
+ "README.md"
30
+ ],
31
+ "scripts": {
32
+ "typecheck": "tsc --noEmit",
33
+ "clean": "rm -rf android/build node_modules/**/android/build lib",
34
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
35
+ "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
36
+ "typescript": "tsc",
37
+ "specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\""
38
+ },
39
+ "keywords": [
40
+ "react-native",
41
+ "nitro"
42
+ ],
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/imagowave/vision-ocr.git"
46
+ },
47
+ "author": "Jonathan Grimes <> (https://github.com/jsg2021)",
48
+ "license": "MIT",
49
+ "bugs": {
50
+ "url": "https://github.com/imagowave/vision-ocr/issues"
51
+ },
52
+ "homepage": "https://github.com/imagowave/vision-ocr#readme",
53
+ "publishConfig": {
54
+ "registry": "https://registry.npmjs.org/",
55
+ "access": "public"
56
+ },
57
+ "devDependencies": {
58
+ "@react-native/eslint-config": "0.83.0",
59
+ "@types/react": "^19.1.03",
60
+ "eslint": "^8.57.0",
61
+ "eslint-config-prettier": "^9.1.0",
62
+ "eslint-plugin-prettier": "^5.2.1",
63
+ "nitrogen": "*",
64
+ "prettier": "^3.3.3",
65
+ "react": "19.2.0",
66
+ "react-native": "0.83.0",
67
+ "react-native-nitro-modules": "*",
68
+ "react-native-vision-camera": "*",
69
+ "typescript": "^5.8.3"
70
+ },
71
+ "peerDependencies": {
72
+ "react": "*",
73
+ "react-native": "*",
74
+ "react-native-nitro-modules": "*",
75
+ "react-native-vision-camera": "*"
76
+ },
77
+ "eslintConfig": {
78
+ "root": true,
79
+ "extends": [
80
+ "@react-native",
81
+ "prettier"
82
+ ],
83
+ "plugins": [
84
+ "prettier"
85
+ ],
86
+ "rules": {
87
+ "prettier/prettier": [
88
+ "warn",
89
+ {
90
+ "quoteProps": "consistent",
91
+ "singleQuote": true,
92
+ "tabWidth": 2,
93
+ "trailingComma": "es5",
94
+ "useTabs": false
95
+ }
96
+ ]
97
+ }
98
+ },
99
+ "eslintIgnore": [
100
+ "node_modules/",
101
+ "lib/"
102
+ ],
103
+ "prettier": {
104
+ "quoteProps": "consistent",
105
+ "singleQuote": true,
106
+ "tabWidth": 2,
107
+ "trailingComma": "es5",
108
+ "useTabs": false,
109
+ "semi": false
110
+ }
111
+ }
@@ -0,0 +1,16 @@
1
+ // https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
2
+
3
+ module.exports = {
4
+ dependency: {
5
+ platforms: {
6
+ /**
7
+ * @type {import('@react-native-community/cli-types').IOSDependencyParams}
8
+ */
9
+ ios: {},
10
+ /**
11
+ * @type {import('@react-native-community/cli-types').AndroidDependencyParams}
12
+ */
13
+ android: {},
14
+ },
15
+ },
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { NitroModules } from "react-native-nitro-modules";
2
+ import type { Frame } from "react-native-vision-camera";
3
+
4
+ import type { VisionOCR } from "./specs/VisionOCR.nitro";
5
+ import type { OcrOptions, OcrResult } from "./types";
6
+
7
+ export * from "./types";
8
+
9
+ const plugin = NitroModules.createHybridObject<VisionOCR>("VisionOCR");
10
+
11
+ export default plugin;
12
+
13
+ export function performOcr(
14
+ frame: Frame,
15
+ options?: OcrOptions,
16
+ ): OcrResult | null {
17
+ "worklet";
18
+ if (plugin == null) throw new Error("Failed to load Frame Processor Plugin");
19
+
20
+ return plugin.call(frame, options ?? {}) as unknown as OcrResult | null;
21
+ }
@@ -0,0 +1,11 @@
1
+ import type { HybridObject } from "react-native-nitro-modules";
2
+ import type { Frame } from "react-native-vision-camera";
3
+ import type { OcrOptions, OcrResult } from "../types";
4
+
5
+ export interface VisionOCR
6
+ extends HybridObject<{
7
+ ios: "swift";
8
+ android: "kotlin";
9
+ }> {
10
+ call(frame: Frame, options?: OcrOptions): OcrResult | undefined;
11
+ }
package/src/types.ts ADDED
@@ -0,0 +1,41 @@
1
+ type RLevel = "fast" | "accurate";
2
+
3
+ export type OcrOptions = {
4
+ includeBoxes?: boolean;
5
+ includeConfidence?: boolean;
6
+ // iOS only options (ignored on Android)
7
+ recognitionLevel?: RLevel;
8
+ recognitionLanguages?: string[];
9
+ usesLanguageCorrection?: boolean;
10
+ };
11
+
12
+ export type OcrBox = {
13
+ x: number;
14
+ y: number;
15
+ width: number;
16
+ height: number;
17
+ };
18
+
19
+ export type OcrWord = {
20
+ text: string;
21
+ box?: OcrBox;
22
+ confidence?: number;
23
+ };
24
+
25
+ export type OcrLine = {
26
+ text: string;
27
+ box?: OcrBox;
28
+ words?: OcrWord[];
29
+ confidence?: number;
30
+ };
31
+
32
+ export type OcrBlock = {
33
+ text: string;
34
+ box?: OcrBox;
35
+ lines?: OcrLine[];
36
+ };
37
+
38
+ export type OcrResult = {
39
+ text: string;
40
+ blocks?: OcrBlock[];
41
+ };