dynamsoft-capture-vision-react-native 3.4.1300 → 3.4.3010
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/LICENSE +4 -4
- package/README.md +62 -62
- package/android/README.md +14 -14
- package/android/build.gradle +167 -163
- package/android/gradle.properties +20 -20
- package/android/settings.gradle +5 -5
- package/android/src/main/AndroidManifest.xml +6 -6
- package/android/src/main/AndroidManifest_noPackage.xml +5 -5
- package/android/src/main/cpp/CMakeLists.txt +21 -21
- package/android/src/main/cpp/ImgHO.cpp +94 -94
- package/android/src/main/cpp/ImgHO.h +34 -34
- package/android/src/main/cpp/JsiCore.cpp +296 -296
- package/android/src/main/cpp/JsiCore.h +51 -51
- package/android/src/main/cpp/JsiCvr.cpp +332 -332
- package/android/src/main/cpp/JsiCvr.h +54 -54
- package/android/src/main/cpp/JsiDbr.cpp +283 -283
- package/android/src/main/cpp/JsiDbr.h +26 -26
- package/android/src/main/cpp/JsiDce.cpp +59 -59
- package/android/src/main/cpp/JsiDce.h +17 -17
- package/android/src/main/cpp/JsiDcp.cpp +51 -51
- package/android/src/main/cpp/JsiDcp.h +31 -31
- package/android/src/main/cpp/JsiDdn.cpp +50 -50
- package/android/src/main/cpp/JsiDdn.h +28 -28
- package/android/src/main/cpp/JsiDlr.cpp +60 -60
- package/android/src/main/cpp/JsiDlr.h +26 -26
- package/android/src/main/cpp/JsiUtility.cpp +604 -604
- package/android/src/main/cpp/JsiUtility.h +26 -26
- package/android/src/main/cpp/RawBuffer.cpp +23 -23
- package/android/src/main/cpp/RawBuffer.h +24 -24
- package/android/src/main/cpp/android_log.h +14 -14
- package/android/src/main/dysJniLibsFor86/debug/arm64-v8a/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/debug/armeabi-v7a/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/debug/x86/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/debug/x86_64/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/release/arm64-v8a/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/release/armeabi-v7a/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/release/x86/librn_dys.so +0 -0
- package/android/src/main/dysJniLibsFor86/release/x86_64/librn_dys.so +0 -0
- package/android/src/main/java/com/dynamsoft/reactnativelib/CVRModule.kt +137 -137
- package/android/src/main/java/com/dynamsoft/reactnativelib/CameraViewManager.kt +62 -62
- package/android/src/main/java/com/dynamsoft/reactnativelib/DCEModule.kt +125 -125
- package/android/src/main/java/com/dynamsoft/reactnativelib/DynamsoftBaseModule.kt +8 -8
- package/android/src/main/java/com/dynamsoft/reactnativelib/ISAModule.kt +73 -73
- package/android/src/main/java/com/dynamsoft/reactnativelib/ImageEditorViewManager.kt +14 -14
- package/android/src/main/java/com/dynamsoft/reactnativelib/ImageEditorViewModule.kt +35 -35
- package/android/src/main/java/com/dynamsoft/reactnativelib/ImageManagerModule.kt +15 -15
- package/android/src/main/java/com/dynamsoft/reactnativelib/LicenseModule.kt +29 -29
- package/android/src/main/java/com/dynamsoft/reactnativelib/MultiCrossFilterModule.kt +83 -83
- package/android/src/main/java/com/dynamsoft/reactnativelib/ReactNativeDcvPackage.kt +32 -32
- package/android/src/main/java/com/dynamsoft/reactnativelib/VersionsModule.kt +41 -41
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/Basic.kt +44 -44
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForCore.kt +50 -50
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForCvr.kt +129 -129
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForDBR.kt +157 -157
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForDCE.kt +110 -110
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForDCP.kt +49 -49
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForDDN.kt +85 -85
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ForDLR.kt +72 -72
- package/android/src/main/java/com/dynamsoft/reactnativelib/basicutils/ImageUtil.kt +58 -58
- package/android/src/main/java/com/dynamsoft/reactnativelib/core/ImageSourceAdapterModuleImpl.kt +120 -120
- package/android/src/main/java/com/dynamsoft/reactnativelib/cvr/CaptureVisionRouterModuleImpl.kt +306 -306
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/CameraEnhancerModuleImpl.kt +247 -247
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/CameraLifeCycleOwner.java +14 -14
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/CameraViewManagerImpl.kt +77 -77
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/ImageEditorViewManagerImpl.kt +15 -15
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/ImageEditorViewModuleImpl.kt +110 -110
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/RNCameraView.kt +20 -20
- package/android/src/main/java/com/dynamsoft/reactnativelib/dce/RNImageEditorView.kt +19 -19
- package/android/src/main/java/com/dynamsoft/reactnativelib/license/LicenseModuleImpl.kt +39 -39
- package/android/src/main/java/com/dynamsoft/reactnativelib/utility/ImageManagerModuleImpl.kt +120 -120
- package/android/src/main/java/com/dynamsoft/reactnativelib/utility/MultiCrossFilterModuleImpl.kt +111 -111
- package/app.plugin.js +21 -21
- package/dynamsoft-capture-vision-react-native.podspec +24 -24
- package/ios/CPP/DSImageData+HostObject.h +18 -18
- package/ios/CPP/DSImageData+HostObject.mm +38 -38
- package/ios/CPP/ImageDataHostObject.cpp +87 -87
- package/ios/CPP/ImageDataHostObject.hpp +35 -35
- package/ios/CPP/MutableRawBuffer.cpp +23 -23
- package/ios/CPP/MutableRawBuffer.hpp +23 -23
- package/ios/CPP/RNDynamsoft+JSI.h +22 -22
- package/ios/CPP/RNDynamsoft+JSI.mm +303 -303
- package/ios/CPP/RNDynamsoft+Json.h +93 -93
- package/ios/CPP/RNDynamsoft+Json.m +733 -733
- package/ios/CPP/YeetJSIUtils.h +56 -56
- package/ios/CPP/YeetJSIUtils.mm +208 -208
- package/ios/RNDynamsoftCameraView.h +31 -31
- package/ios/RNDynamsoftCameraView.m +108 -108
- package/ios/RNDynamsoftCameraViewManager.h +14 -14
- package/ios/RNDynamsoftCameraViewManager.m +195 -195
- package/ios/RNDynamsoftCaptureVisionRouter.h +18 -18
- package/ios/RNDynamsoftCaptureVisionRouter.mm +532 -532
- package/ios/RNDynamsoftImageEditorView.h +17 -17
- package/ios/RNDynamsoftImageEditorView.m +25 -25
- package/ios/RNDynamsoftImageEditorViewManager.h +14 -14
- package/ios/RNDynamsoftImageEditorViewManager.mm +183 -183
- package/ios/RNDynamsoftImageManager.h +14 -14
- package/ios/RNDynamsoftImageManager.mm +369 -369
- package/ios/RNDynamsoftImageSourceAdapter.h +19 -19
- package/ios/RNDynamsoftImageSourceAdapter.mm +255 -255
- package/ios/RNDynamsoftLicense.h +14 -14
- package/ios/RNDynamsoftLicense.m +62 -62
- package/ios/RNDynamsoftMultiCrossFilter.h +14 -14
- package/ios/RNDynamsoftMultiCrossFilter.m +145 -145
- package/ios/RNDynamsoftVersions.h +13 -13
- package/ios/RNDynamsoftVersions.m +27 -27
- package/package.json +48 -48
- package/src/NativeDynamsoftVersionsModule.tsx +20 -20
- package/src/VersionsModule.tsx +7 -7
- package/src/core/CapturedResultBase.tsx +18 -18
- package/src/core/CapturedResultItem.tsx +23 -23
- package/src/core/CoreModule.tsx +9 -9
- package/src/core/DSRect.tsx +29 -29
- package/src/core/EnumCaptureResultItemType.tsx +52 -52
- package/src/core/EnumColourChannelUsageType.tsx +26 -26
- package/src/core/EnumCrossVerificationStatus.tsx +46 -46
- package/src/core/EnumGrayscaleEnhancementMode.tsx +46 -46
- package/src/core/EnumGrayscaleTransformationMode.tsx +35 -35
- package/src/core/EnumImageFileFormat.tsx +6 -6
- package/src/core/EnumPixelFormat.tsx +53 -53
- package/src/core/ImageData.tsx +87 -87
- package/src/core/ImageSourceAdapter.tsx +160 -160
- package/src/core/NativeDynamsoftImageSourceAdapterModule.tsx +29 -29
- package/src/core/Point.tsx +13 -13
- package/src/core/Quadrilateral.tsx +12 -12
- package/src/core/index.tsx +18 -18
- package/src/cvr/CaptureVisionRouter.tsx +683 -683
- package/src/cvr/CaptureVisionRouterModule.tsx +9 -9
- package/src/cvr/CapturedResult.tsx +123 -123
- package/src/cvr/CapturedResultFilter.tsx +13 -13
- package/src/cvr/CapturedResultReceiver.tsx +71 -71
- package/src/cvr/EnumPresetTemplate.tsx +81 -81
- package/src/cvr/NativeDynamsoftCaptureVisionRouterModule.tsx +25 -25
- package/src/cvr/SimplifiedCaptureVisionSettings.tsx +61 -61
- package/src/cvr/index.tsx +11 -11
- package/src/dbr/BarcodeDetails.tsx +51 -51
- package/src/dbr/BarcodeReaderModule.tsx +9 -9
- package/src/dbr/BarcodeResultItem.tsx +65 -65
- package/src/dbr/DecodedBarcodesResult.tsx +14 -14
- package/src/dbr/ECISegment.tsx +23 -23
- package/src/dbr/EnumBarcodeFormat.tsx +112 -112
- package/src/dbr/EnumDeblurMode.tsx +29 -29
- package/src/dbr/EnumLocalizationMode.tsx +27 -27
- package/src/dbr/EnumQRCodeErrorCorrectionLevel.tsx +6 -6
- package/src/dbr/SimplifiedBarcodeReaderSettings.tsx +80 -80
- package/src/dbr/index.tsx +9 -9
- package/src/dce/CameraEnhancer.tsx +254 -254
- package/src/dce/CameraEnhancerModule.tsx +9 -9
- package/src/dce/CameraView.tsx +100 -100
- package/src/dce/DynamsoftCameraViewNativeComponent.ts +96 -96
- package/src/dce/DynamsoftImageEditorViewNativeComponent.ts +9 -9
- package/src/dce/EnumCameraPosition.tsx +25 -25
- package/src/dce/EnumDrawingLayerId.tsx +17 -17
- package/src/dce/EnumEnhancedFeatures.tsx +24 -24
- package/src/dce/EnumFocusMode.tsx +6 -6
- package/src/dce/EnumResolution.tsx +8 -8
- package/src/dce/EnumTorchState.tsx +10 -10
- package/src/dce/FeedBack.tsx +28 -28
- package/src/dce/ImageEditorView.tsx +131 -131
- package/src/dce/NativeDynamsoftCameraViewModule.tsx +47 -47
- package/src/dce/NativeDynamsoftImageEditorViewModule.ts +9 -9
- package/src/dce/index.tsx +13 -13
- package/src/dcp/CodeParserDedicatorModule.tsx +9 -9
- package/src/dcp/CodeParserModule.tsx +9 -9
- package/src/dcp/EnumMappingStatus.tsx +14 -14
- package/src/dcp/EnumValidationStatus.tsx +14 -14
- package/src/dcp/ParsedResult.tsx +14 -14
- package/src/dcp/ParsedResultItem.tsx +50 -50
- package/src/dcp/index.tsx +8 -8
- package/src/ddn/DeskewedImageResultItem.tsx +40 -40
- package/src/ddn/DetectedQuadResultItem.tsx +31 -31
- package/src/ddn/DocumentNormalizerModule.tsx +9 -9
- package/src/ddn/EnhancedImageResultItem.tsx +20 -20
- package/src/ddn/EnumImageColourMode.tsx +14 -14
- package/src/ddn/ProcessedDocumentResult.tsx +27 -27
- package/src/ddn/SimplifiedDocumentNormalizerSettings.tsx +65 -65
- package/src/ddn/index.tsx +11 -11
- package/src/dip/ImageProcessingModule.tsx +9 -9
- package/src/dip/index.tsx +1 -1
- package/src/dlr/CharacterResult.tsx +28 -28
- package/src/dlr/LabelRecognizerModule.tsx +9 -9
- package/src/dlr/RecognizedTextLinesResult.tsx +19 -19
- package/src/dlr/SimplifiedLabelRecognizerSettings.tsx +33 -33
- package/src/dlr/TextLineResultItem.tsx +41 -41
- package/src/dlr/index.tsx +8 -8
- package/src/index.tsx +13 -13
- package/src/license/LicenseManager.tsx +49 -49
- package/src/license/LicenseModule.tsx +9 -9
- package/src/license/NativeDynamsoftLicenseModule.tsx +7 -7
- package/src/license/index.tsx +7 -7
- package/src/utility/CrossVerificationCriteria.tsx +11 -11
- package/src/utility/EnumFilterType.tsx +5 -5
- package/src/utility/ImageManager.tsx +348 -348
- package/src/utility/MultiFrameResultCrossFilter.tsx +183 -183
- package/src/utility/NativeDynamsoftImageManagerModule.tsx +7 -7
- package/src/utility/NativeDynamsoftMultiCrossFilterModule.tsx +18 -18
- package/src/utility/UtilityModule.tsx +9 -9
- package/src/utility/index.tsx +4 -4
- package/android/.gitignore +0 -4
|
@@ -1,683 +1,683 @@
|
|
|
1
|
-
import {type EmitterSubscription, NativeEventEmitter, NativeModules, Platform} from "react-native";
|
|
2
|
-
import {EnumCapturedResultItemType, type ImageData, ImageSourceAdapter} from "../core";
|
|
3
|
-
import type {CapturedResultReceiver} from "./CapturedResultReceiver";
|
|
4
|
-
import {type CapturedResult, _populateResults} from "./CapturedResult";
|
|
5
|
-
import type {BarcodeResultItem, DecodedBarcodesResult} from "../dbr";
|
|
6
|
-
import type {ProcessedDocumentResult} from "../ddn";
|
|
7
|
-
import type {RecognizedTextLinesResult} from "../dlr";
|
|
8
|
-
import type {ParsedResult} from "../dcp";
|
|
9
|
-
import type {CapturedResultFilter} from "./CapturedResultFilter";
|
|
10
|
-
import type {SimplifiedCaptureVisionSettings} from "./SimplifiedCaptureVisionSettings";
|
|
11
|
-
import {MultiFrameResultCrossFilter} from "../utility";
|
|
12
|
-
import {CameraEnhancer} from "../dce";
|
|
13
|
-
|
|
14
|
-
// @ts-ignore Check whether __turboModuleProxy exists, it may not
|
|
15
|
-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
16
|
-
|
|
17
|
-
const CvrModule = !isTurboModuleEnabled ?
|
|
18
|
-
NativeModules.DynamsoftCaptureVisionRouterModule :
|
|
19
|
-
require("./NativeDynamsoftCaptureVisionRouterModule").default;
|
|
20
|
-
|
|
21
|
-
const CVREventEmitter = new NativeEventEmitter(CvrModule);
|
|
22
|
-
let isInstalled = false
|
|
23
|
-
const installMethods = () => {
|
|
24
|
-
if (!isInstalled) {
|
|
25
|
-
CvrModule.install()
|
|
26
|
-
isInstalled = true
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The singleton instance of CaptureVisionRouter.
|
|
32
|
-
* */
|
|
33
|
-
let cvr: CaptureVisionRouter | null = null;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The CaptureVisionRouter class defines how a user interacts with image-processing and semantic-processing products in their applications.
|
|
37
|
-
* A CaptureVisionRouter instance accepts and processes images from an image source and returns processing results which may contain Final results or Intermediate Results.
|
|
38
|
-
* <p>
|
|
39
|
-
* In js end of react-native, CaptureVisionRouter uses singleton mode. You can only get CaptureVisionRouter instance by {@link CaptureVisionRouter.getInstance}.
|
|
40
|
-
* */
|
|
41
|
-
export class CaptureVisionRouter {
|
|
42
|
-
private constructor() {
|
|
43
|
-
CvrModule.createInstance();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get the singleton instance of CaptureVisionRouter.
|
|
48
|
-
* <p>
|
|
49
|
-
* This method ensures that only one instance of CaptureVisionRouter is created
|
|
50
|
-
* and reused throughout the application. If an instance already exists, it will
|
|
51
|
-
* return the existing one. Otherwise, it will create a new instance and return it.
|
|
52
|
-
*
|
|
53
|
-
* @returns {CaptureVisionRouter} The singleton instance of CaptureVisionRouter.
|
|
54
|
-
* */
|
|
55
|
-
static getInstance(): CaptureVisionRouter {
|
|
56
|
-
if (cvr) {
|
|
57
|
-
return cvr;
|
|
58
|
-
}
|
|
59
|
-
return cvr = new CaptureVisionRouter();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Destroys the CaptureVisionRouter instance and releases all associated resources.
|
|
64
|
-
* After calling this method, the instance will be set to null and cannot be used anymore.
|
|
65
|
-
* Only call this method when you want to completely dispose the CaptureVisionRouter instance, otherwise just call {@link CaptureVisionRouter.stopCapturing} to stop the capturing process.
|
|
66
|
-
*/
|
|
67
|
-
dispose() {
|
|
68
|
-
CvrModule.destroyInstance();
|
|
69
|
-
cvr = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Sets the global number of threads used internally for model execution.
|
|
74
|
-
*
|
|
75
|
-
* @param intraOpNumThreads - Number of threads used internally for model execution. Valid range: [0, 256].
|
|
76
|
-
* If the value is outside the range [0, 256], it will be treated as 0 (default).
|
|
77
|
-
*/
|
|
78
|
-
static setGlobalIntraOpNumThreads(intraOpNumThreads: number) {
|
|
79
|
-
CvrModule.setGlobalIntraOpNumThreads(intraOpNumThreads);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Clears all deep learning models from buffer to free up memory.
|
|
84
|
-
*/
|
|
85
|
-
static clearDLModelBuffers() {
|
|
86
|
-
CvrModule.clearDLModelBuffers();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Initiates a capturing process based on a specified template. This process is repeated for each image fetched from the source.
|
|
91
|
-
* <p>Code Snippet:</p>
|
|
92
|
-
*
|
|
93
|
-
*```
|
|
94
|
-
* let router = CaptureVisionRouter.getInstance();
|
|
95
|
-
* await router.startCapturing('ReadSingleBarcode');
|
|
96
|
-
* ```
|
|
97
|
-
* @param templateName - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
98
|
-
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
99
|
-
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
100
|
-
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
101
|
-
*
|
|
102
|
-
* @return Promise<void> - A promise that resolves when the capturing process has successfully started. It does not provide any value upon resolution.
|
|
103
|
-
* @throws Error - If the capturing process fails to start, the promise will be rejected with an error.
|
|
104
|
-
* The error may occur due to invalid template names, or a capturing process is already in progress, etc.
|
|
105
|
-
*
|
|
106
|
-
* @remarks - Always make sure there is no capturing in process or just call `await CaptureVisionRouter.stopCapturing()` to stop any ongoing capturing process
|
|
107
|
-
* before calling `startCapturing`.
|
|
108
|
-
*
|
|
109
|
-
* @see {@link EnumPresetTemplate}
|
|
110
|
-
* */
|
|
111
|
-
startCapturing(templateName: string | undefined | null = ""): Promise<void> {
|
|
112
|
-
return CvrModule.startCapturing(templateName)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Stops the capturing process.
|
|
118
|
-
* <p>Code Snippet:</p>
|
|
119
|
-
*
|
|
120
|
-
*```
|
|
121
|
-
* let router = await CaptureVisionRouter.getInstance();
|
|
122
|
-
* await router.startCapturing("ReadSingleBarcode");
|
|
123
|
-
* // ...
|
|
124
|
-
* router.stopCapturing();
|
|
125
|
-
* ```
|
|
126
|
-
* */
|
|
127
|
-
stopCapturing(): Promise<void> {
|
|
128
|
-
return CvrModule.stopCapturing()
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Switch the capturing template during the image processing workflow.
|
|
133
|
-
*
|
|
134
|
-
* @param templateName -The name of the new capturing template to apply.
|
|
135
|
-
*
|
|
136
|
-
* @return Promise<void> - A promise that resolves when the template switch is successful. If the template switch fails, the promise will be rejected with an error.
|
|
137
|
-
*/
|
|
138
|
-
switchCapturingTemplate(templateName: string): Promise<void> {
|
|
139
|
-
return CvrModule.switchCapturingTemplate(templateName)
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Sets up an image source to provide images for continuous processing.
|
|
143
|
-
* <p>Code Snippet:</p>
|
|
144
|
-
*
|
|
145
|
-
*```
|
|
146
|
-
* let router = await CaptureVisionRouter.getInstance();
|
|
147
|
-
* let cameraEnhancer = CameraEnhancer.getInstance();
|
|
148
|
-
* router.setInput(cameraEnhancer);
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* @param input - The image source which is compliant with the {@link ImageSourceAdapter} interface.
|
|
152
|
-
* @see {@link ImageSourceAdapter}
|
|
153
|
-
* @see {@link CameraEnhancer}
|
|
154
|
-
* */
|
|
155
|
-
setInput(input: ImageSourceAdapter) {
|
|
156
|
-
CvrModule.setInput(input._getIsaId())
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private receiverMap = new Map<string, CapturedResultReceiver>();
|
|
160
|
-
private onCapturedResultReceived?: EmitterSubscription;
|
|
161
|
-
private onProcessedDocumentResultReceived?: EmitterSubscription;
|
|
162
|
-
private onDecodedBarcodesReceived?: EmitterSubscription;
|
|
163
|
-
private onRecognizedTextLinesReceived?: EmitterSubscription;
|
|
164
|
-
private onParsedResultsReceived?: EmitterSubscription;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Adds a CapturedResultReceiver object as the receiver of captured results.
|
|
168
|
-
* It will return the receiver added itself, convenient to use {@link removeResultReceiver} method.
|
|
169
|
-
*
|
|
170
|
-
* <p>Code Snippet:</p>
|
|
171
|
-
*
|
|
172
|
-
* ```
|
|
173
|
-
* let router = await CaptureVisionRouter.getInstance();
|
|
174
|
-
* let receiver = router.addResultReceiver({
|
|
175
|
-
* onCapturedResultReceived: result => {
|
|
176
|
-
* // Do something with the result
|
|
177
|
-
* },
|
|
178
|
-
* });
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* @param receiver - The receiver object, of type {@link CapturedResultReceiver}.
|
|
182
|
-
* @return return the receiver added in CapturedResultReceiver.
|
|
183
|
-
* @see CaptureVisionRouter.removeResultReceiver
|
|
184
|
-
* */
|
|
185
|
-
addResultReceiver(receiver: CapturedResultReceiver): CapturedResultReceiver {
|
|
186
|
-
let receiverEx = receiver as CapturedResultReceiver & { receiverId?: string };
|
|
187
|
-
receiverEx.receiverId = receiverEx.receiverId || Math.random().toString(36).slice(-6);
|
|
188
|
-
this.receiverMap.set(receiverEx.receiverId, receiverEx);
|
|
189
|
-
if (!this.onCapturedResultReceived && receiver.onCapturedResultReceived) {
|
|
190
|
-
if (Platform.OS == 'ios') {
|
|
191
|
-
CvrModule.addResultReceiver('onCapturedResultReceived')
|
|
192
|
-
}
|
|
193
|
-
this.onCapturedResultReceived = CVREventEmitter.addListener('onCapturedResultReceived',
|
|
194
|
-
async (result: CapturedResult) => {
|
|
195
|
-
_populateResults(result)
|
|
196
|
-
let processingDocumentResult = result.processingDocumentResult;
|
|
197
|
-
if (processingDocumentResult && processingDocumentResult.deskewedImageResultItems && processingDocumentResult.deskewedImageResultItems.length > 0) {
|
|
198
|
-
installMethods();
|
|
199
|
-
let imageArr: ImageData[] | undefined | null = global.getCurrentDeskewedImages();
|
|
200
|
-
if (imageArr) {
|
|
201
|
-
for (let i = 0; i < processingDocumentResult.deskewedImageResultItems.length; i++) {
|
|
202
|
-
processingDocumentResult.deskewedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (processingDocumentResult && processingDocumentResult.enhancedImageResultItems && processingDocumentResult.enhancedImageResultItems.length > 0) {
|
|
207
|
-
installMethods();
|
|
208
|
-
let imageArr: ImageData[] | undefined | null = global.getCurrentEnhancedImages();
|
|
209
|
-
if (imageArr) {
|
|
210
|
-
for (let i = 0; i < processingDocumentResult.enhancedImageResultItems.length; i++) {
|
|
211
|
-
processingDocumentResult.enhancedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
for (let _receiver of this.receiverMap.values()) {
|
|
216
|
-
await _receiver.onCapturedResultReceived?.(result);
|
|
217
|
-
}
|
|
218
|
-
CvrModule.continueCRR()
|
|
219
|
-
}
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (!this.onDecodedBarcodesReceived && receiver.onDecodedBarcodesReceived) {
|
|
224
|
-
if (Platform.OS == 'ios') {
|
|
225
|
-
CvrModule.addResultReceiver('onDecodedBarcodesReceived')
|
|
226
|
-
}
|
|
227
|
-
this.onDecodedBarcodesReceived = CVREventEmitter.addListener('onDecodedBarcodesReceived',
|
|
228
|
-
async (result: DecodedBarcodesResult) => {
|
|
229
|
-
result.items?.forEach((item: BarcodeResultItem, _) => {
|
|
230
|
-
item.format = BigInt(item._formatNumberString!!)
|
|
231
|
-
});
|
|
232
|
-
for (let _receiver of this.receiverMap.values()) {
|
|
233
|
-
await _receiver.onDecodedBarcodesReceived?.(result);
|
|
234
|
-
}
|
|
235
|
-
CvrModule.continueCRR()
|
|
236
|
-
}
|
|
237
|
-
)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (!this.onRecognizedTextLinesReceived && receiver.onRecognizedTextLinesReceived) {
|
|
241
|
-
if (Platform.OS == 'ios') {
|
|
242
|
-
CvrModule.addResultReceiver('onRecognizedTextLinesReceived')
|
|
243
|
-
}
|
|
244
|
-
this.onRecognizedTextLinesReceived = CVREventEmitter.addListener('onRecognizedTextLinesReceived',
|
|
245
|
-
async (result: RecognizedTextLinesResult) => {
|
|
246
|
-
for (let _receiver of this.receiverMap.values()) {
|
|
247
|
-
await _receiver.onRecognizedTextLinesReceived?.(result);
|
|
248
|
-
}
|
|
249
|
-
CvrModule.continueCRR()
|
|
250
|
-
}
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (!this.onProcessedDocumentResultReceived && receiver.onProcessedDocumentResultReceived) {
|
|
255
|
-
if (Platform.OS == 'ios') {
|
|
256
|
-
CvrModule.addResultReceiver('onProcessedDocumentResultReceived')
|
|
257
|
-
}
|
|
258
|
-
this.onProcessedDocumentResultReceived = CVREventEmitter.addListener('onProcessedDocumentResultReceived',
|
|
259
|
-
async (result: ProcessedDocumentResult) => {
|
|
260
|
-
if (result && result.deskewedImageResultItems && result.deskewedImageResultItems.length > 0) {
|
|
261
|
-
installMethods();
|
|
262
|
-
let imageArr: ImageData[] = global.getCurrentDeskewedImages();
|
|
263
|
-
for (let i = 0; i < result.deskewedImageResultItems.length; i++) {
|
|
264
|
-
result.deskewedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (result && result.enhancedImageResultItems && result.enhancedImageResultItems.length > 0) {
|
|
268
|
-
installMethods();
|
|
269
|
-
let imageArr: ImageData[] = global.getCurrentEnhancedImages();
|
|
270
|
-
for (let i = 0; i < result.enhancedImageResultItems.length; i++) {
|
|
271
|
-
result.enhancedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
for (let _receiver of this.receiverMap.values()) {
|
|
275
|
-
await _receiver.onProcessedDocumentResultReceived?.(result);
|
|
276
|
-
}
|
|
277
|
-
CvrModule.continueCRR()
|
|
278
|
-
}
|
|
279
|
-
)
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (!this.onParsedResultsReceived && receiver.onParsedResultsReceived) {
|
|
283
|
-
if (Platform.OS == 'ios') {
|
|
284
|
-
CvrModule.addResultReceiver('onParsedResultsReceived')
|
|
285
|
-
}
|
|
286
|
-
this.onParsedResultsReceived = CVREventEmitter.addListener('onParsedResultsReceived',
|
|
287
|
-
async (result: ParsedResult) => {
|
|
288
|
-
for (let _receiver of this.receiverMap.values()) {
|
|
289
|
-
await _receiver.onParsedResultsReceived?.(result);
|
|
290
|
-
}
|
|
291
|
-
CvrModule.continueCRR()
|
|
292
|
-
}
|
|
293
|
-
)
|
|
294
|
-
}
|
|
295
|
-
return receiver
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Removes the specified CapturedResultReceiver object.
|
|
300
|
-
* <p>Code Snippet:</p>
|
|
301
|
-
*
|
|
302
|
-
*```
|
|
303
|
-
* let router = await CaptureVisionRouter.getInstance();
|
|
304
|
-
* let receiver = router.addResultReceiver({
|
|
305
|
-
* onCapturedResultReceived: result => {
|
|
306
|
-
* // Do something with the result
|
|
307
|
-
* },
|
|
308
|
-
* });
|
|
309
|
-
* //...
|
|
310
|
-
* router.removeResultReceiver(receiver);
|
|
311
|
-
* ```
|
|
312
|
-
* @param receiver - The receiver object, of type CapturedResultReceiver.
|
|
313
|
-
* */
|
|
314
|
-
removeResultReceiver(receiver: CapturedResultReceiver): void {
|
|
315
|
-
let receiverEx = receiver as CapturedResultReceiver & { receiverId?: string };
|
|
316
|
-
if (receiverEx.receiverId) this.receiverMap.delete(receiverEx.receiverId);
|
|
317
|
-
|
|
318
|
-
let needToKeepTypes = 0;
|
|
319
|
-
let needToKeep_onCapturedResultReceived = false;
|
|
320
|
-
for (let _receiver of this.receiverMap.values()) {
|
|
321
|
-
if (_receiver.onCapturedResultReceived) needToKeep_onCapturedResultReceived = true;
|
|
322
|
-
needToKeepTypes |= _receiver.onDecodedBarcodesReceived ? EnumCapturedResultItemType.CRIT_BARCODE : 0;
|
|
323
|
-
needToKeepTypes |= _receiver.onRecognizedTextLinesReceived ? EnumCapturedResultItemType.CRIT_TEXT_LINE : 0;
|
|
324
|
-
needToKeepTypes |= _receiver.onProcessedDocumentResultReceived ? (EnumCapturedResultItemType.CRIT_DETECTED_QUAD | EnumCapturedResultItemType.CRIT_DESKEWED_IMAGE | EnumCapturedResultItemType.CRIT_ENHANCED_IMAGE) : 0;
|
|
325
|
-
needToKeepTypes |= _receiver.onParsedResultsReceived ? EnumCapturedResultItemType.CRIT_PARSED_RESULT : 0;
|
|
326
|
-
}
|
|
327
|
-
if (!needToKeep_onCapturedResultReceived) {
|
|
328
|
-
this.onCapturedResultReceived = this.onCapturedResultReceived?.remove() || undefined
|
|
329
|
-
CvrModule.removeResultReceiver('onCapturedResultReceived')
|
|
330
|
-
CVREventEmitter.removeAllListeners('onCapturedResultReceived')
|
|
331
|
-
}
|
|
332
|
-
if ((needToKeepTypes & EnumCapturedResultItemType.CRIT_BARCODE) == 0) {
|
|
333
|
-
this.onDecodedBarcodesReceived = this.onDecodedBarcodesReceived?.remove() || undefined
|
|
334
|
-
CvrModule.removeResultReceiver('onDecodedBarcodesReceived')
|
|
335
|
-
CVREventEmitter.removeAllListeners('onDecodedBarcodesReceived')
|
|
336
|
-
}
|
|
337
|
-
if ((needToKeepTypes & EnumCapturedResultItemType.CRIT_TEXT_LINE) == 0) {
|
|
338
|
-
this.onRecognizedTextLinesReceived = this.onRecognizedTextLinesReceived?.remove() || undefined
|
|
339
|
-
CvrModule.removeResultReceiver('onRecognizedTextLinesReceived')
|
|
340
|
-
CVREventEmitter.removeAllListeners('onRecognizedTextLinesReceived')
|
|
341
|
-
}
|
|
342
|
-
if ((needToKeepTypes & (EnumCapturedResultItemType.CRIT_DETECTED_QUAD | EnumCapturedResultItemType.CRIT_DESKEWED_IMAGE | EnumCapturedResultItemType.CRIT_ENHANCED_IMAGE)) == 0) {
|
|
343
|
-
this.onProcessedDocumentResultReceived = this.onProcessedDocumentResultReceived?.remove() || undefined
|
|
344
|
-
CvrModule.removeResultReceiver('onProcessedDocumentResultReceived')
|
|
345
|
-
CVREventEmitter.removeAllListeners('onProcessedDocumentResultReceived')
|
|
346
|
-
}
|
|
347
|
-
if ((needToKeepTypes & EnumCapturedResultItemType.CRIT_PARSED_RESULT) == 0) {
|
|
348
|
-
this.onParsedResultsReceived = this.onParsedResultsReceived?.remove() || undefined
|
|
349
|
-
CvrModule.removeResultReceiver('onParsedResultsReceived')
|
|
350
|
-
CVREventEmitter.removeAllListeners('onParsedResultsReceived')
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Removes all CapturedResultReceiver object added in.
|
|
356
|
-
* */
|
|
357
|
-
removeAllResultListeners(): void {
|
|
358
|
-
CvrModule.removeAllResultListeners()
|
|
359
|
-
this.receiverMap.clear()
|
|
360
|
-
this.onCapturedResultReceived?.remove()
|
|
361
|
-
this.onDecodedBarcodesReceived?.remove()
|
|
362
|
-
this.onProcessedDocumentResultReceived?.remove()
|
|
363
|
-
this.onRecognizedTextLinesReceived?.remove()
|
|
364
|
-
this.onParsedResultsReceived?.remove()
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Adds a CapturedResultFilter object to filter non-essential results.
|
|
369
|
-
* It will return the CapturedResultFilter added itself, convenient to use {@link removeFilter} method.
|
|
370
|
-
*
|
|
371
|
-
* Code snippet:
|
|
372
|
-
* ```
|
|
373
|
-
* let router = await CaptureVisionRouter.getInstance();
|
|
374
|
-
* let filter = router.addFilter(new MultiFrameResultCrossFilter());
|
|
375
|
-
* //...
|
|
376
|
-
* router.removeFilter(filter);
|
|
377
|
-
* ```
|
|
378
|
-
*
|
|
379
|
-
* @param filter - The result filter object, of type {@link CapturedResultFilter}.
|
|
380
|
-
* @return return the result filter added in CapturedResultReceiver.
|
|
381
|
-
* @see CaptureVisionRouter.removeFilter
|
|
382
|
-
* @remarks Can only add {@link MultiFrameResultCrossFilter} object for now.
|
|
383
|
-
* */
|
|
384
|
-
addFilter(filter: CapturedResultFilter): CapturedResultFilter {
|
|
385
|
-
CvrModule.addFilter(filter._getFilterId())
|
|
386
|
-
return filter
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Removes the specified MultiFrameResultCrossFilter object.
|
|
391
|
-
*
|
|
392
|
-
* * @param filter - The specified result filter object removed, of type {@link CapturedResultFilter}.
|
|
393
|
-
* */
|
|
394
|
-
removeFilter(filter: CapturedResultFilter) {
|
|
395
|
-
CvrModule.removeFilter(filter._getFilterId())
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Restores all runtime settings to their original default values.
|
|
400
|
-
* @return {Promise<void>} - A promise that resolves when the operation has completed.
|
|
401
|
-
* @throws Error - If resetSettings fails, the promise will be rejected with an error. The error may occur when
|
|
402
|
-
* - Function call is rejected when capturing in progress.
|
|
403
|
-
* */
|
|
404
|
-
resetSettings(): Promise<void> {
|
|
405
|
-
return CvrModule.resetSettings()
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Get a simplified settings object for the specified template name.
|
|
410
|
-
* @param templateName Specify a template with a templateName for the data capturing. If not specified, the preset template named 'Default' will be used.
|
|
411
|
-
* @return {Promise<SimplifiedCaptureVisionSettings>} - A promise that resolves an object of SimplifiedCaptureVisionSettings.
|
|
412
|
-
* @throws Error - If getSimplifiedSettings fails, the promise will be rejected with an error. The error may occur when
|
|
413
|
-
* - The target template name is invalid.
|
|
414
|
-
* - The template you specified is a complex template which can not be output as a SimplifiedCaptureVisionSettings object.
|
|
415
|
-
* - Function call is rejected when capturing in progress.
|
|
416
|
-
* */
|
|
417
|
-
async getSimplifiedSettings(templateName: string | undefined | null = ""): Promise<SimplifiedCaptureVisionSettings> {
|
|
418
|
-
try {
|
|
419
|
-
let settings: SimplifiedCaptureVisionSettings = await CvrModule.getSimplifiedSettings(templateName)
|
|
420
|
-
if (settings.barcodeSettings) {
|
|
421
|
-
settings.barcodeSettings.barcodeFormatIds = BigInt(settings.barcodeSettings?._barcodeFormatIdsNumberString!!);
|
|
422
|
-
}
|
|
423
|
-
return settings
|
|
424
|
-
} catch (e) {
|
|
425
|
-
throw e
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Updates the specified templateName with an updated SimplifiedCaptureVisionSettings object.
|
|
431
|
-
* Defined properties will be updated, and undefined properties will retain their original values.
|
|
432
|
-
*
|
|
433
|
-
* Code Snippet:
|
|
434
|
-
* ```
|
|
435
|
-
* let router = CaptureVisionRouter.getInstance();
|
|
436
|
-
* let settings = {
|
|
437
|
-
* timeout: 1000,
|
|
438
|
-
* maxParallelTasks: 1,
|
|
439
|
-
* barcodeSettings: {
|
|
440
|
-
* expectedBarcodesCount: 999,
|
|
441
|
-
* barcodeFormatIds: EnumBarcodeFormat.BF_ONED | EnumBarcodeFormat.BF_QR_CODE,
|
|
442
|
-
* }
|
|
443
|
-
* };
|
|
444
|
-
* //Only timeout, maxParallelTasks, expectedBarcodesCount and barcodeFormatIds will be updated.
|
|
445
|
-
* router.updateSettings("ReadSingleBarcode", settings);
|
|
446
|
-
*
|
|
447
|
-
* ```
|
|
448
|
-
*
|
|
449
|
-
* @param templateName Specify the name of the template that you want to update. If undefined, the preset template named 'Default' will be used.
|
|
450
|
-
* @param settings An object of SimplifiedCaptureVisionSettings. If undefined, will not change settings.
|
|
451
|
-
* @return {Promise<void>} - A promise that resolves when the operation has completed.
|
|
452
|
-
* @throws Error - If updateSettings fails, the promise will be rejected with an error. The error may occur when
|
|
453
|
-
* - The target template name is invalid.
|
|
454
|
-
* - There exists invalid parameter value in your SimplifiedCaptureVisionSettings.
|
|
455
|
-
* - The template you specified is a complex template which can not be output as a SimplifiedCaptureVisionSettings object.
|
|
456
|
-
* - Function call is rejected when capturing in progress.
|
|
457
|
-
*
|
|
458
|
-
* @see {@link SimplifiedCaptureVisionSettings}
|
|
459
|
-
* */
|
|
460
|
-
async updateSettings(settings?: SimplifiedCaptureVisionSettings | null, templateName: string | undefined | null = ""): Promise<void> {
|
|
461
|
-
let barcodeFormatIds = settings?.barcodeSettings?.barcodeFormatIds
|
|
462
|
-
try {
|
|
463
|
-
if (barcodeFormatIds != undefined) {
|
|
464
|
-
settings!!.barcodeSettings!!.barcodeFormatIds = undefined
|
|
465
|
-
let settingsTemp: SimplifiedCaptureVisionSettings = JSON.parse(JSON.stringify(settings)) as SimplifiedCaptureVisionSettings;
|
|
466
|
-
settingsTemp!!.barcodeSettings!!._barcodeFormatIdsNumberString = barcodeFormatIds.toString()
|
|
467
|
-
settings!!.barcodeSettings!!.barcodeFormatIds = barcodeFormatIds
|
|
468
|
-
await CvrModule.updateSettings(settingsTemp, templateName)
|
|
469
|
-
} else {
|
|
470
|
-
await CvrModule.updateSettings(settings, templateName)
|
|
471
|
-
}
|
|
472
|
-
} catch (e) {
|
|
473
|
-
throw e
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Configures runtime settings using a provided JSON string, which contains settings for one or more CaptureVisionTemplates.
|
|
479
|
-
*
|
|
480
|
-
* @param content - A JSON string that contains Capture Vision settings.
|
|
481
|
-
* @return {Promise<void>} - A promise that resolves or rejected with an error when the operation has completed.
|
|
482
|
-
* */
|
|
483
|
-
initSettings(content: string): Promise<void> {
|
|
484
|
-
return CvrModule.initSettings(content)
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Configures runtime settings using a provided JSON file, which contains settings for one or more CaptureVisionTemplates.
|
|
489
|
-
*
|
|
490
|
-
* @param file - Absolute path of a JSON file that contains Capture Vision settings.
|
|
491
|
-
* @return {Promise<void>} - A promise that resolves or rejected with an error when the operation has completed.
|
|
492
|
-
* */
|
|
493
|
-
initSettingsFromFile(file: string): Promise<void> {
|
|
494
|
-
return CvrModule.initSettingsFromFile(file)
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* Get a JSON string that contains settings for the specified templateName.
|
|
499
|
-
*
|
|
500
|
-
* @param templateName - The name of the template that you want to output.
|
|
501
|
-
* @param includeDefaultValues - Whether to include default values in the output.
|
|
502
|
-
* @return {Promise<string>} - A promise that resolves a JSON string that contains settings for the specified templateName.
|
|
503
|
-
* */
|
|
504
|
-
outputSettings(templateName: string, includeDefaultValues: boolean): Promise<string> {
|
|
505
|
-
return CvrModule.outputSettings(templateName, includeDefaultValues)
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Generates a JSON file download containing the settings for the specified templateName and saved to specified file path.
|
|
510
|
-
* @param templateName - The name of the template that you want to output.
|
|
511
|
-
* @param file - The absolute file path that you want to save the template.
|
|
512
|
-
* @param includeDefaultValues - Whether to include default values in the output.
|
|
513
|
-
* @return {Promise<void>} - A promise that resolves or rejected with an error when the operation has completed.
|
|
514
|
-
* */
|
|
515
|
-
outputSettingsToFile(templateName: string, file: string, includeDefaultValues: boolean): Promise<void> {
|
|
516
|
-
return CvrModule.outputSettingsToFile(templateName, file, includeDefaultValues)
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Processes {@link ImageData} object to derive important information.
|
|
521
|
-
* <p>Code Snippet:</p>
|
|
522
|
-
*
|
|
523
|
-
*```
|
|
524
|
-
* let cameraEnhancer = CameraEnhancer.getInstance();
|
|
525
|
-
* let router = CaptureVisionRouter.getInstance();
|
|
526
|
-
* let imageData = cameraEnhancer.getImage();
|
|
527
|
-
* let result = router.capture(imageData, "ReadSingleBarcode");
|
|
528
|
-
* for(let i = 0; i < result.items.length; i++) {
|
|
529
|
-
* //...
|
|
530
|
-
* }
|
|
531
|
-
* ```
|
|
532
|
-
*
|
|
533
|
-
* @param imageData - An {@link ImageData} object that contains image info.
|
|
534
|
-
* @param template - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
535
|
-
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
536
|
-
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
537
|
-
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
538
|
-
*
|
|
539
|
-
* @return A {@link CapturedResult} object which contains the derived information from the image processed.
|
|
540
|
-
* If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.
|
|
541
|
-
*
|
|
542
|
-
* @see {@link EnumPresetTemplate}
|
|
543
|
-
* @see {@link CapturedResult}
|
|
544
|
-
* */
|
|
545
|
-
capture(imageData: ImageData, template: string = ""): CapturedResult | undefined | null {
|
|
546
|
-
installMethods();
|
|
547
|
-
if (imageData) {
|
|
548
|
-
if (typeof global.captureImageData !== 'function') {
|
|
549
|
-
return null;
|
|
550
|
-
}
|
|
551
|
-
let result = global.captureImageData(imageData, template);
|
|
552
|
-
_populateResults(result)
|
|
553
|
-
return result;
|
|
554
|
-
} else {
|
|
555
|
-
return null;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Processes a file containing a single image to derive important information.
|
|
561
|
-
* <p>Code Snippet:</p>
|
|
562
|
-
*
|
|
563
|
-
*```
|
|
564
|
-
* let router = CaptureVisionRouter.getInstance();
|
|
565
|
-
* let result = router.capture("absolute-image-file-path", "ReadSingleBarcode");
|
|
566
|
-
* for(let i = 0; i < result.items.length; i++) {
|
|
567
|
-
* //...
|
|
568
|
-
* }
|
|
569
|
-
* ```
|
|
570
|
-
*
|
|
571
|
-
* @param filePath - The absolute file path and name that you want to capture data from.
|
|
572
|
-
* You have to specify the file name with extension name in the filePath.
|
|
573
|
-
* Supported file type includes “.bmp”, “.jpg”, “.png”, “.gif” or one-page “.tiff”.
|
|
574
|
-
* @param template - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
575
|
-
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
576
|
-
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
577
|
-
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
578
|
-
*
|
|
579
|
-
* @return A {@link CapturedResult} object which contains the derived information from the image processed.
|
|
580
|
-
* If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.
|
|
581
|
-
*
|
|
582
|
-
* @see {@link EnumPresetTemplate}
|
|
583
|
-
* @see {@link CapturedResult}
|
|
584
|
-
* */
|
|
585
|
-
captureFile(filePath: string, template: string = ""): CapturedResult | undefined | null {
|
|
586
|
-
installMethods();
|
|
587
|
-
if (filePath) {
|
|
588
|
-
if (typeof global.captureFile !== 'function') {
|
|
589
|
-
return null;
|
|
590
|
-
}
|
|
591
|
-
let result = global.captureFile(filePath, template);
|
|
592
|
-
_populateResults(result)
|
|
593
|
-
return result;
|
|
594
|
-
} else {
|
|
595
|
-
return null;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Processes An ArrayBuffer object that points to a file in memory to derive important information.
|
|
601
|
-
*
|
|
602
|
-
* @param fileBytes - An ArrayBuffer object that points to a file in memory.
|
|
603
|
-
* @param template - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
604
|
-
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
605
|
-
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
606
|
-
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
607
|
-
*
|
|
608
|
-
* @return A {@link CapturedResult} object which contains the derived information from the image processed.
|
|
609
|
-
* If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.
|
|
610
|
-
*
|
|
611
|
-
* @see {@link EnumPresetTemplate}
|
|
612
|
-
* @see {@link CapturedResult}
|
|
613
|
-
* */
|
|
614
|
-
captureFileBytes(fileBytes: ArrayBuffer, template: string = ""): CapturedResult | undefined | null {
|
|
615
|
-
installMethods();
|
|
616
|
-
if (fileBytes) {
|
|
617
|
-
if (typeof global.captureFileBytes !== 'function') {
|
|
618
|
-
return null;
|
|
619
|
-
}
|
|
620
|
-
let result = global.captureFileBytes(fileBytes, template);
|
|
621
|
-
_populateResults(result)
|
|
622
|
-
return result;
|
|
623
|
-
} else {
|
|
624
|
-
return null;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
private intermediateResultManager: IntermediateResultManager | undefined = undefined;
|
|
629
|
-
|
|
630
|
-
/**@see {@link IntermediateResultManager}*/
|
|
631
|
-
getIntermediateResultManager(): IntermediateResultManager {
|
|
632
|
-
if (!this.intermediateResultManager) {
|
|
633
|
-
this.intermediateResultManager = new IntermediateResultManager();
|
|
634
|
-
}
|
|
635
|
-
return this.intermediateResultManager!!;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
* The IntermediateResultManager class is responsible for handling intermediate results obtained during the process of an image.
|
|
641
|
-
* @see {@link CaptureVisionRouter.getIntermediateResultManager}
|
|
642
|
-
* @hideconstructor
|
|
643
|
-
* */
|
|
644
|
-
export class IntermediateResultManager {
|
|
645
|
-
/**
|
|
646
|
-
* Retrieves the original image data.
|
|
647
|
-
* <p>Code Snippet:</p>
|
|
648
|
-
*
|
|
649
|
-
*```
|
|
650
|
-
* let router = CaptureVisionRouter.getInstance();
|
|
651
|
-
* let intermediateResultManager = router.getIntermediateResultManager()
|
|
652
|
-
* router.addResultReceiver({
|
|
653
|
-
* onCaptureResultReceive: result => {
|
|
654
|
-
* let imageData = intermediateResultManager.getOriginalImage(result.originalImageHashId)
|
|
655
|
-
* //...
|
|
656
|
-
* }
|
|
657
|
-
* });
|
|
658
|
-
* ```
|
|
659
|
-
*
|
|
660
|
-
* @param imageHashId - The image hash ID. Get from {@link CapturedResult.originalImageHashId}, {@link DecodedBarcodesResult.originalImageHashId},
|
|
661
|
-
* {@link ProcessedDocumentResult.originalImageHashId}, {@link RecognizedTextLinesResult.originalImageHashId}.
|
|
662
|
-
*
|
|
663
|
-
* @remarks `Do not call this method after calling stopCapturing() or outside the CapturedResultReceiver callback where you get the hashId, otherwise you will not get any valid ImageData.`
|
|
664
|
-
* @see {@link CaptureVisionRouter.addResultReceiver}
|
|
665
|
-
* @see {@link CapturedResultReceiver}
|
|
666
|
-
* */
|
|
667
|
-
getOriginalImage(imageHashId: string): ImageData | undefined | null {
|
|
668
|
-
installMethods();
|
|
669
|
-
if (typeof global.cvr_getOriginalImage !== 'function') {
|
|
670
|
-
return null;
|
|
671
|
-
}
|
|
672
|
-
return global.cvr_getOriginalImage(imageHashId);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
declare var global: {
|
|
677
|
-
captureImageData: (imageData: ImageData, template: string) => CapturedResult | undefined | null;
|
|
678
|
-
captureFile: (file: string, template: string) => CapturedResult | undefined | null;
|
|
679
|
-
captureFileBytes: (fileBytes: ArrayBuffer, template: string) => CapturedResult | undefined | null;
|
|
680
|
-
getCurrentDeskewedImages: () => ImageData[] | undefined | null;
|
|
681
|
-
getCurrentEnhancedImages: () => ImageData[] | undefined | null;
|
|
682
|
-
cvr_getOriginalImage: (imageHashId: string) => ImageData | undefined | null;
|
|
683
|
-
}
|
|
1
|
+
import {type EmitterSubscription, NativeEventEmitter, NativeModules, Platform} from "react-native";
|
|
2
|
+
import {EnumCapturedResultItemType, type ImageData, ImageSourceAdapter} from "../core";
|
|
3
|
+
import type {CapturedResultReceiver} from "./CapturedResultReceiver";
|
|
4
|
+
import {type CapturedResult, _populateResults} from "./CapturedResult";
|
|
5
|
+
import type {BarcodeResultItem, DecodedBarcodesResult} from "../dbr";
|
|
6
|
+
import type {ProcessedDocumentResult} from "../ddn";
|
|
7
|
+
import type {RecognizedTextLinesResult} from "../dlr";
|
|
8
|
+
import type {ParsedResult} from "../dcp";
|
|
9
|
+
import type {CapturedResultFilter} from "./CapturedResultFilter";
|
|
10
|
+
import type {SimplifiedCaptureVisionSettings} from "./SimplifiedCaptureVisionSettings";
|
|
11
|
+
import {MultiFrameResultCrossFilter} from "../utility";
|
|
12
|
+
import {CameraEnhancer} from "../dce";
|
|
13
|
+
|
|
14
|
+
// @ts-ignore Check whether __turboModuleProxy exists, it may not
|
|
15
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
16
|
+
|
|
17
|
+
const CvrModule = !isTurboModuleEnabled ?
|
|
18
|
+
NativeModules.DynamsoftCaptureVisionRouterModule :
|
|
19
|
+
require("./NativeDynamsoftCaptureVisionRouterModule").default;
|
|
20
|
+
|
|
21
|
+
const CVREventEmitter = new NativeEventEmitter(CvrModule);
|
|
22
|
+
let isInstalled = false
|
|
23
|
+
const installMethods = () => {
|
|
24
|
+
if (!isInstalled) {
|
|
25
|
+
CvrModule.install()
|
|
26
|
+
isInstalled = true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The singleton instance of CaptureVisionRouter.
|
|
32
|
+
* */
|
|
33
|
+
let cvr: CaptureVisionRouter | null = null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The CaptureVisionRouter class defines how a user interacts with image-processing and semantic-processing products in their applications.
|
|
37
|
+
* A CaptureVisionRouter instance accepts and processes images from an image source and returns processing results which may contain Final results or Intermediate Results.
|
|
38
|
+
* <p>
|
|
39
|
+
* In js end of react-native, CaptureVisionRouter uses singleton mode. You can only get CaptureVisionRouter instance by {@link CaptureVisionRouter.getInstance}.
|
|
40
|
+
* */
|
|
41
|
+
export class CaptureVisionRouter {
|
|
42
|
+
private constructor() {
|
|
43
|
+
CvrModule.createInstance();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the singleton instance of CaptureVisionRouter.
|
|
48
|
+
* <p>
|
|
49
|
+
* This method ensures that only one instance of CaptureVisionRouter is created
|
|
50
|
+
* and reused throughout the application. If an instance already exists, it will
|
|
51
|
+
* return the existing one. Otherwise, it will create a new instance and return it.
|
|
52
|
+
*
|
|
53
|
+
* @returns {CaptureVisionRouter} The singleton instance of CaptureVisionRouter.
|
|
54
|
+
* */
|
|
55
|
+
static getInstance(): CaptureVisionRouter {
|
|
56
|
+
if (cvr) {
|
|
57
|
+
return cvr;
|
|
58
|
+
}
|
|
59
|
+
return cvr = new CaptureVisionRouter();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Destroys the CaptureVisionRouter instance and releases all associated resources.
|
|
64
|
+
* After calling this method, the instance will be set to null and cannot be used anymore.
|
|
65
|
+
* Only call this method when you want to completely dispose the CaptureVisionRouter instance, otherwise just call {@link CaptureVisionRouter.stopCapturing} to stop the capturing process.
|
|
66
|
+
*/
|
|
67
|
+
dispose() {
|
|
68
|
+
CvrModule.destroyInstance();
|
|
69
|
+
cvr = null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Sets the global number of threads used internally for model execution.
|
|
74
|
+
*
|
|
75
|
+
* @param intraOpNumThreads - Number of threads used internally for model execution. Valid range: [0, 256].
|
|
76
|
+
* If the value is outside the range [0, 256], it will be treated as 0 (default).
|
|
77
|
+
*/
|
|
78
|
+
static setGlobalIntraOpNumThreads(intraOpNumThreads: number) {
|
|
79
|
+
CvrModule.setGlobalIntraOpNumThreads(intraOpNumThreads);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Clears all deep learning models from buffer to free up memory.
|
|
84
|
+
*/
|
|
85
|
+
static clearDLModelBuffers() {
|
|
86
|
+
CvrModule.clearDLModelBuffers();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Initiates a capturing process based on a specified template. This process is repeated for each image fetched from the source.
|
|
91
|
+
* <p>Code Snippet:</p>
|
|
92
|
+
*
|
|
93
|
+
*```
|
|
94
|
+
* let router = CaptureVisionRouter.getInstance();
|
|
95
|
+
* await router.startCapturing('ReadSingleBarcode');
|
|
96
|
+
* ```
|
|
97
|
+
* @param templateName - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
98
|
+
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
99
|
+
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
100
|
+
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
101
|
+
*
|
|
102
|
+
* @return Promise<void> - A promise that resolves when the capturing process has successfully started. It does not provide any value upon resolution.
|
|
103
|
+
* @throws Error - If the capturing process fails to start, the promise will be rejected with an error.
|
|
104
|
+
* The error may occur due to invalid template names, or a capturing process is already in progress, etc.
|
|
105
|
+
*
|
|
106
|
+
* @remarks - Always make sure there is no capturing in process or just call `await CaptureVisionRouter.stopCapturing()` to stop any ongoing capturing process
|
|
107
|
+
* before calling `startCapturing`.
|
|
108
|
+
*
|
|
109
|
+
* @see {@link EnumPresetTemplate}
|
|
110
|
+
* */
|
|
111
|
+
startCapturing(templateName: string | undefined | null = ""): Promise<void> {
|
|
112
|
+
return CvrModule.startCapturing(templateName)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Stops the capturing process.
|
|
118
|
+
* <p>Code Snippet:</p>
|
|
119
|
+
*
|
|
120
|
+
*```
|
|
121
|
+
* let router = await CaptureVisionRouter.getInstance();
|
|
122
|
+
* await router.startCapturing("ReadSingleBarcode");
|
|
123
|
+
* // ...
|
|
124
|
+
* router.stopCapturing();
|
|
125
|
+
* ```
|
|
126
|
+
* */
|
|
127
|
+
stopCapturing(): Promise<void> {
|
|
128
|
+
return CvrModule.stopCapturing()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Switch the capturing template during the image processing workflow.
|
|
133
|
+
*
|
|
134
|
+
* @param templateName -The name of the new capturing template to apply.
|
|
135
|
+
*
|
|
136
|
+
* @return Promise<void> - A promise that resolves when the template switch is successful. If the template switch fails, the promise will be rejected with an error.
|
|
137
|
+
*/
|
|
138
|
+
switchCapturingTemplate(templateName: string): Promise<void> {
|
|
139
|
+
return CvrModule.switchCapturingTemplate(templateName)
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Sets up an image source to provide images for continuous processing.
|
|
143
|
+
* <p>Code Snippet:</p>
|
|
144
|
+
*
|
|
145
|
+
*```
|
|
146
|
+
* let router = await CaptureVisionRouter.getInstance();
|
|
147
|
+
* let cameraEnhancer = CameraEnhancer.getInstance();
|
|
148
|
+
* router.setInput(cameraEnhancer);
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @param input - The image source which is compliant with the {@link ImageSourceAdapter} interface.
|
|
152
|
+
* @see {@link ImageSourceAdapter}
|
|
153
|
+
* @see {@link CameraEnhancer}
|
|
154
|
+
* */
|
|
155
|
+
setInput(input: ImageSourceAdapter) {
|
|
156
|
+
CvrModule.setInput(input._getIsaId())
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private receiverMap = new Map<string, CapturedResultReceiver>();
|
|
160
|
+
private onCapturedResultReceived?: EmitterSubscription;
|
|
161
|
+
private onProcessedDocumentResultReceived?: EmitterSubscription;
|
|
162
|
+
private onDecodedBarcodesReceived?: EmitterSubscription;
|
|
163
|
+
private onRecognizedTextLinesReceived?: EmitterSubscription;
|
|
164
|
+
private onParsedResultsReceived?: EmitterSubscription;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Adds a CapturedResultReceiver object as the receiver of captured results.
|
|
168
|
+
* It will return the receiver added itself, convenient to use {@link removeResultReceiver} method.
|
|
169
|
+
*
|
|
170
|
+
* <p>Code Snippet:</p>
|
|
171
|
+
*
|
|
172
|
+
* ```
|
|
173
|
+
* let router = await CaptureVisionRouter.getInstance();
|
|
174
|
+
* let receiver = router.addResultReceiver({
|
|
175
|
+
* onCapturedResultReceived: result => {
|
|
176
|
+
* // Do something with the result
|
|
177
|
+
* },
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @param receiver - The receiver object, of type {@link CapturedResultReceiver}.
|
|
182
|
+
* @return return the receiver added in CapturedResultReceiver.
|
|
183
|
+
* @see CaptureVisionRouter.removeResultReceiver
|
|
184
|
+
* */
|
|
185
|
+
addResultReceiver(receiver: CapturedResultReceiver): CapturedResultReceiver {
|
|
186
|
+
let receiverEx = receiver as CapturedResultReceiver & { receiverId?: string };
|
|
187
|
+
receiverEx.receiverId = receiverEx.receiverId || Math.random().toString(36).slice(-6);
|
|
188
|
+
this.receiverMap.set(receiverEx.receiverId, receiverEx);
|
|
189
|
+
if (!this.onCapturedResultReceived && receiver.onCapturedResultReceived) {
|
|
190
|
+
if (Platform.OS == 'ios') {
|
|
191
|
+
CvrModule.addResultReceiver('onCapturedResultReceived')
|
|
192
|
+
}
|
|
193
|
+
this.onCapturedResultReceived = CVREventEmitter.addListener('onCapturedResultReceived',
|
|
194
|
+
async (result: CapturedResult) => {
|
|
195
|
+
_populateResults(result)
|
|
196
|
+
let processingDocumentResult = result.processingDocumentResult;
|
|
197
|
+
if (processingDocumentResult && processingDocumentResult.deskewedImageResultItems && processingDocumentResult.deskewedImageResultItems.length > 0) {
|
|
198
|
+
installMethods();
|
|
199
|
+
let imageArr: ImageData[] | undefined | null = global.getCurrentDeskewedImages();
|
|
200
|
+
if (imageArr) {
|
|
201
|
+
for (let i = 0; i < processingDocumentResult.deskewedImageResultItems.length; i++) {
|
|
202
|
+
processingDocumentResult.deskewedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (processingDocumentResult && processingDocumentResult.enhancedImageResultItems && processingDocumentResult.enhancedImageResultItems.length > 0) {
|
|
207
|
+
installMethods();
|
|
208
|
+
let imageArr: ImageData[] | undefined | null = global.getCurrentEnhancedImages();
|
|
209
|
+
if (imageArr) {
|
|
210
|
+
for (let i = 0; i < processingDocumentResult.enhancedImageResultItems.length; i++) {
|
|
211
|
+
processingDocumentResult.enhancedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
for (let _receiver of this.receiverMap.values()) {
|
|
216
|
+
await _receiver.onCapturedResultReceived?.(result);
|
|
217
|
+
}
|
|
218
|
+
CvrModule.continueCRR()
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!this.onDecodedBarcodesReceived && receiver.onDecodedBarcodesReceived) {
|
|
224
|
+
if (Platform.OS == 'ios') {
|
|
225
|
+
CvrModule.addResultReceiver('onDecodedBarcodesReceived')
|
|
226
|
+
}
|
|
227
|
+
this.onDecodedBarcodesReceived = CVREventEmitter.addListener('onDecodedBarcodesReceived',
|
|
228
|
+
async (result: DecodedBarcodesResult) => {
|
|
229
|
+
result.items?.forEach((item: BarcodeResultItem, _) => {
|
|
230
|
+
item.format = BigInt(item._formatNumberString!!)
|
|
231
|
+
});
|
|
232
|
+
for (let _receiver of this.receiverMap.values()) {
|
|
233
|
+
await _receiver.onDecodedBarcodesReceived?.(result);
|
|
234
|
+
}
|
|
235
|
+
CvrModule.continueCRR()
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!this.onRecognizedTextLinesReceived && receiver.onRecognizedTextLinesReceived) {
|
|
241
|
+
if (Platform.OS == 'ios') {
|
|
242
|
+
CvrModule.addResultReceiver('onRecognizedTextLinesReceived')
|
|
243
|
+
}
|
|
244
|
+
this.onRecognizedTextLinesReceived = CVREventEmitter.addListener('onRecognizedTextLinesReceived',
|
|
245
|
+
async (result: RecognizedTextLinesResult) => {
|
|
246
|
+
for (let _receiver of this.receiverMap.values()) {
|
|
247
|
+
await _receiver.onRecognizedTextLinesReceived?.(result);
|
|
248
|
+
}
|
|
249
|
+
CvrModule.continueCRR()
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (!this.onProcessedDocumentResultReceived && receiver.onProcessedDocumentResultReceived) {
|
|
255
|
+
if (Platform.OS == 'ios') {
|
|
256
|
+
CvrModule.addResultReceiver('onProcessedDocumentResultReceived')
|
|
257
|
+
}
|
|
258
|
+
this.onProcessedDocumentResultReceived = CVREventEmitter.addListener('onProcessedDocumentResultReceived',
|
|
259
|
+
async (result: ProcessedDocumentResult) => {
|
|
260
|
+
if (result && result.deskewedImageResultItems && result.deskewedImageResultItems.length > 0) {
|
|
261
|
+
installMethods();
|
|
262
|
+
let imageArr: ImageData[] = global.getCurrentDeskewedImages();
|
|
263
|
+
for (let i = 0; i < result.deskewedImageResultItems.length; i++) {
|
|
264
|
+
result.deskewedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (result && result.enhancedImageResultItems && result.enhancedImageResultItems.length > 0) {
|
|
268
|
+
installMethods();
|
|
269
|
+
let imageArr: ImageData[] = global.getCurrentEnhancedImages();
|
|
270
|
+
for (let i = 0; i < result.enhancedImageResultItems.length; i++) {
|
|
271
|
+
result.enhancedImageResultItems[i]!!.imageData = imageArr[i]!!;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (let _receiver of this.receiverMap.values()) {
|
|
275
|
+
await _receiver.onProcessedDocumentResultReceived?.(result);
|
|
276
|
+
}
|
|
277
|
+
CvrModule.continueCRR()
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!this.onParsedResultsReceived && receiver.onParsedResultsReceived) {
|
|
283
|
+
if (Platform.OS == 'ios') {
|
|
284
|
+
CvrModule.addResultReceiver('onParsedResultsReceived')
|
|
285
|
+
}
|
|
286
|
+
this.onParsedResultsReceived = CVREventEmitter.addListener('onParsedResultsReceived',
|
|
287
|
+
async (result: ParsedResult) => {
|
|
288
|
+
for (let _receiver of this.receiverMap.values()) {
|
|
289
|
+
await _receiver.onParsedResultsReceived?.(result);
|
|
290
|
+
}
|
|
291
|
+
CvrModule.continueCRR()
|
|
292
|
+
}
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
return receiver
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Removes the specified CapturedResultReceiver object.
|
|
300
|
+
* <p>Code Snippet:</p>
|
|
301
|
+
*
|
|
302
|
+
*```
|
|
303
|
+
* let router = await CaptureVisionRouter.getInstance();
|
|
304
|
+
* let receiver = router.addResultReceiver({
|
|
305
|
+
* onCapturedResultReceived: result => {
|
|
306
|
+
* // Do something with the result
|
|
307
|
+
* },
|
|
308
|
+
* });
|
|
309
|
+
* //...
|
|
310
|
+
* router.removeResultReceiver(receiver);
|
|
311
|
+
* ```
|
|
312
|
+
* @param receiver - The receiver object, of type CapturedResultReceiver.
|
|
313
|
+
* */
|
|
314
|
+
removeResultReceiver(receiver: CapturedResultReceiver): void {
|
|
315
|
+
let receiverEx = receiver as CapturedResultReceiver & { receiverId?: string };
|
|
316
|
+
if (receiverEx.receiverId) this.receiverMap.delete(receiverEx.receiverId);
|
|
317
|
+
|
|
318
|
+
let needToKeepTypes = 0;
|
|
319
|
+
let needToKeep_onCapturedResultReceived = false;
|
|
320
|
+
for (let _receiver of this.receiverMap.values()) {
|
|
321
|
+
if (_receiver.onCapturedResultReceived) needToKeep_onCapturedResultReceived = true;
|
|
322
|
+
needToKeepTypes |= _receiver.onDecodedBarcodesReceived ? EnumCapturedResultItemType.CRIT_BARCODE : 0;
|
|
323
|
+
needToKeepTypes |= _receiver.onRecognizedTextLinesReceived ? EnumCapturedResultItemType.CRIT_TEXT_LINE : 0;
|
|
324
|
+
needToKeepTypes |= _receiver.onProcessedDocumentResultReceived ? (EnumCapturedResultItemType.CRIT_DETECTED_QUAD | EnumCapturedResultItemType.CRIT_DESKEWED_IMAGE | EnumCapturedResultItemType.CRIT_ENHANCED_IMAGE) : 0;
|
|
325
|
+
needToKeepTypes |= _receiver.onParsedResultsReceived ? EnumCapturedResultItemType.CRIT_PARSED_RESULT : 0;
|
|
326
|
+
}
|
|
327
|
+
if (!needToKeep_onCapturedResultReceived) {
|
|
328
|
+
this.onCapturedResultReceived = this.onCapturedResultReceived?.remove() || undefined
|
|
329
|
+
CvrModule.removeResultReceiver('onCapturedResultReceived')
|
|
330
|
+
CVREventEmitter.removeAllListeners('onCapturedResultReceived')
|
|
331
|
+
}
|
|
332
|
+
if ((needToKeepTypes & EnumCapturedResultItemType.CRIT_BARCODE) == 0) {
|
|
333
|
+
this.onDecodedBarcodesReceived = this.onDecodedBarcodesReceived?.remove() || undefined
|
|
334
|
+
CvrModule.removeResultReceiver('onDecodedBarcodesReceived')
|
|
335
|
+
CVREventEmitter.removeAllListeners('onDecodedBarcodesReceived')
|
|
336
|
+
}
|
|
337
|
+
if ((needToKeepTypes & EnumCapturedResultItemType.CRIT_TEXT_LINE) == 0) {
|
|
338
|
+
this.onRecognizedTextLinesReceived = this.onRecognizedTextLinesReceived?.remove() || undefined
|
|
339
|
+
CvrModule.removeResultReceiver('onRecognizedTextLinesReceived')
|
|
340
|
+
CVREventEmitter.removeAllListeners('onRecognizedTextLinesReceived')
|
|
341
|
+
}
|
|
342
|
+
if ((needToKeepTypes & (EnumCapturedResultItemType.CRIT_DETECTED_QUAD | EnumCapturedResultItemType.CRIT_DESKEWED_IMAGE | EnumCapturedResultItemType.CRIT_ENHANCED_IMAGE)) == 0) {
|
|
343
|
+
this.onProcessedDocumentResultReceived = this.onProcessedDocumentResultReceived?.remove() || undefined
|
|
344
|
+
CvrModule.removeResultReceiver('onProcessedDocumentResultReceived')
|
|
345
|
+
CVREventEmitter.removeAllListeners('onProcessedDocumentResultReceived')
|
|
346
|
+
}
|
|
347
|
+
if ((needToKeepTypes & EnumCapturedResultItemType.CRIT_PARSED_RESULT) == 0) {
|
|
348
|
+
this.onParsedResultsReceived = this.onParsedResultsReceived?.remove() || undefined
|
|
349
|
+
CvrModule.removeResultReceiver('onParsedResultsReceived')
|
|
350
|
+
CVREventEmitter.removeAllListeners('onParsedResultsReceived')
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Removes all CapturedResultReceiver object added in.
|
|
356
|
+
* */
|
|
357
|
+
removeAllResultListeners(): void {
|
|
358
|
+
CvrModule.removeAllResultListeners()
|
|
359
|
+
this.receiverMap.clear()
|
|
360
|
+
this.onCapturedResultReceived?.remove()
|
|
361
|
+
this.onDecodedBarcodesReceived?.remove()
|
|
362
|
+
this.onProcessedDocumentResultReceived?.remove()
|
|
363
|
+
this.onRecognizedTextLinesReceived?.remove()
|
|
364
|
+
this.onParsedResultsReceived?.remove()
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Adds a CapturedResultFilter object to filter non-essential results.
|
|
369
|
+
* It will return the CapturedResultFilter added itself, convenient to use {@link removeFilter} method.
|
|
370
|
+
*
|
|
371
|
+
* Code snippet:
|
|
372
|
+
* ```
|
|
373
|
+
* let router = await CaptureVisionRouter.getInstance();
|
|
374
|
+
* let filter = router.addFilter(new MultiFrameResultCrossFilter());
|
|
375
|
+
* //...
|
|
376
|
+
* router.removeFilter(filter);
|
|
377
|
+
* ```
|
|
378
|
+
*
|
|
379
|
+
* @param filter - The result filter object, of type {@link CapturedResultFilter}.
|
|
380
|
+
* @return return the result filter added in CapturedResultReceiver.
|
|
381
|
+
* @see CaptureVisionRouter.removeFilter
|
|
382
|
+
* @remarks Can only add {@link MultiFrameResultCrossFilter} object for now.
|
|
383
|
+
* */
|
|
384
|
+
addFilter(filter: CapturedResultFilter): CapturedResultFilter {
|
|
385
|
+
CvrModule.addFilter(filter._getFilterId())
|
|
386
|
+
return filter
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Removes the specified MultiFrameResultCrossFilter object.
|
|
391
|
+
*
|
|
392
|
+
* * @param filter - The specified result filter object removed, of type {@link CapturedResultFilter}.
|
|
393
|
+
* */
|
|
394
|
+
removeFilter(filter: CapturedResultFilter) {
|
|
395
|
+
CvrModule.removeFilter(filter._getFilterId())
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Restores all runtime settings to their original default values.
|
|
400
|
+
* @return {Promise<void>} - A promise that resolves when the operation has completed.
|
|
401
|
+
* @throws Error - If resetSettings fails, the promise will be rejected with an error. The error may occur when
|
|
402
|
+
* - Function call is rejected when capturing in progress.
|
|
403
|
+
* */
|
|
404
|
+
resetSettings(): Promise<void> {
|
|
405
|
+
return CvrModule.resetSettings()
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Get a simplified settings object for the specified template name.
|
|
410
|
+
* @param templateName Specify a template with a templateName for the data capturing. If not specified, the preset template named 'Default' will be used.
|
|
411
|
+
* @return {Promise<SimplifiedCaptureVisionSettings>} - A promise that resolves an object of SimplifiedCaptureVisionSettings.
|
|
412
|
+
* @throws Error - If getSimplifiedSettings fails, the promise will be rejected with an error. The error may occur when
|
|
413
|
+
* - The target template name is invalid.
|
|
414
|
+
* - The template you specified is a complex template which can not be output as a SimplifiedCaptureVisionSettings object.
|
|
415
|
+
* - Function call is rejected when capturing in progress.
|
|
416
|
+
* */
|
|
417
|
+
async getSimplifiedSettings(templateName: string | undefined | null = ""): Promise<SimplifiedCaptureVisionSettings> {
|
|
418
|
+
try {
|
|
419
|
+
let settings: SimplifiedCaptureVisionSettings = await CvrModule.getSimplifiedSettings(templateName)
|
|
420
|
+
if (settings.barcodeSettings) {
|
|
421
|
+
settings.barcodeSettings.barcodeFormatIds = BigInt(settings.barcodeSettings?._barcodeFormatIdsNumberString!!);
|
|
422
|
+
}
|
|
423
|
+
return settings
|
|
424
|
+
} catch (e) {
|
|
425
|
+
throw e
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Updates the specified templateName with an updated SimplifiedCaptureVisionSettings object.
|
|
431
|
+
* Defined properties will be updated, and undefined properties will retain their original values.
|
|
432
|
+
*
|
|
433
|
+
* Code Snippet:
|
|
434
|
+
* ```
|
|
435
|
+
* let router = CaptureVisionRouter.getInstance();
|
|
436
|
+
* let settings = {
|
|
437
|
+
* timeout: 1000,
|
|
438
|
+
* maxParallelTasks: 1,
|
|
439
|
+
* barcodeSettings: {
|
|
440
|
+
* expectedBarcodesCount: 999,
|
|
441
|
+
* barcodeFormatIds: EnumBarcodeFormat.BF_ONED | EnumBarcodeFormat.BF_QR_CODE,
|
|
442
|
+
* }
|
|
443
|
+
* };
|
|
444
|
+
* //Only timeout, maxParallelTasks, expectedBarcodesCount and barcodeFormatIds will be updated.
|
|
445
|
+
* router.updateSettings("ReadSingleBarcode", settings);
|
|
446
|
+
*
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @param templateName Specify the name of the template that you want to update. If undefined, the preset template named 'Default' will be used.
|
|
450
|
+
* @param settings An object of SimplifiedCaptureVisionSettings. If undefined, will not change settings.
|
|
451
|
+
* @return {Promise<void>} - A promise that resolves when the operation has completed.
|
|
452
|
+
* @throws Error - If updateSettings fails, the promise will be rejected with an error. The error may occur when
|
|
453
|
+
* - The target template name is invalid.
|
|
454
|
+
* - There exists invalid parameter value in your SimplifiedCaptureVisionSettings.
|
|
455
|
+
* - The template you specified is a complex template which can not be output as a SimplifiedCaptureVisionSettings object.
|
|
456
|
+
* - Function call is rejected when capturing in progress.
|
|
457
|
+
*
|
|
458
|
+
* @see {@link SimplifiedCaptureVisionSettings}
|
|
459
|
+
* */
|
|
460
|
+
async updateSettings(settings?: SimplifiedCaptureVisionSettings | null, templateName: string | undefined | null = ""): Promise<void> {
|
|
461
|
+
let barcodeFormatIds = settings?.barcodeSettings?.barcodeFormatIds
|
|
462
|
+
try {
|
|
463
|
+
if (barcodeFormatIds != undefined) {
|
|
464
|
+
settings!!.barcodeSettings!!.barcodeFormatIds = undefined
|
|
465
|
+
let settingsTemp: SimplifiedCaptureVisionSettings = JSON.parse(JSON.stringify(settings)) as SimplifiedCaptureVisionSettings;
|
|
466
|
+
settingsTemp!!.barcodeSettings!!._barcodeFormatIdsNumberString = barcodeFormatIds.toString()
|
|
467
|
+
settings!!.barcodeSettings!!.barcodeFormatIds = barcodeFormatIds
|
|
468
|
+
await CvrModule.updateSettings(settingsTemp, templateName)
|
|
469
|
+
} else {
|
|
470
|
+
await CvrModule.updateSettings(settings, templateName)
|
|
471
|
+
}
|
|
472
|
+
} catch (e) {
|
|
473
|
+
throw e
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Configures runtime settings using a provided JSON string, which contains settings for one or more CaptureVisionTemplates.
|
|
479
|
+
*
|
|
480
|
+
* @param content - A JSON string that contains Capture Vision settings.
|
|
481
|
+
* @return {Promise<void>} - A promise that resolves or rejected with an error when the operation has completed.
|
|
482
|
+
* */
|
|
483
|
+
initSettings(content: string): Promise<void> {
|
|
484
|
+
return CvrModule.initSettings(content)
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Configures runtime settings using a provided JSON file, which contains settings for one or more CaptureVisionTemplates.
|
|
489
|
+
*
|
|
490
|
+
* @param file - Absolute path of a JSON file that contains Capture Vision settings.
|
|
491
|
+
* @return {Promise<void>} - A promise that resolves or rejected with an error when the operation has completed.
|
|
492
|
+
* */
|
|
493
|
+
initSettingsFromFile(file: string): Promise<void> {
|
|
494
|
+
return CvrModule.initSettingsFromFile(file)
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Get a JSON string that contains settings for the specified templateName.
|
|
499
|
+
*
|
|
500
|
+
* @param templateName - The name of the template that you want to output.
|
|
501
|
+
* @param includeDefaultValues - Whether to include default values in the output.
|
|
502
|
+
* @return {Promise<string>} - A promise that resolves a JSON string that contains settings for the specified templateName.
|
|
503
|
+
* */
|
|
504
|
+
outputSettings(templateName: string, includeDefaultValues: boolean): Promise<string> {
|
|
505
|
+
return CvrModule.outputSettings(templateName, includeDefaultValues)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Generates a JSON file download containing the settings for the specified templateName and saved to specified file path.
|
|
510
|
+
* @param templateName - The name of the template that you want to output.
|
|
511
|
+
* @param file - The absolute file path that you want to save the template.
|
|
512
|
+
* @param includeDefaultValues - Whether to include default values in the output.
|
|
513
|
+
* @return {Promise<void>} - A promise that resolves or rejected with an error when the operation has completed.
|
|
514
|
+
* */
|
|
515
|
+
outputSettingsToFile(templateName: string, file: string, includeDefaultValues: boolean): Promise<void> {
|
|
516
|
+
return CvrModule.outputSettingsToFile(templateName, file, includeDefaultValues)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Processes {@link ImageData} object to derive important information.
|
|
521
|
+
* <p>Code Snippet:</p>
|
|
522
|
+
*
|
|
523
|
+
*```
|
|
524
|
+
* let cameraEnhancer = CameraEnhancer.getInstance();
|
|
525
|
+
* let router = CaptureVisionRouter.getInstance();
|
|
526
|
+
* let imageData = cameraEnhancer.getImage();
|
|
527
|
+
* let result = router.capture(imageData, "ReadSingleBarcode");
|
|
528
|
+
* for(let i = 0; i < result.items.length; i++) {
|
|
529
|
+
* //...
|
|
530
|
+
* }
|
|
531
|
+
* ```
|
|
532
|
+
*
|
|
533
|
+
* @param imageData - An {@link ImageData} object that contains image info.
|
|
534
|
+
* @param template - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
535
|
+
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
536
|
+
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
537
|
+
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
538
|
+
*
|
|
539
|
+
* @return A {@link CapturedResult} object which contains the derived information from the image processed.
|
|
540
|
+
* If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.
|
|
541
|
+
*
|
|
542
|
+
* @see {@link EnumPresetTemplate}
|
|
543
|
+
* @see {@link CapturedResult}
|
|
544
|
+
* */
|
|
545
|
+
capture(imageData: ImageData, template: string = ""): CapturedResult | undefined | null {
|
|
546
|
+
installMethods();
|
|
547
|
+
if (imageData) {
|
|
548
|
+
if (typeof global.captureImageData !== 'function') {
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
let result = global.captureImageData(imageData, template);
|
|
552
|
+
_populateResults(result)
|
|
553
|
+
return result;
|
|
554
|
+
} else {
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Processes a file containing a single image to derive important information.
|
|
561
|
+
* <p>Code Snippet:</p>
|
|
562
|
+
*
|
|
563
|
+
*```
|
|
564
|
+
* let router = CaptureVisionRouter.getInstance();
|
|
565
|
+
* let result = router.capture("absolute-image-file-path", "ReadSingleBarcode");
|
|
566
|
+
* for(let i = 0; i < result.items.length; i++) {
|
|
567
|
+
* //...
|
|
568
|
+
* }
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* @param filePath - The absolute file path and name that you want to capture data from.
|
|
572
|
+
* You have to specify the file name with extension name in the filePath.
|
|
573
|
+
* Supported file type includes “.bmp”, “.jpg”, “.png”, “.gif” or one-page “.tiff”.
|
|
574
|
+
* @param template - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
575
|
+
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
576
|
+
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
577
|
+
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
578
|
+
*
|
|
579
|
+
* @return A {@link CapturedResult} object which contains the derived information from the image processed.
|
|
580
|
+
* If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.
|
|
581
|
+
*
|
|
582
|
+
* @see {@link EnumPresetTemplate}
|
|
583
|
+
* @see {@link CapturedResult}
|
|
584
|
+
* */
|
|
585
|
+
captureFile(filePath: string, template: string = ""): CapturedResult | undefined | null {
|
|
586
|
+
installMethods();
|
|
587
|
+
if (filePath) {
|
|
588
|
+
if (typeof global.captureFile !== 'function') {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
let result = global.captureFile(filePath, template);
|
|
592
|
+
_populateResults(result)
|
|
593
|
+
return result;
|
|
594
|
+
} else {
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Processes An ArrayBuffer object that points to a file in memory to derive important information.
|
|
601
|
+
*
|
|
602
|
+
* @param fileBytes - An ArrayBuffer object that points to a file in memory.
|
|
603
|
+
* @param template - Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:
|
|
604
|
+
* - One of the {@link EnumPresetTemplate} member. This is available only if you have never upload a new template via {@link initSettingsFromFile} or {@link initSettings}.
|
|
605
|
+
* - A string that represents one of the template name that you have uploaded via {@link initSettingsFromFile} or {@link initSettings}.
|
|
606
|
+
* - ""(empty string) to use the default template. The first template will be used if you have uploaded a template file via {@link initSettingsFromFile} or {@link initSettings}.
|
|
607
|
+
*
|
|
608
|
+
* @return A {@link CapturedResult} object which contains the derived information from the image processed.
|
|
609
|
+
* If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.
|
|
610
|
+
*
|
|
611
|
+
* @see {@link EnumPresetTemplate}
|
|
612
|
+
* @see {@link CapturedResult}
|
|
613
|
+
* */
|
|
614
|
+
captureFileBytes(fileBytes: ArrayBuffer, template: string = ""): CapturedResult | undefined | null {
|
|
615
|
+
installMethods();
|
|
616
|
+
if (fileBytes) {
|
|
617
|
+
if (typeof global.captureFileBytes !== 'function') {
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
620
|
+
let result = global.captureFileBytes(fileBytes, template);
|
|
621
|
+
_populateResults(result)
|
|
622
|
+
return result;
|
|
623
|
+
} else {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
private intermediateResultManager: IntermediateResultManager | undefined = undefined;
|
|
629
|
+
|
|
630
|
+
/**@see {@link IntermediateResultManager}*/
|
|
631
|
+
getIntermediateResultManager(): IntermediateResultManager {
|
|
632
|
+
if (!this.intermediateResultManager) {
|
|
633
|
+
this.intermediateResultManager = new IntermediateResultManager();
|
|
634
|
+
}
|
|
635
|
+
return this.intermediateResultManager!!;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* The IntermediateResultManager class is responsible for handling intermediate results obtained during the process of an image.
|
|
641
|
+
* @see {@link CaptureVisionRouter.getIntermediateResultManager}
|
|
642
|
+
* @hideconstructor
|
|
643
|
+
* */
|
|
644
|
+
export class IntermediateResultManager {
|
|
645
|
+
/**
|
|
646
|
+
* Retrieves the original image data.
|
|
647
|
+
* <p>Code Snippet:</p>
|
|
648
|
+
*
|
|
649
|
+
*```
|
|
650
|
+
* let router = CaptureVisionRouter.getInstance();
|
|
651
|
+
* let intermediateResultManager = router.getIntermediateResultManager()
|
|
652
|
+
* router.addResultReceiver({
|
|
653
|
+
* onCaptureResultReceive: result => {
|
|
654
|
+
* let imageData = intermediateResultManager.getOriginalImage(result.originalImageHashId)
|
|
655
|
+
* //...
|
|
656
|
+
* }
|
|
657
|
+
* });
|
|
658
|
+
* ```
|
|
659
|
+
*
|
|
660
|
+
* @param imageHashId - The image hash ID. Get from {@link CapturedResult.originalImageHashId}, {@link DecodedBarcodesResult.originalImageHashId},
|
|
661
|
+
* {@link ProcessedDocumentResult.originalImageHashId}, {@link RecognizedTextLinesResult.originalImageHashId}.
|
|
662
|
+
*
|
|
663
|
+
* @remarks `Do not call this method after calling stopCapturing() or outside the CapturedResultReceiver callback where you get the hashId, otherwise you will not get any valid ImageData.`
|
|
664
|
+
* @see {@link CaptureVisionRouter.addResultReceiver}
|
|
665
|
+
* @see {@link CapturedResultReceiver}
|
|
666
|
+
* */
|
|
667
|
+
getOriginalImage(imageHashId: string): ImageData | undefined | null {
|
|
668
|
+
installMethods();
|
|
669
|
+
if (typeof global.cvr_getOriginalImage !== 'function') {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
return global.cvr_getOriginalImage(imageHashId);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
declare var global: {
|
|
677
|
+
captureImageData: (imageData: ImageData, template: string) => CapturedResult | undefined | null;
|
|
678
|
+
captureFile: (file: string, template: string) => CapturedResult | undefined | null;
|
|
679
|
+
captureFileBytes: (fileBytes: ArrayBuffer, template: string) => CapturedResult | undefined | null;
|
|
680
|
+
getCurrentDeskewedImages: () => ImageData[] | undefined | null;
|
|
681
|
+
getCurrentEnhancedImages: () => ImageData[] | undefined | null;
|
|
682
|
+
cvr_getOriginalImage: (imageHashId: string) => ImageData | undefined | null;
|
|
683
|
+
}
|