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