@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.
- package/NitroVisionOcr.podspec +32 -0
- package/README.md +38 -0
- package/android/CMakeLists.txt +31 -0
- package/android/build.gradle +143 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/margelo/nitro/visionocr/NitroVisionOcrPackage.kt +18 -0
- package/android/src/main/java/com/margelo/nitro/visionocr/VisionOcr.kt +120 -0
- package/ios/Bridge.h +8 -0
- package/ios/VisionOCR.swift +137 -0
- package/nitro.json +19 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroVisionOcr+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroVisionOcr+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroVisionOcrOnLoad.cpp +41 -0
- package/nitrogen/generated/android/NitroVisionOcrOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JHybridVisionOCRSpec.cpp +87 -0
- package/nitrogen/generated/android/c++/JHybridVisionOCRSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JOcrBlock.hpp +91 -0
- package/nitrogen/generated/android/c++/JOcrBox.hpp +69 -0
- package/nitrogen/generated/android/c++/JOcrLine.hpp +93 -0
- package/nitrogen/generated/android/c++/JOcrOptions.hpp +95 -0
- package/nitrogen/generated/android/c++/JOcrResult.hpp +89 -0
- package/nitrogen/generated/android/c++/JOcrWord.hpp +68 -0
- package/nitrogen/generated/android/c++/JRLevel.hpp +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/HybridVisionOCRSpec.kt +55 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/NitroVisionOcrOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrBlock.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrBox.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrLine.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrOptions.kt +71 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrResult.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/OcrWord.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/visionocr/RLevel.kt +23 -0
- package/nitrogen/generated/ios/NitroVisionOcr+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroVisionOcr-Swift-Cxx-Bridge.cpp +44 -0
- package/nitrogen/generated/ios/NitroVisionOcr-Swift-Cxx-Bridge.hpp +286 -0
- package/nitrogen/generated/ios/NitroVisionOcr-Swift-Cxx-Umbrella.hpp +72 -0
- package/nitrogen/generated/ios/c++/HybridVisionOCRSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridVisionOCRSpecSwift.hpp +108 -0
- package/nitrogen/generated/ios/swift/HybridVisionOCRSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridVisionOCRSpec_cxx.swift +149 -0
- package/nitrogen/generated/ios/swift/OcrBlock.swift +64 -0
- package/nitrogen/generated/ios/swift/OcrBox.swift +44 -0
- package/nitrogen/generated/ios/swift/OcrLine.swift +82 -0
- package/nitrogen/generated/ios/swift/OcrOptions.swift +113 -0
- package/nitrogen/generated/ios/swift/OcrResult.swift +53 -0
- package/nitrogen/generated/ios/swift/OcrWord.swift +58 -0
- package/nitrogen/generated/ios/swift/RLevel.swift +40 -0
- package/nitrogen/generated/shared/c++/HybridVisionOCRSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridVisionOCRSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/OcrBlock.hpp +98 -0
- package/nitrogen/generated/shared/c++/OcrBox.hpp +95 -0
- package/nitrogen/generated/shared/c++/OcrLine.hpp +102 -0
- package/nitrogen/generated/shared/c++/OcrOptions.hpp +103 -0
- package/nitrogen/generated/shared/c++/OcrResult.hpp +91 -0
- package/nitrogen/generated/shared/c++/OcrWord.hpp +94 -0
- package/nitrogen/generated/shared/c++/RLevel.hpp +76 -0
- package/package.json +111 -0
- package/react-native.config.js +16 -0
- package/src/index.ts +21 -0
- package/src/specs/VisionOCR.nitro.ts +11 -0
- package/src/types.ts +41 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// OcrWord.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 `OcrWord`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias OcrWord = margelo.nitro.visionocr.OcrWord
|
|
14
|
+
|
|
15
|
+
public extension OcrWord {
|
|
16
|
+
private typealias bridge = margelo.nitro.visionocr.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `OcrWord`.
|
|
20
|
+
*/
|
|
21
|
+
init(text: String, box: OcrBox?, 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_double_ in
|
|
29
|
+
if let __unwrappedValue = confidence {
|
|
30
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
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 box: OcrBox? {
|
|
44
|
+
return self.__box.value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@inline(__always)
|
|
48
|
+
var confidence: Double? {
|
|
49
|
+
return { () -> Double? in
|
|
50
|
+
if bridge.has_value_std__optional_double_(self.__confidence) {
|
|
51
|
+
let __unwrapped = bridge.get_std__optional_double_(self.__confidence)
|
|
52
|
+
return __unwrapped
|
|
53
|
+
} else {
|
|
54
|
+
return nil
|
|
55
|
+
}
|
|
56
|
+
}()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// RLevel.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
|
+
/**
|
|
9
|
+
* Represents the JS union `RLevel`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias RLevel = margelo.nitro.visionocr.RLevel
|
|
12
|
+
|
|
13
|
+
public extension RLevel {
|
|
14
|
+
/**
|
|
15
|
+
* Get a RLevel for the given String value, or
|
|
16
|
+
* return `nil` if the given value was invalid/unknown.
|
|
17
|
+
*/
|
|
18
|
+
init?(fromString string: String) {
|
|
19
|
+
switch string {
|
|
20
|
+
case "fast":
|
|
21
|
+
self = .fast
|
|
22
|
+
case "accurate":
|
|
23
|
+
self = .accurate
|
|
24
|
+
default:
|
|
25
|
+
return nil
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the String value this RLevel represents.
|
|
31
|
+
*/
|
|
32
|
+
var stringValue: String {
|
|
33
|
+
switch self {
|
|
34
|
+
case .fast:
|
|
35
|
+
return "fast"
|
|
36
|
+
case .accurate:
|
|
37
|
+
return "accurate"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridVisionOCRSpec.cpp
|
|
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
|
+
#include "HybridVisionOCRSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::visionocr {
|
|
11
|
+
|
|
12
|
+
void HybridVisionOCRSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("call", &HybridVisionOCRSpec::call);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridVisionOCRSpec.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/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `OcrResult` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::visionocr { struct OcrResult; }
|
|
18
|
+
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
20
|
+
// Forward declaration of `OcrOptions` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::visionocr { struct OcrOptions; }
|
|
22
|
+
|
|
23
|
+
#include "OcrResult.hpp"
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include <memory>
|
|
26
|
+
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
27
|
+
#include "OcrOptions.hpp"
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::visionocr {
|
|
30
|
+
|
|
31
|
+
using namespace margelo::nitro;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An abstract base class for `VisionOCR`
|
|
35
|
+
* Inherit this class to create instances of `HybridVisionOCRSpec` in C++.
|
|
36
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
37
|
+
* @example
|
|
38
|
+
* ```cpp
|
|
39
|
+
* class HybridVisionOCR: public HybridVisionOCRSpec {
|
|
40
|
+
* public:
|
|
41
|
+
* HybridVisionOCR(...): HybridObject(TAG) { ... }
|
|
42
|
+
* // ...
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
class HybridVisionOCRSpec: public virtual HybridObject {
|
|
47
|
+
public:
|
|
48
|
+
// Constructor
|
|
49
|
+
explicit HybridVisionOCRSpec(): HybridObject(TAG) { }
|
|
50
|
+
|
|
51
|
+
// Destructor
|
|
52
|
+
~HybridVisionOCRSpec() override = default;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Properties
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Methods
|
|
60
|
+
virtual std::optional<OcrResult> call(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame, const std::optional<OcrOptions>& options) = 0;
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
// Hybrid Setup
|
|
64
|
+
void loadHybridMethods() override;
|
|
65
|
+
|
|
66
|
+
protected:
|
|
67
|
+
// Tag for logging
|
|
68
|
+
static constexpr auto TAG = "VisionOCR";
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// OcrBlock.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
|
+
// Forward declaration of `OcrLine` to properly resolve imports.
|
|
34
|
+
namespace margelo::nitro::visionocr { struct OcrLine; }
|
|
35
|
+
|
|
36
|
+
#include <string>
|
|
37
|
+
#include "OcrBox.hpp"
|
|
38
|
+
#include <optional>
|
|
39
|
+
#include "OcrLine.hpp"
|
|
40
|
+
#include <vector>
|
|
41
|
+
|
|
42
|
+
namespace margelo::nitro::visionocr {
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A struct which can be represented as a JavaScript object (OcrBlock).
|
|
46
|
+
*/
|
|
47
|
+
struct OcrBlock final {
|
|
48
|
+
public:
|
|
49
|
+
std::string text SWIFT_PRIVATE;
|
|
50
|
+
std::optional<OcrBox> box SWIFT_PRIVATE;
|
|
51
|
+
std::optional<std::vector<OcrLine>> lines SWIFT_PRIVATE;
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
OcrBlock() = default;
|
|
55
|
+
explicit OcrBlock(std::string text, std::optional<OcrBox> box, std::optional<std::vector<OcrLine>> lines): text(text), box(box), lines(lines) {}
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
friend bool operator==(const OcrBlock& lhs, const OcrBlock& rhs) = default;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
} // namespace margelo::nitro::visionocr
|
|
62
|
+
|
|
63
|
+
namespace margelo::nitro {
|
|
64
|
+
|
|
65
|
+
// C++ OcrBlock <> JS OcrBlock (object)
|
|
66
|
+
template <>
|
|
67
|
+
struct JSIConverter<margelo::nitro::visionocr::OcrBlock> final {
|
|
68
|
+
static inline margelo::nitro::visionocr::OcrBlock fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
69
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
70
|
+
return margelo::nitro::visionocr::OcrBlock(
|
|
71
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text"))),
|
|
72
|
+
JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "box"))),
|
|
73
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrLine>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lines")))
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::visionocr::OcrBlock& arg) {
|
|
77
|
+
jsi::Object obj(runtime);
|
|
78
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::string>::toJSI(runtime, arg.text));
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "box"), JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::toJSI(runtime, arg.box));
|
|
80
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "lines"), JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrLine>>>::toJSI(runtime, arg.lines));
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
84
|
+
if (!value.isObject()) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
jsi::Object obj = value.getObject(runtime);
|
|
88
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
|
|
92
|
+
if (!JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "box")))) return false;
|
|
93
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrLine>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lines")))) return false;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// OcrBox.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
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::visionocr {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (OcrBox).
|
|
39
|
+
*/
|
|
40
|
+
struct OcrBox final {
|
|
41
|
+
public:
|
|
42
|
+
double x SWIFT_PRIVATE;
|
|
43
|
+
double y SWIFT_PRIVATE;
|
|
44
|
+
double width SWIFT_PRIVATE;
|
|
45
|
+
double height SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
OcrBox() = default;
|
|
49
|
+
explicit OcrBox(double x, double y, double width, double height): x(x), y(y), width(width), height(height) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const OcrBox& lhs, const OcrBox& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::visionocr
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ OcrBox <> JS OcrBox (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::visionocr::OcrBox> final {
|
|
62
|
+
static inline margelo::nitro::visionocr::OcrBox fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::visionocr::OcrBox(
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))),
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::visionocr::OcrBox& arg) {
|
|
72
|
+
jsi::Object obj(runtime);
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter<double>::toJSI(runtime, arg.x));
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter<double>::toJSI(runtime, arg.y));
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
|
|
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<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x")))) return false;
|
|
88
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false;
|
|
89
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// OcrLine.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
|
+
// Forward declaration of `OcrWord` to properly resolve imports.
|
|
34
|
+
namespace margelo::nitro::visionocr { struct OcrWord; }
|
|
35
|
+
|
|
36
|
+
#include <string>
|
|
37
|
+
#include "OcrBox.hpp"
|
|
38
|
+
#include <optional>
|
|
39
|
+
#include "OcrWord.hpp"
|
|
40
|
+
#include <vector>
|
|
41
|
+
|
|
42
|
+
namespace margelo::nitro::visionocr {
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A struct which can be represented as a JavaScript object (OcrLine).
|
|
46
|
+
*/
|
|
47
|
+
struct OcrLine final {
|
|
48
|
+
public:
|
|
49
|
+
std::string text SWIFT_PRIVATE;
|
|
50
|
+
std::optional<OcrBox> box SWIFT_PRIVATE;
|
|
51
|
+
std::optional<std::vector<OcrWord>> words SWIFT_PRIVATE;
|
|
52
|
+
std::optional<double> confidence SWIFT_PRIVATE;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
OcrLine() = default;
|
|
56
|
+
explicit OcrLine(std::string text, std::optional<OcrBox> box, std::optional<std::vector<OcrWord>> words, std::optional<double> confidence): text(text), box(box), words(words), confidence(confidence) {}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
friend bool operator==(const OcrLine& lhs, const OcrLine& rhs) = default;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::visionocr
|
|
63
|
+
|
|
64
|
+
namespace margelo::nitro {
|
|
65
|
+
|
|
66
|
+
// C++ OcrLine <> JS OcrLine (object)
|
|
67
|
+
template <>
|
|
68
|
+
struct JSIConverter<margelo::nitro::visionocr::OcrLine> final {
|
|
69
|
+
static inline margelo::nitro::visionocr::OcrLine fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
70
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
71
|
+
return margelo::nitro::visionocr::OcrLine(
|
|
72
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text"))),
|
|
73
|
+
JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "box"))),
|
|
74
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrWord>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "words"))),
|
|
75
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::visionocr::OcrLine& arg) {
|
|
79
|
+
jsi::Object obj(runtime);
|
|
80
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::string>::toJSI(runtime, arg.text));
|
|
81
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "box"), JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::toJSI(runtime, arg.box));
|
|
82
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "words"), JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrWord>>>::toJSI(runtime, arg.words));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "confidence"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.confidence));
|
|
84
|
+
return obj;
|
|
85
|
+
}
|
|
86
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
87
|
+
if (!value.isObject()) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
jsi::Object obj = value.getObject(runtime);
|
|
91
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
|
|
95
|
+
if (!JSIConverter<std::optional<margelo::nitro::visionocr::OcrBox>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "box")))) return false;
|
|
96
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::visionocr::OcrWord>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "words")))) return false;
|
|
97
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))) return false;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// OcrOptions.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 `RLevel` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::visionocr { enum class RLevel; }
|
|
33
|
+
|
|
34
|
+
#include <optional>
|
|
35
|
+
#include "RLevel.hpp"
|
|
36
|
+
#include <string>
|
|
37
|
+
#include <vector>
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::visionocr {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (OcrOptions).
|
|
43
|
+
*/
|
|
44
|
+
struct OcrOptions final {
|
|
45
|
+
public:
|
|
46
|
+
std::optional<bool> includeBoxes SWIFT_PRIVATE;
|
|
47
|
+
std::optional<bool> includeConfidence SWIFT_PRIVATE;
|
|
48
|
+
std::optional<RLevel> recognitionLevel SWIFT_PRIVATE;
|
|
49
|
+
std::optional<std::vector<std::string>> recognitionLanguages SWIFT_PRIVATE;
|
|
50
|
+
std::optional<bool> usesLanguageCorrection SWIFT_PRIVATE;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
OcrOptions() = default;
|
|
54
|
+
explicit OcrOptions(std::optional<bool> includeBoxes, std::optional<bool> includeConfidence, std::optional<RLevel> recognitionLevel, std::optional<std::vector<std::string>> recognitionLanguages, std::optional<bool> usesLanguageCorrection): includeBoxes(includeBoxes), includeConfidence(includeConfidence), recognitionLevel(recognitionLevel), recognitionLanguages(recognitionLanguages), usesLanguageCorrection(usesLanguageCorrection) {}
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
friend bool operator==(const OcrOptions& lhs, const OcrOptions& rhs) = default;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
} // namespace margelo::nitro::visionocr
|
|
61
|
+
|
|
62
|
+
namespace margelo::nitro {
|
|
63
|
+
|
|
64
|
+
// C++ OcrOptions <> JS OcrOptions (object)
|
|
65
|
+
template <>
|
|
66
|
+
struct JSIConverter<margelo::nitro::visionocr::OcrOptions> final {
|
|
67
|
+
static inline margelo::nitro::visionocr::OcrOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
68
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
69
|
+
return margelo::nitro::visionocr::OcrOptions(
|
|
70
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "includeBoxes"))),
|
|
71
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "includeConfidence"))),
|
|
72
|
+
JSIConverter<std::optional<margelo::nitro::visionocr::RLevel>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "recognitionLevel"))),
|
|
73
|
+
JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "recognitionLanguages"))),
|
|
74
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "usesLanguageCorrection")))
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::visionocr::OcrOptions& arg) {
|
|
78
|
+
jsi::Object obj(runtime);
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "includeBoxes"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.includeBoxes));
|
|
80
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "includeConfidence"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.includeConfidence));
|
|
81
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "recognitionLevel"), JSIConverter<std::optional<margelo::nitro::visionocr::RLevel>>::toJSI(runtime, arg.recognitionLevel));
|
|
82
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "recognitionLanguages"), JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.recognitionLanguages));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "usesLanguageCorrection"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.usesLanguageCorrection));
|
|
84
|
+
return obj;
|
|
85
|
+
}
|
|
86
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
87
|
+
if (!value.isObject()) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
jsi::Object obj = value.getObject(runtime);
|
|
91
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "includeBoxes")))) return false;
|
|
95
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "includeConfidence")))) return false;
|
|
96
|
+
if (!JSIConverter<std::optional<margelo::nitro::visionocr::RLevel>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "recognitionLevel")))) return false;
|
|
97
|
+
if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "recognitionLanguages")))) return false;
|
|
98
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "usesLanguageCorrection")))) return false;
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
} // namespace margelo::nitro
|