@imagowave/vision-ocr 0.0.1 → 0.0.2
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/README.md +3 -36
- package/android/src/main/java/com/margelo/nitro/visionocr/{VisionOcr.kt → HybridVisionOCR.kt} +1 -1
- package/ios/{VisionOCR.swift → HybridVisionOCR.swift} +1 -1
- package/nitro.json +22 -17
- package/nitrogen/generated/android/NitroVisionOcrOnLoad.cpp +16 -2
- package/nitrogen/generated/ios/NitroVisionOcrAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroVisionOcrAutolinking.swift +26 -0
- package/package.json +2 -7
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -1,38 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @imagowave/vision-ocr
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Inspired by @bear-block/vision-camera-ocr but updated to work with Vision Camera 5. (as a nitro module)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Clone this repo, and change all `$$*$$` names according to your `nitro.json` file.
|
|
8
|
-
|
|
9
|
-
## Contributing
|
|
10
|
-
|
|
11
|
-
Contribute a change to this template to update it for newer React Native versions.
|
|
12
|
-
|
|
13
|
-
## Structure
|
|
14
|
-
|
|
15
|
-
- [`android/`](android): All your `android`-specific implementations.
|
|
16
|
-
- [`build.gradle`](android/build.gradle): The gradle build file. This contains four important pieces:
|
|
17
|
-
1. Standard react-native library boilerplate code
|
|
18
|
-
2. Configures Kotlin (`apply plugin: 'org.jetbrains.kotlin.android'`)
|
|
19
|
-
3. Adds all Nitrogen files (`apply from: '.../NitroVisionOcr+autolinking.gradle'`)
|
|
20
|
-
4. Triggers the native C++ build (via CMake/`externalNativeBuild`)
|
|
21
|
-
- [`CMakeLists.txt`](android/CMakeLists.txt): The CMake build file to build C++ code. This contains four important pieces:
|
|
22
|
-
1. Creates a library called `NitroVisionOcr` (same as in `nitro.json`)
|
|
23
|
-
2. Adds all Nitrogen files (`include(.../NitroVisionOcr+autolinking.cmake)`)
|
|
24
|
-
3. Adds all custom C++ files (only `HybridTestObjectCpp.cpp`)
|
|
25
|
-
4. Adds a `cpp-adapter.cpp` file, which autolinks all C++ HybridObjects (only `HybridTestObjectCpp`)
|
|
26
|
-
- [`src/main/java/com/margelo/nitro/visionocr/`](android/src/main/java/com/margelo/nitro/visionocr/): All Kotlin implementations.
|
|
27
|
-
- [`NitroVisionOcrPackage.kt`](android/src/main/java/com/margelo/nitro/visionocr/NitroVisionOcrPackage.kt): The react-native package. You need this because the react-native CLI only adds libraries if they have a `*Package.kt` file. In here, you can autolink all Kotlin HybridObjects.
|
|
28
|
-
- [`cpp/`](cpp): All your cross-platform implementations. (only `HybridTestObjectCpp.cpp`)
|
|
29
|
-
- [`ios/`](ios): All your iOS-specific implementations.
|
|
30
|
-
- [`nitrogen/`](nitrogen): All files generated by nitrogen. You should commit this folder to git.
|
|
31
|
-
- [`src/`](src): The TypeScript codebase. This defines all HybridObjects and loads them at runtime.
|
|
32
|
-
- [`specs/`](src/specs): All HybridObject types. Nitrogen will run on all `*.nitro.ts` files.
|
|
33
|
-
- [`nitro.json`](nitro.json): The configuration file for nitrogen. This will define all native namespaces, as well as the library name.
|
|
34
|
-
- [`NitroVisionOcr.podspec`](NitroVisionOcr.podspec): The iOS podspec build file to build the iOS code. This contains three important pieces:
|
|
35
|
-
1. Specifies the Pod's name. This must be identical to the name specified in `nitro.json`.
|
|
36
|
-
2. Adds all of your `.swift` or `.cpp` files (implementations).
|
|
37
|
-
3. Adds all Nitrogen files (`add_nitrogen_files(s)`)
|
|
38
|
-
- [`package.json`](package.json): The npm package.json file. `react-native-nitro-modules` should be a `peerDependency`.
|
|
5
|
+
Android side has not been tested.
|
package/android/src/main/java/com/margelo/nitro/visionocr/{VisionOcr.kt → HybridVisionOCR.kt}
RENAMED
|
@@ -16,7 +16,7 @@ import com.mrousavy.camera.frameprocessors.FrameProcessorPlugin
|
|
|
16
16
|
import com.mrousavy.camera.frameprocessors.VisionCameraProxy
|
|
17
17
|
import java.util.HashMap
|
|
18
18
|
|
|
19
|
-
class
|
|
19
|
+
class HybridVisionOCR : HybridVisionOCRSpec() {
|
|
20
20
|
private val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)
|
|
21
21
|
|
|
22
22
|
override fun call(frame: Frame, arguments: Map<String, Any>?): HashMap<String, Any>? {
|
|
@@ -5,7 +5,7 @@ import ImageIO
|
|
|
5
5
|
import Vision
|
|
6
6
|
import VisionCamera
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class HybridVisionOCR : HybridVisionOCRSpec {
|
|
9
9
|
func call(frame: (any HybridFrameSpec), options: OcrOptions?) throws -> OcrResult? {
|
|
10
10
|
let includeBoxes = options?.includeBoxes ?? false
|
|
11
11
|
let includeConfidence = options?.includeConfidence ?? false
|
package/nitro.json
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"cxxNamespace": ["visionocr"],
|
|
4
|
+
"ios": {
|
|
5
|
+
"iosModuleName": "NitroVisionOcr"
|
|
6
|
+
},
|
|
7
|
+
"android": {
|
|
8
|
+
"androidNamespace": ["visionocr"],
|
|
9
|
+
"androidCxxLibName": "NitroVisionOcr"
|
|
10
|
+
},
|
|
11
|
+
"autolinking": {
|
|
12
|
+
"NitroVisionOcr": {
|
|
13
|
+
"ios": {
|
|
14
|
+
"language": "swift",
|
|
15
|
+
"implementationClassName": "HybridVisionOCR"
|
|
16
|
+
},
|
|
17
|
+
"android": {
|
|
18
|
+
"language": "kotlin",
|
|
19
|
+
"implementationClassName": "HybridVisionOCR"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"ignorePaths": ["**/node_modules"]
|
|
19
24
|
}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
18
|
#include "JHybridVisionOCRSpec.hpp"
|
|
19
|
+
#include "JHybridNitroVisionOcrSpec.hpp"
|
|
20
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
19
21
|
|
|
20
22
|
namespace margelo::nitro::visionocr {
|
|
21
23
|
|
|
@@ -25,7 +27,14 @@ int initialize(JavaVM* vm) {
|
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
struct JHybridNitroVisionOcrSpecImpl: public jni::JavaClass<JHybridNitroVisionOcrSpecImpl, JHybridNitroVisionOcrSpec::JavaPart> {
|
|
31
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/visionocr/HybridVisionOCR;";
|
|
32
|
+
static std::shared_ptr<JHybridNitroVisionOcrSpec> create() {
|
|
33
|
+
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridNitroVisionOcrSpecImpl::javaobject()>();
|
|
34
|
+
jni::local_ref<JHybridNitroVisionOcrSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
35
|
+
return javaPart->getJHybridNitroVisionOcrSpec();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
29
38
|
|
|
30
39
|
void registerAllNatives() {
|
|
31
40
|
using namespace margelo::nitro;
|
|
@@ -35,7 +44,12 @@ void registerAllNatives() {
|
|
|
35
44
|
margelo::nitro::visionocr::JHybridVisionOCRSpec::CxxPart::registerNatives();
|
|
36
45
|
|
|
37
46
|
// Register Nitro Hybrid Objects
|
|
38
|
-
|
|
47
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
48
|
+
"NitroVisionOcr",
|
|
49
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
50
|
+
return JHybridNitroVisionOcrSpecImpl::create();
|
|
51
|
+
}
|
|
52
|
+
);
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
} // namespace margelo::nitro::visionocr
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVisionOcrAutolinking.mm
|
|
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 <Foundation/Foundation.h>
|
|
9
|
+
#import <NitroModules/HybridObjectRegistry.hpp>
|
|
10
|
+
#import "NitroVisionOcr-Swift-Cxx-Umbrella.hpp"
|
|
11
|
+
#import <type_traits>
|
|
12
|
+
|
|
13
|
+
#include "HybridNitroVisionOcrSpecSwift.hpp"
|
|
14
|
+
|
|
15
|
+
@interface NitroVisionOcrAutolinking : NSObject
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
@implementation NitroVisionOcrAutolinking
|
|
19
|
+
|
|
20
|
+
+ (void) load {
|
|
21
|
+
using namespace margelo::nitro;
|
|
22
|
+
using namespace margelo::nitro::visionocr;
|
|
23
|
+
|
|
24
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
25
|
+
"NitroVisionOcr",
|
|
26
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
27
|
+
std::shared_ptr<HybridNitroVisionOcrSpec> hybridObject = NitroVisionOcr::NitroVisionOcrAutolinking::createNitroVisionOcr();
|
|
28
|
+
return hybridObject;
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVisionOcrAutolinking.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
|
+
// TODO: Use empty enums once Swift supports exporting them as namespaces
|
|
11
|
+
// See: https://github.com/swiftlang/swift/pull/83616
|
|
12
|
+
public final class NitroVisionOcrAutolinking {
|
|
13
|
+
public typealias bridge = margelo.nitro.visionocr.bridge.swift
|
|
14
|
+
|
|
15
|
+
public static func createNitroVisionOcr() -> bridge.std__shared_ptr_HybridNitroVisionOcrSpec_ {
|
|
16
|
+
let hybridObject = HybridVisionOCR()
|
|
17
|
+
return { () -> bridge.std__shared_ptr_HybridNitroVisionOcrSpec_ in
|
|
18
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
19
|
+
return __cxxWrapped.getCxxPart()
|
|
20
|
+
}()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static func isNitroVisionOcrRecyclable() -> Bool {
|
|
24
|
+
return HybridVisionOCR.self is any RecyclableView.Type
|
|
25
|
+
}
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imagowave/vision-ocr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A React Native module for performing OCR using the Vision framework on iOS and ML Kit on Android.",
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "lib/index",
|
|
7
|
-
"types": "lib/types.ts",
|
|
8
|
-
"react-native": "src/index",
|
|
9
|
-
"source": "src/index",
|
|
5
|
+
"main": "src/index",
|
|
10
6
|
"files": [
|
|
11
7
|
"src",
|
|
12
8
|
"react-native.config.js",
|
|
@@ -33,7 +29,6 @@
|
|
|
33
29
|
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
34
30
|
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
35
31
|
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
|
|
36
|
-
"typescript": "tsc",
|
|
37
32
|
"specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\""
|
|
38
33
|
},
|
|
39
34
|
"keywords": [
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { OcrOptions, OcrResult } from "./types";
|
|
|
6
6
|
|
|
7
7
|
export * from "./types";
|
|
8
8
|
|
|
9
|
-
const plugin = NitroModules.createHybridObject<VisionOCR>("
|
|
9
|
+
const plugin = NitroModules.createHybridObject<VisionOCR>("NitroVisionOcr");
|
|
10
10
|
|
|
11
11
|
export default plugin;
|
|
12
12
|
|