@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,108 @@
1
+ ///
2
+ /// HybridVisionOCRSpecSwift.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
+ #include "HybridVisionOCRSpec.hpp"
11
+
12
+ // Forward declaration of `HybridVisionOCRSpec_cxx` to properly resolve imports.
13
+ namespace NitroVisionOcr { class HybridVisionOCRSpec_cxx; }
14
+
15
+ // Forward declaration of `OcrResult` to properly resolve imports.
16
+ namespace margelo::nitro::visionocr { struct OcrResult; }
17
+ // Forward declaration of `OcrBlock` to properly resolve imports.
18
+ namespace margelo::nitro::visionocr { struct OcrBlock; }
19
+ // Forward declaration of `OcrBox` to properly resolve imports.
20
+ namespace margelo::nitro::visionocr { struct OcrBox; }
21
+ // Forward declaration of `OcrLine` to properly resolve imports.
22
+ namespace margelo::nitro::visionocr { struct OcrLine; }
23
+ // Forward declaration of `OcrWord` to properly resolve imports.
24
+ namespace margelo::nitro::visionocr { struct OcrWord; }
25
+ // Forward declaration of `HybridFrameSpec` to properly resolve imports.
26
+ namespace margelo::nitro::camera { class HybridFrameSpec; }
27
+ // Forward declaration of `OcrOptions` to properly resolve imports.
28
+ namespace margelo::nitro::visionocr { struct OcrOptions; }
29
+ // Forward declaration of `RLevel` to properly resolve imports.
30
+ namespace margelo::nitro::visionocr { enum class RLevel; }
31
+
32
+ #include "OcrResult.hpp"
33
+ #include <optional>
34
+ #include <string>
35
+ #include "OcrBlock.hpp"
36
+ #include <vector>
37
+ #include "OcrBox.hpp"
38
+ #include "OcrLine.hpp"
39
+ #include "OcrWord.hpp"
40
+ #include <memory>
41
+ #include <VisionCamera/HybridFrameSpec.hpp>
42
+ #include "OcrOptions.hpp"
43
+ #include "RLevel.hpp"
44
+
45
+ #include "NitroVisionOcr-Swift-Cxx-Umbrella.hpp"
46
+
47
+ namespace margelo::nitro::visionocr {
48
+
49
+ /**
50
+ * The C++ part of HybridVisionOCRSpec_cxx.swift.
51
+ *
52
+ * HybridVisionOCRSpecSwift (C++) accesses HybridVisionOCRSpec_cxx (Swift), and might
53
+ * contain some additional bridging code for C++ <> Swift interop.
54
+ *
55
+ * Since this obviously introduces an overhead, I hope at some point in
56
+ * the future, HybridVisionOCRSpec_cxx can directly inherit from the C++ class HybridVisionOCRSpec
57
+ * to simplify the whole structure and memory management.
58
+ */
59
+ class HybridVisionOCRSpecSwift: public virtual HybridVisionOCRSpec {
60
+ public:
61
+ // Constructor from a Swift instance
62
+ explicit HybridVisionOCRSpecSwift(const NitroVisionOcr::HybridVisionOCRSpec_cxx& swiftPart):
63
+ HybridObject(HybridVisionOCRSpec::TAG),
64
+ _swiftPart(swiftPart) { }
65
+
66
+ public:
67
+ // Get the Swift part
68
+ inline NitroVisionOcr::HybridVisionOCRSpec_cxx& getSwiftPart() noexcept {
69
+ return _swiftPart;
70
+ }
71
+
72
+ public:
73
+ inline size_t getExternalMemorySize() noexcept override {
74
+ return _swiftPart.getMemorySize();
75
+ }
76
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
77
+ if (auto otherCast = std::dynamic_pointer_cast<HybridVisionOCRSpecSwift>(other)) {
78
+ return _swiftPart.equals(otherCast->_swiftPart);
79
+ }
80
+ return false;
81
+ }
82
+ void dispose() noexcept override {
83
+ _swiftPart.dispose();
84
+ }
85
+ std::string toString() override {
86
+ return _swiftPart.toString();
87
+ }
88
+
89
+ public:
90
+ // Properties
91
+
92
+
93
+ public:
94
+ // Methods
95
+ inline std::optional<OcrResult> call(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame, const std::optional<OcrOptions>& options) override {
96
+ auto __result = _swiftPart.call(frame, options);
97
+ if (__result.hasError()) [[unlikely]] {
98
+ std::rethrow_exception(__result.error());
99
+ }
100
+ auto __value = std::move(__result.value());
101
+ return __value;
102
+ }
103
+
104
+ private:
105
+ NitroVisionOcr::HybridVisionOCRSpec_cxx _swiftPart;
106
+ };
107
+
108
+ } // namespace margelo::nitro::visionocr
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// HybridVisionOCRSpec.swift
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
+ import VisionCamera
9
+ import NitroModules
10
+
11
+ /// See ``HybridVisionOCRSpec``
12
+ public protocol HybridVisionOCRSpec_protocol: HybridObject {
13
+ // Properties
14
+
15
+
16
+ // Methods
17
+ func call(frame: (any HybridFrameSpec), options: OcrOptions?) throws -> OcrResult?
18
+ }
19
+
20
+ public extension HybridVisionOCRSpec_protocol {
21
+ /// Default implementation of ``HybridObject.toString``
22
+ func toString() -> String {
23
+ return "[HybridObject VisionOCR]"
24
+ }
25
+ }
26
+
27
+ /// See ``HybridVisionOCRSpec``
28
+ open class HybridVisionOCRSpec_base {
29
+ private weak var cxxWrapper: HybridVisionOCRSpec_cxx? = nil
30
+ public init() { }
31
+ public func getCxxWrapper() -> HybridVisionOCRSpec_cxx {
32
+ #if DEBUG
33
+ guard self is any HybridVisionOCRSpec else {
34
+ fatalError("`self` is not a `HybridVisionOCRSpec`! Did you accidentally inherit from `HybridVisionOCRSpec_base` instead of `HybridVisionOCRSpec`?")
35
+ }
36
+ #endif
37
+ if let cxxWrapper = self.cxxWrapper {
38
+ return cxxWrapper
39
+ } else {
40
+ let cxxWrapper = HybridVisionOCRSpec_cxx(self as! any HybridVisionOCRSpec)
41
+ self.cxxWrapper = cxxWrapper
42
+ return cxxWrapper
43
+ }
44
+ }
45
+ }
46
+
47
+ /**
48
+ * A Swift base-protocol representing the VisionOCR HybridObject.
49
+ * Implement this protocol to create Swift-based instances of VisionOCR.
50
+ * ```swift
51
+ * class HybridVisionOCR : HybridVisionOCRSpec {
52
+ * // ...
53
+ * }
54
+ * ```
55
+ */
56
+ public typealias HybridVisionOCRSpec = HybridVisionOCRSpec_protocol & HybridVisionOCRSpec_base
@@ -0,0 +1,149 @@
1
+ ///
2
+ /// HybridVisionOCRSpec_cxx.swift
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
+ import NitroModules
9
+ import VisionCamera
10
+
11
+ /**
12
+ * A class implementation that bridges HybridVisionOCRSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridVisionOCRSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::visionocr::bridge::swift`)
23
+ * from `NitroVisionOcr-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.visionocr.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridVisionOCRSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridVisionOCRSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridVisionOCRSpec_
37
+
38
+ /**
39
+ * Create a new `HybridVisionOCRSpec_cxx` that wraps the given `HybridVisionOCRSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridVisionOCRSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridVisionOCRSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridVisionOCRSpec() -> any HybridVisionOCRSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridVisionOCRSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridVisionOCRSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridVisionOCRSpec_cxx {
70
+ return Unmanaged<HybridVisionOCRSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridVisionOCRSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridVisionOCRSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridVisionOCRSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridVisionOCRSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Compares this object with the given [other] object for reference equality.
101
+ */
102
+ @inline(__always)
103
+ public func equals(other: HybridVisionOCRSpec_cxx) -> Bool {
104
+ return self.__implementation === other.__implementation
105
+ }
106
+
107
+ /**
108
+ * Call dispose() on the Swift class.
109
+ * This _may_ be called manually from JS.
110
+ */
111
+ @inline(__always)
112
+ public func dispose() {
113
+ self.__implementation.dispose()
114
+ }
115
+
116
+ /**
117
+ * Call toString() on the Swift class.
118
+ */
119
+ @inline(__always)
120
+ public func toString() -> String {
121
+ return self.__implementation.toString()
122
+ }
123
+
124
+ // Properties
125
+
126
+
127
+ // Methods
128
+ @inline(__always)
129
+ public final func call(frame: bridge.std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_, options: bridge.std__optional_OcrOptions_) -> bridge.Result_std__optional_OcrResult__ {
130
+ do {
131
+ let __result = try self.__implementation.call(frame: { () -> any HybridFrameSpec in
132
+ let __unsafePointer = bridge.get_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(frame)
133
+ let __instance = HybridFrameSpec_cxx.fromUnsafe(__unsafePointer)
134
+ return __instance.getHybridFrameSpec()
135
+ }(), options: options.value)
136
+ let __resultCpp = { () -> bridge.std__optional_OcrResult_ in
137
+ if let __unwrappedValue = __result {
138
+ return bridge.create_std__optional_OcrResult_(__unwrappedValue)
139
+ } else {
140
+ return .init()
141
+ }
142
+ }()
143
+ return bridge.create_Result_std__optional_OcrResult__(__resultCpp)
144
+ } catch (let __error) {
145
+ let __exceptionPtr = __error.toCpp()
146
+ return bridge.create_Result_std__optional_OcrResult__(__exceptionPtr)
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// OcrBlock.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `OcrBlock`, backed by a C++ struct.
12
+ */
13
+ public typealias OcrBlock = margelo.nitro.visionocr.OcrBlock
14
+
15
+ public extension OcrBlock {
16
+ private typealias bridge = margelo.nitro.visionocr.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `OcrBlock`.
20
+ */
21
+ init(text: String, box: OcrBox?, lines: [OcrLine]?) {
22
+ self.init(std.string(text), { () -> bridge.std__optional_OcrBox_ in
23
+ if let __unwrappedValue = box {
24
+ return bridge.create_std__optional_OcrBox_(__unwrappedValue)
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), { () -> bridge.std__optional_std__vector_OcrLine__ in
29
+ if let __unwrappedValue = lines {
30
+ return bridge.create_std__optional_std__vector_OcrLine__({ () -> bridge.std__vector_OcrLine_ in
31
+ var __vector = bridge.create_std__vector_OcrLine_(__unwrappedValue.count)
32
+ for __item in __unwrappedValue {
33
+ __vector.push_back(__item)
34
+ }
35
+ return __vector
36
+ }())
37
+ } else {
38
+ return .init()
39
+ }
40
+ }())
41
+ }
42
+
43
+ @inline(__always)
44
+ var text: String {
45
+ return String(self.__text)
46
+ }
47
+
48
+ @inline(__always)
49
+ var box: OcrBox? {
50
+ return self.__box.value
51
+ }
52
+
53
+ @inline(__always)
54
+ var lines: [OcrLine]? {
55
+ return { () -> [OcrLine]? in
56
+ if bridge.has_value_std__optional_std__vector_OcrLine__(self.__lines) {
57
+ let __unwrapped = bridge.get_std__optional_std__vector_OcrLine__(self.__lines)
58
+ return __unwrapped.map({ __item in __item })
59
+ } else {
60
+ return nil
61
+ }
62
+ }()
63
+ }
64
+ }
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// OcrBox.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `OcrBox`, backed by a C++ struct.
12
+ */
13
+ public typealias OcrBox = margelo.nitro.visionocr.OcrBox
14
+
15
+ public extension OcrBox {
16
+ private typealias bridge = margelo.nitro.visionocr.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `OcrBox`.
20
+ */
21
+ init(x: Double, y: Double, width: Double, height: Double) {
22
+ self.init(x, y, width, height)
23
+ }
24
+
25
+ @inline(__always)
26
+ var x: Double {
27
+ return self.__x
28
+ }
29
+
30
+ @inline(__always)
31
+ var y: Double {
32
+ return self.__y
33
+ }
34
+
35
+ @inline(__always)
36
+ var width: Double {
37
+ return self.__width
38
+ }
39
+
40
+ @inline(__always)
41
+ var height: Double {
42
+ return self.__height
43
+ }
44
+ }
@@ -0,0 +1,82 @@
1
+ ///
2
+ /// OcrLine.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `OcrLine`, backed by a C++ struct.
12
+ */
13
+ public typealias OcrLine = margelo.nitro.visionocr.OcrLine
14
+
15
+ public extension OcrLine {
16
+ private typealias bridge = margelo.nitro.visionocr.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `OcrLine`.
20
+ */
21
+ init(text: String, box: OcrBox?, words: [OcrWord]?, confidence: Double?) {
22
+ self.init(std.string(text), { () -> bridge.std__optional_OcrBox_ in
23
+ if let __unwrappedValue = box {
24
+ return bridge.create_std__optional_OcrBox_(__unwrappedValue)
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), { () -> bridge.std__optional_std__vector_OcrWord__ in
29
+ if let __unwrappedValue = words {
30
+ return bridge.create_std__optional_std__vector_OcrWord__({ () -> bridge.std__vector_OcrWord_ in
31
+ var __vector = bridge.create_std__vector_OcrWord_(__unwrappedValue.count)
32
+ for __item in __unwrappedValue {
33
+ __vector.push_back(__item)
34
+ }
35
+ return __vector
36
+ }())
37
+ } else {
38
+ return .init()
39
+ }
40
+ }(), { () -> bridge.std__optional_double_ in
41
+ if let __unwrappedValue = confidence {
42
+ return bridge.create_std__optional_double_(__unwrappedValue)
43
+ } else {
44
+ return .init()
45
+ }
46
+ }())
47
+ }
48
+
49
+ @inline(__always)
50
+ var text: String {
51
+ return String(self.__text)
52
+ }
53
+
54
+ @inline(__always)
55
+ var box: OcrBox? {
56
+ return self.__box.value
57
+ }
58
+
59
+ @inline(__always)
60
+ var words: [OcrWord]? {
61
+ return { () -> [OcrWord]? in
62
+ if bridge.has_value_std__optional_std__vector_OcrWord__(self.__words) {
63
+ let __unwrapped = bridge.get_std__optional_std__vector_OcrWord__(self.__words)
64
+ return __unwrapped.map({ __item in __item })
65
+ } else {
66
+ return nil
67
+ }
68
+ }()
69
+ }
70
+
71
+ @inline(__always)
72
+ var confidence: Double? {
73
+ return { () -> Double? in
74
+ if bridge.has_value_std__optional_double_(self.__confidence) {
75
+ let __unwrapped = bridge.get_std__optional_double_(self.__confidence)
76
+ return __unwrapped
77
+ } else {
78
+ return nil
79
+ }
80
+ }()
81
+ }
82
+ }
@@ -0,0 +1,113 @@
1
+ ///
2
+ /// OcrOptions.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `OcrOptions`, backed by a C++ struct.
12
+ */
13
+ public typealias OcrOptions = margelo.nitro.visionocr.OcrOptions
14
+
15
+ public extension OcrOptions {
16
+ private typealias bridge = margelo.nitro.visionocr.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `OcrOptions`.
20
+ */
21
+ init(includeBoxes: Bool?, includeConfidence: Bool?, recognitionLevel: RLevel?, recognitionLanguages: [String]?, usesLanguageCorrection: Bool?) {
22
+ self.init({ () -> bridge.std__optional_bool_ in
23
+ if let __unwrappedValue = includeBoxes {
24
+ return bridge.create_std__optional_bool_(__unwrappedValue)
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), { () -> bridge.std__optional_bool_ in
29
+ if let __unwrappedValue = includeConfidence {
30
+ return bridge.create_std__optional_bool_(__unwrappedValue)
31
+ } else {
32
+ return .init()
33
+ }
34
+ }(), { () -> bridge.std__optional_RLevel_ in
35
+ if let __unwrappedValue = recognitionLevel {
36
+ return bridge.create_std__optional_RLevel_(__unwrappedValue)
37
+ } else {
38
+ return .init()
39
+ }
40
+ }(), { () -> bridge.std__optional_std__vector_std__string__ in
41
+ if let __unwrappedValue = recognitionLanguages {
42
+ return bridge.create_std__optional_std__vector_std__string__({ () -> bridge.std__vector_std__string_ in
43
+ var __vector = bridge.create_std__vector_std__string_(__unwrappedValue.count)
44
+ for __item in __unwrappedValue {
45
+ __vector.push_back(std.string(__item))
46
+ }
47
+ return __vector
48
+ }())
49
+ } else {
50
+ return .init()
51
+ }
52
+ }(), { () -> bridge.std__optional_bool_ in
53
+ if let __unwrappedValue = usesLanguageCorrection {
54
+ return bridge.create_std__optional_bool_(__unwrappedValue)
55
+ } else {
56
+ return .init()
57
+ }
58
+ }())
59
+ }
60
+
61
+ @inline(__always)
62
+ var includeBoxes: Bool? {
63
+ return { () -> Bool? in
64
+ if bridge.has_value_std__optional_bool_(self.__includeBoxes) {
65
+ let __unwrapped = bridge.get_std__optional_bool_(self.__includeBoxes)
66
+ return __unwrapped
67
+ } else {
68
+ return nil
69
+ }
70
+ }()
71
+ }
72
+
73
+ @inline(__always)
74
+ var includeConfidence: Bool? {
75
+ return { () -> Bool? in
76
+ if bridge.has_value_std__optional_bool_(self.__includeConfidence) {
77
+ let __unwrapped = bridge.get_std__optional_bool_(self.__includeConfidence)
78
+ return __unwrapped
79
+ } else {
80
+ return nil
81
+ }
82
+ }()
83
+ }
84
+
85
+ @inline(__always)
86
+ var recognitionLevel: RLevel? {
87
+ return self.__recognitionLevel.value
88
+ }
89
+
90
+ @inline(__always)
91
+ var recognitionLanguages: [String]? {
92
+ return { () -> [String]? in
93
+ if bridge.has_value_std__optional_std__vector_std__string__(self.__recognitionLanguages) {
94
+ let __unwrapped = bridge.get_std__optional_std__vector_std__string__(self.__recognitionLanguages)
95
+ return __unwrapped.map({ __item in String(__item) })
96
+ } else {
97
+ return nil
98
+ }
99
+ }()
100
+ }
101
+
102
+ @inline(__always)
103
+ var usesLanguageCorrection: Bool? {
104
+ return { () -> Bool? in
105
+ if bridge.has_value_std__optional_bool_(self.__usesLanguageCorrection) {
106
+ let __unwrapped = bridge.get_std__optional_bool_(self.__usesLanguageCorrection)
107
+ return __unwrapped
108
+ } else {
109
+ return nil
110
+ }
111
+ }()
112
+ }
113
+ }
@@ -0,0 +1,53 @@
1
+ ///
2
+ /// OcrResult.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `OcrResult`, backed by a C++ struct.
12
+ */
13
+ public typealias OcrResult = margelo.nitro.visionocr.OcrResult
14
+
15
+ public extension OcrResult {
16
+ private typealias bridge = margelo.nitro.visionocr.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `OcrResult`.
20
+ */
21
+ init(text: String, blocks: [OcrBlock]?) {
22
+ self.init(std.string(text), { () -> bridge.std__optional_std__vector_OcrBlock__ in
23
+ if let __unwrappedValue = blocks {
24
+ return bridge.create_std__optional_std__vector_OcrBlock__({ () -> bridge.std__vector_OcrBlock_ in
25
+ var __vector = bridge.create_std__vector_OcrBlock_(__unwrappedValue.count)
26
+ for __item in __unwrappedValue {
27
+ __vector.push_back(__item)
28
+ }
29
+ return __vector
30
+ }())
31
+ } else {
32
+ return .init()
33
+ }
34
+ }())
35
+ }
36
+
37
+ @inline(__always)
38
+ var text: String {
39
+ return String(self.__text)
40
+ }
41
+
42
+ @inline(__always)
43
+ var blocks: [OcrBlock]? {
44
+ return { () -> [OcrBlock]? in
45
+ if bridge.has_value_std__optional_std__vector_OcrBlock__(self.__blocks) {
46
+ let __unwrapped = bridge.get_std__optional_std__vector_OcrBlock__(self.__blocks)
47
+ return __unwrapped.map({ __item in __item })
48
+ } else {
49
+ return nil
50
+ }
51
+ }()
52
+ }
53
+ }