@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,81 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroVisionOcr+autolinking.cmake
|
|
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
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroVisionOcr+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROVISIONOCR_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
NitroVisionOcr PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/NitroVisionOcrOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridVisionOCRSpec.cpp
|
|
37
|
+
# Android-specific Nitrogen C++ sources
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridVisionOCRSpec.cpp
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
42
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
43
|
+
target_compile_definitions(
|
|
44
|
+
NitroVisionOcr PRIVATE
|
|
45
|
+
-DFOLLY_NO_CONFIG=1
|
|
46
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
47
|
+
-DFOLLY_USE_LIBCPP=1
|
|
48
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
49
|
+
-DFOLLY_MOBILE=1
|
|
50
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
51
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
52
|
+
# Once we target android-23 above, we can comment
|
|
53
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
54
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Add all libraries required by the generated specs
|
|
58
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
59
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
60
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
61
|
+
|
|
62
|
+
# Link all libraries together
|
|
63
|
+
target_link_libraries(
|
|
64
|
+
NitroVisionOcr
|
|
65
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
66
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
67
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
71
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
72
|
+
target_link_libraries(
|
|
73
|
+
NitroVisionOcr
|
|
74
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
75
|
+
)
|
|
76
|
+
else()
|
|
77
|
+
target_link_libraries(
|
|
78
|
+
NitroVisionOcr
|
|
79
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
80
|
+
)
|
|
81
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVisionOcr+autolinking.gradle
|
|
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
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/NitroVisionOcr+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 NitroVisionOcr is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVisionOcrOnLoad.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
|
+
#ifndef BUILDING_NITROVISIONOCR_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroVisionOcrOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroVisionOcrOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridVisionOCRSpec.hpp"
|
|
19
|
+
|
|
20
|
+
namespace margelo::nitro::visionocr {
|
|
21
|
+
|
|
22
|
+
int initialize(JavaVM* vm) {
|
|
23
|
+
return facebook::jni::initialize(vm, []() {
|
|
24
|
+
::margelo::nitro::visionocr::registerAllNatives();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
void registerAllNatives() {
|
|
31
|
+
using namespace margelo::nitro;
|
|
32
|
+
using namespace margelo::nitro::visionocr;
|
|
33
|
+
|
|
34
|
+
// Register native JNI methods
|
|
35
|
+
margelo::nitro::visionocr::JHybridVisionOCRSpec::CxxPart::registerNatives();
|
|
36
|
+
|
|
37
|
+
// Register Nitro Hybrid Objects
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVisionOcrOnLoad.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
|
+
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::visionocr {
|
|
13
|
+
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the native (C++) part of NitroVisionOcr, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
21
|
+
* Example:
|
|
22
|
+
* ```cpp (cpp-adapter.cpp)
|
|
23
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroVisionOcr HybridObjects
|
|
26
|
+
* margelo::nitro::visionocr::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
void registerAllNatives();
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridVisionOCRSpec.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 "JHybridVisionOCRSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `OcrResult` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::visionocr { struct OcrResult; }
|
|
12
|
+
// Forward declaration of `OcrBlock` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::visionocr { struct OcrBlock; }
|
|
14
|
+
// Forward declaration of `OcrBox` to properly resolve imports.
|
|
15
|
+
namespace margelo::nitro::visionocr { struct OcrBox; }
|
|
16
|
+
// Forward declaration of `OcrLine` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::visionocr { struct OcrLine; }
|
|
18
|
+
// Forward declaration of `OcrWord` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::visionocr { struct OcrWord; }
|
|
20
|
+
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
22
|
+
// Forward declaration of `OcrOptions` to properly resolve imports.
|
|
23
|
+
namespace margelo::nitro::visionocr { struct OcrOptions; }
|
|
24
|
+
// Forward declaration of `RLevel` to properly resolve imports.
|
|
25
|
+
namespace margelo::nitro::visionocr { enum class RLevel; }
|
|
26
|
+
|
|
27
|
+
#include "OcrResult.hpp"
|
|
28
|
+
#include <optional>
|
|
29
|
+
#include "JOcrResult.hpp"
|
|
30
|
+
#include <string>
|
|
31
|
+
#include "OcrBlock.hpp"
|
|
32
|
+
#include <vector>
|
|
33
|
+
#include "JOcrBlock.hpp"
|
|
34
|
+
#include "OcrBox.hpp"
|
|
35
|
+
#include "JOcrBox.hpp"
|
|
36
|
+
#include "OcrLine.hpp"
|
|
37
|
+
#include "JOcrLine.hpp"
|
|
38
|
+
#include "OcrWord.hpp"
|
|
39
|
+
#include "JOcrWord.hpp"
|
|
40
|
+
#include <memory>
|
|
41
|
+
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
42
|
+
#include <VisionCamera/JHybridFrameSpec.hpp>
|
|
43
|
+
#include "OcrOptions.hpp"
|
|
44
|
+
#include "JOcrOptions.hpp"
|
|
45
|
+
#include "RLevel.hpp"
|
|
46
|
+
#include "JRLevel.hpp"
|
|
47
|
+
|
|
48
|
+
namespace margelo::nitro::visionocr {
|
|
49
|
+
|
|
50
|
+
std::shared_ptr<JHybridVisionOCRSpec> JHybridVisionOCRSpec::JavaPart::getJHybridVisionOCRSpec() {
|
|
51
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
52
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridVisionOCRSpec>(hybridObject);
|
|
53
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
54
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridVisionOCRSpec!");
|
|
55
|
+
}
|
|
56
|
+
return castHybridObject;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
jni::local_ref<JHybridVisionOCRSpec::CxxPart::jhybriddata> JHybridVisionOCRSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
60
|
+
return makeCxxInstance(jThis);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
std::shared_ptr<JHybridObject> JHybridVisionOCRSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
64
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridVisionOCRSpec::JavaPart>(javaPart);
|
|
65
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
66
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridVisionOCRSpec::JavaPart!");
|
|
67
|
+
}
|
|
68
|
+
return std::make_shared<JHybridVisionOCRSpec>(castJavaPart);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
void JHybridVisionOCRSpec::CxxPart::registerNatives() {
|
|
72
|
+
registerHybrid({
|
|
73
|
+
makeNativeMethod("initHybrid", JHybridVisionOCRSpec::CxxPart::initHybrid),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Properties
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// Methods
|
|
81
|
+
std::optional<OcrResult> JHybridVisionOCRSpec::call(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame, const std::optional<OcrOptions>& options) {
|
|
82
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JOcrResult>(jni::alias_ref<margelo::nitro::camera::JHybridFrameSpec::JavaPart> /* frame */, jni::alias_ref<JOcrOptions> /* options */)>("call");
|
|
83
|
+
auto __result = method(_javaPart, std::dynamic_pointer_cast<margelo::nitro::camera::JHybridFrameSpec>(frame)->getJavaPart(), options.has_value() ? JOcrOptions::fromCpp(options.value()) : nullptr);
|
|
84
|
+
return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridVisionOCRSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::visionocr {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridVisionOCRSpec: public virtual HybridVisionOCRSpec, public virtual JHybridObject {
|
|
22
|
+
public:
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visionocr/HybridVisionOCRSpec;";
|
|
25
|
+
std::shared_ptr<JHybridVisionOCRSpec> getJHybridVisionOCRSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visionocr/HybridVisionOCRSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
explicit JHybridVisionOCRSpec(const jni::local_ref<JHybridVisionOCRSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridVisionOCRSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
41
|
+
~JHybridVisionOCRSpec() override {
|
|
42
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
43
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridVisionOCRSpec::JavaPart>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
std::optional<OcrResult> call(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame, const std::optional<OcrOptions>& options) override;
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
jni::global_ref<JHybridVisionOCRSpec::JavaPart> _javaPart;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JOcrBlock.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 <fbjni/fbjni.h>
|
|
11
|
+
#include "OcrBlock.hpp"
|
|
12
|
+
|
|
13
|
+
#include "JOcrBox.hpp"
|
|
14
|
+
#include "JOcrLine.hpp"
|
|
15
|
+
#include "JOcrWord.hpp"
|
|
16
|
+
#include "OcrBox.hpp"
|
|
17
|
+
#include "OcrLine.hpp"
|
|
18
|
+
#include "OcrWord.hpp"
|
|
19
|
+
#include <optional>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
namespace margelo::nitro::visionocr {
|
|
24
|
+
|
|
25
|
+
using namespace facebook;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The C++ JNI bridge between the C++ struct "OcrBlock" and the the Kotlin data class "OcrBlock".
|
|
29
|
+
*/
|
|
30
|
+
struct JOcrBlock final: public jni::JavaClass<JOcrBlock> {
|
|
31
|
+
public:
|
|
32
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visionocr/OcrBlock;";
|
|
33
|
+
|
|
34
|
+
public:
|
|
35
|
+
/**
|
|
36
|
+
* Convert this Java/Kotlin-based struct to the C++ struct OcrBlock by copying all values to C++.
|
|
37
|
+
*/
|
|
38
|
+
[[maybe_unused]]
|
|
39
|
+
[[nodiscard]]
|
|
40
|
+
OcrBlock toCpp() const {
|
|
41
|
+
static const auto clazz = javaClassStatic();
|
|
42
|
+
static const auto fieldText = clazz->getField<jni::JString>("text");
|
|
43
|
+
jni::local_ref<jni::JString> text = this->getFieldValue(fieldText);
|
|
44
|
+
static const auto fieldBox = clazz->getField<JOcrBox>("box");
|
|
45
|
+
jni::local_ref<JOcrBox> box = this->getFieldValue(fieldBox);
|
|
46
|
+
static const auto fieldLines = clazz->getField<jni::JArrayClass<JOcrLine>>("lines");
|
|
47
|
+
jni::local_ref<jni::JArrayClass<JOcrLine>> lines = this->getFieldValue(fieldLines);
|
|
48
|
+
return OcrBlock(
|
|
49
|
+
text->toStdString(),
|
|
50
|
+
box != nullptr ? std::make_optional(box->toCpp()) : std::nullopt,
|
|
51
|
+
lines != nullptr ? std::make_optional([&](auto&& __input) {
|
|
52
|
+
size_t __size = __input->size();
|
|
53
|
+
std::vector<OcrLine> __vector;
|
|
54
|
+
__vector.reserve(__size);
|
|
55
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
56
|
+
auto __element = __input->getElement(__i);
|
|
57
|
+
__vector.push_back(__element->toCpp());
|
|
58
|
+
}
|
|
59
|
+
return __vector;
|
|
60
|
+
}(lines)) : std::nullopt
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public:
|
|
65
|
+
/**
|
|
66
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
67
|
+
*/
|
|
68
|
+
[[maybe_unused]]
|
|
69
|
+
static jni::local_ref<JOcrBlock::javaobject> fromCpp(const OcrBlock& value) {
|
|
70
|
+
using JSignature = JOcrBlock(jni::alias_ref<jni::JString>, jni::alias_ref<JOcrBox>, jni::alias_ref<jni::JArrayClass<JOcrLine>>);
|
|
71
|
+
static const auto clazz = javaClassStatic();
|
|
72
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
73
|
+
return create(
|
|
74
|
+
clazz,
|
|
75
|
+
jni::make_jstring(value.text),
|
|
76
|
+
value.box.has_value() ? JOcrBox::fromCpp(value.box.value()) : nullptr,
|
|
77
|
+
value.lines.has_value() ? [&](auto&& __input) {
|
|
78
|
+
size_t __size = __input.size();
|
|
79
|
+
jni::local_ref<jni::JArrayClass<JOcrLine>> __array = jni::JArrayClass<JOcrLine>::newArray(__size);
|
|
80
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
81
|
+
const auto& __element = __input[__i];
|
|
82
|
+
auto __elementJni = JOcrLine::fromCpp(__element);
|
|
83
|
+
__array->setElement(__i, *__elementJni);
|
|
84
|
+
}
|
|
85
|
+
return __array;
|
|
86
|
+
}(value.lines.value()) : nullptr
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JOcrBox.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 <fbjni/fbjni.h>
|
|
11
|
+
#include "OcrBox.hpp"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::visionocr {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "OcrBox" and the the Kotlin data class "OcrBox".
|
|
21
|
+
*/
|
|
22
|
+
struct JOcrBox final: public jni::JavaClass<JOcrBox> {
|
|
23
|
+
public:
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visionocr/OcrBox;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct OcrBox by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
OcrBox toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldX = clazz->getField<double>("x");
|
|
35
|
+
double x = this->getFieldValue(fieldX);
|
|
36
|
+
static const auto fieldY = clazz->getField<double>("y");
|
|
37
|
+
double y = this->getFieldValue(fieldY);
|
|
38
|
+
static const auto fieldWidth = clazz->getField<double>("width");
|
|
39
|
+
double width = this->getFieldValue(fieldWidth);
|
|
40
|
+
static const auto fieldHeight = clazz->getField<double>("height");
|
|
41
|
+
double height = this->getFieldValue(fieldHeight);
|
|
42
|
+
return OcrBox(
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
width,
|
|
46
|
+
height
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
/**
|
|
52
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
53
|
+
*/
|
|
54
|
+
[[maybe_unused]]
|
|
55
|
+
static jni::local_ref<JOcrBox::javaobject> fromCpp(const OcrBox& value) {
|
|
56
|
+
using JSignature = JOcrBox(double, double, double, double);
|
|
57
|
+
static const auto clazz = javaClassStatic();
|
|
58
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
59
|
+
return create(
|
|
60
|
+
clazz,
|
|
61
|
+
value.x,
|
|
62
|
+
value.y,
|
|
63
|
+
value.width,
|
|
64
|
+
value.height
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JOcrLine.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 <fbjni/fbjni.h>
|
|
11
|
+
#include "OcrLine.hpp"
|
|
12
|
+
|
|
13
|
+
#include "JOcrBox.hpp"
|
|
14
|
+
#include "JOcrWord.hpp"
|
|
15
|
+
#include "OcrBox.hpp"
|
|
16
|
+
#include "OcrWord.hpp"
|
|
17
|
+
#include <optional>
|
|
18
|
+
#include <string>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::visionocr {
|
|
22
|
+
|
|
23
|
+
using namespace facebook;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The C++ JNI bridge between the C++ struct "OcrLine" and the the Kotlin data class "OcrLine".
|
|
27
|
+
*/
|
|
28
|
+
struct JOcrLine final: public jni::JavaClass<JOcrLine> {
|
|
29
|
+
public:
|
|
30
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visionocr/OcrLine;";
|
|
31
|
+
|
|
32
|
+
public:
|
|
33
|
+
/**
|
|
34
|
+
* Convert this Java/Kotlin-based struct to the C++ struct OcrLine by copying all values to C++.
|
|
35
|
+
*/
|
|
36
|
+
[[maybe_unused]]
|
|
37
|
+
[[nodiscard]]
|
|
38
|
+
OcrLine toCpp() const {
|
|
39
|
+
static const auto clazz = javaClassStatic();
|
|
40
|
+
static const auto fieldText = clazz->getField<jni::JString>("text");
|
|
41
|
+
jni::local_ref<jni::JString> text = this->getFieldValue(fieldText);
|
|
42
|
+
static const auto fieldBox = clazz->getField<JOcrBox>("box");
|
|
43
|
+
jni::local_ref<JOcrBox> box = this->getFieldValue(fieldBox);
|
|
44
|
+
static const auto fieldWords = clazz->getField<jni::JArrayClass<JOcrWord>>("words");
|
|
45
|
+
jni::local_ref<jni::JArrayClass<JOcrWord>> words = this->getFieldValue(fieldWords);
|
|
46
|
+
static const auto fieldConfidence = clazz->getField<jni::JDouble>("confidence");
|
|
47
|
+
jni::local_ref<jni::JDouble> confidence = this->getFieldValue(fieldConfidence);
|
|
48
|
+
return OcrLine(
|
|
49
|
+
text->toStdString(),
|
|
50
|
+
box != nullptr ? std::make_optional(box->toCpp()) : std::nullopt,
|
|
51
|
+
words != nullptr ? std::make_optional([&](auto&& __input) {
|
|
52
|
+
size_t __size = __input->size();
|
|
53
|
+
std::vector<OcrWord> __vector;
|
|
54
|
+
__vector.reserve(__size);
|
|
55
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
56
|
+
auto __element = __input->getElement(__i);
|
|
57
|
+
__vector.push_back(__element->toCpp());
|
|
58
|
+
}
|
|
59
|
+
return __vector;
|
|
60
|
+
}(words)) : std::nullopt,
|
|
61
|
+
confidence != nullptr ? std::make_optional(confidence->value()) : std::nullopt
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
/**
|
|
67
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
68
|
+
*/
|
|
69
|
+
[[maybe_unused]]
|
|
70
|
+
static jni::local_ref<JOcrLine::javaobject> fromCpp(const OcrLine& value) {
|
|
71
|
+
using JSignature = JOcrLine(jni::alias_ref<jni::JString>, jni::alias_ref<JOcrBox>, jni::alias_ref<jni::JArrayClass<JOcrWord>>, jni::alias_ref<jni::JDouble>);
|
|
72
|
+
static const auto clazz = javaClassStatic();
|
|
73
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
74
|
+
return create(
|
|
75
|
+
clazz,
|
|
76
|
+
jni::make_jstring(value.text),
|
|
77
|
+
value.box.has_value() ? JOcrBox::fromCpp(value.box.value()) : nullptr,
|
|
78
|
+
value.words.has_value() ? [&](auto&& __input) {
|
|
79
|
+
size_t __size = __input.size();
|
|
80
|
+
jni::local_ref<jni::JArrayClass<JOcrWord>> __array = jni::JArrayClass<JOcrWord>::newArray(__size);
|
|
81
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
82
|
+
const auto& __element = __input[__i];
|
|
83
|
+
auto __elementJni = JOcrWord::fromCpp(__element);
|
|
84
|
+
__array->setElement(__i, *__elementJni);
|
|
85
|
+
}
|
|
86
|
+
return __array;
|
|
87
|
+
}(value.words.value()) : nullptr,
|
|
88
|
+
value.confidence.has_value() ? jni::JDouble::valueOf(value.confidence.value()) : nullptr
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
} // namespace margelo::nitro::visionocr
|