cordova-plugin-mlkit-suite 0.1.0 → 0.2.0
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/CHANGELOG.md +12 -0
- package/README.md +526 -640
- package/docs/screenshots/ios-text-recognition.jpg +0 -0
- package/package.json +7 -3
- package/plugin.xml +149 -134
- package/src/android/java/BarcodeFrameAnalyzer.java +115 -111
- package/src/android/java/BarcodeOverlayView.java +83 -25
- package/src/android/java/BarcodeScanActivity.java +100 -12
- package/src/android/java/BarcodeScanConfig.java +6 -1
- package/src/android/java/BarcodeScanRegion.java +26 -8
- package/src/android/java/MlKitModelsModuleInstaller.java +35 -16
- package/src/android/java/MlKitSuitePlugin.java +315 -33
- package/src/android/java/SelfieSegmentationProcessor.java +215 -0
- package/src/android/java/StaticImageProcessor.java +208 -151
- package/src/android/java/SubjectSegmentationModuleInstaller.java +154 -0
- package/src/android/java/SubjectSegmentationProcessor.java +189 -0
- package/src/android/mlkit-suite.gradle +30 -0
- package/src/android/res/values/mlkit_suite_strings.xml +8 -0
- package/src/android/res/values-es/mlkit_suite_strings.xml +8 -0
- package/src/ios/BarcodeOverlayView.swift +57 -6
- package/src/ios/BarcodeScanTypes.swift +3 -1
- package/src/ios/BarcodeScanViewController.swift +120 -5
- package/src/ios/MlKitSuitePlugin.swift +222 -13
- package/src/ios/MlKitSuiteResources.bundle/en.lproj/Localizable.strings +4 -0
- package/src/ios/MlKitSuiteResources.bundle/es.lproj/Localizable.strings +4 -0
- package/src/ios/SelfieSegmentationProcessor.swift +105 -0
- package/src/ios/TextRecognitionProcessor.swift +99 -0
- package/tests/ios-image-labeling.test.js +17 -0
- package/tests/ios-live-barcode.test.js +5 -0
- package/tests/ios-selfie-segmentation.test.js +24 -0
- package/tests/ios-static-text.test.js +21 -0
- package/tests/java/BarcodeScanRegionTest.java +12 -0
- package/tests/java-confirmation.test.js +41 -41
- package/tests/js-api.test.js +42 -2
- package/www/MlKit.js +111 -7
- package/docs/screenshots/capabilities.jpg +0 -0
- package/docs/screenshots/demo-tour.gif +0 -0
- package/docs/screenshots/text-recognition.jpg +0 -0
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cordova-plugin-mlkit-suite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Extensible Google ML Kit suite for Cordova document, text, barcode, and guided face processing.",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Extensible Google ML Kit suite for Cordova document, text, barcode, image labeling, selfie and subject segmentation, and guided face processing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Andres Zs",
|
|
7
7
|
"homepage": "https://github.com/andreszs/cordova-plugin-mlkit-suite",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"document-scanner",
|
|
24
24
|
"text-recognition",
|
|
25
25
|
"ocr",
|
|
26
|
+
"image-labeling",
|
|
27
|
+
"selfie-segmentation",
|
|
28
|
+
"subject-segmentation",
|
|
29
|
+
"background-removal",
|
|
26
30
|
"pdf417",
|
|
27
31
|
"qr-code",
|
|
28
32
|
"camera",
|
|
@@ -56,7 +60,7 @@
|
|
|
56
60
|
"LICENSE"
|
|
57
61
|
],
|
|
58
62
|
"scripts": {
|
|
59
|
-
"test": "node tests/js-api.test.js && node tests/java-confirmation.test.js && node tests/ios-live-barcode.test.js && node tests/ios-face-capture.test.js && node tests/localization.test.js"
|
|
63
|
+
"test": "node tests/js-api.test.js && node tests/java-confirmation.test.js && node tests/ios-live-barcode.test.js && node tests/ios-static-text.test.js && node tests/ios-image-labeling.test.js && node tests/ios-selfie-segmentation.test.js && node tests/ios-face-capture.test.js && node tests/localization.test.js"
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
|
package/plugin.xml
CHANGED
|
@@ -1,134 +1,149 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
|
-
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
-
xmlns:tools="http://schemas.android.com/tools"
|
|
5
|
-
id="cordova-plugin-mlkit-suite"
|
|
6
|
-
version="0.
|
|
7
|
-
<name>ML Kit Suite</name>
|
|
8
|
-
<description>Extensible Google ML Kit suite for document, text, barcode, and guided face processing.</description>
|
|
9
|
-
<license>MIT</license>
|
|
10
|
-
<keywords>cordova,android,ios,mlkit,ml-kit,document-scanner,text-recognition,ocr,face-detection,barcode-scanning,pdf417,qr-code,camera,camerax,avfoundation</keywords>
|
|
11
|
-
|
|
12
|
-
<engines>
|
|
13
|
-
<engine name="cordova" version=">=11.0.0" />
|
|
14
|
-
<engine name="cordova-android" version=">=12.0.0 <16.0.0" />
|
|
15
|
-
<engine name="cordova-ios" version=">=8.0.0 <9.0.0" />
|
|
16
|
-
</engines>
|
|
17
|
-
|
|
18
|
-
<js-module src="www/MlKit.js" name="MlKit">
|
|
19
|
-
<clobbers target="MlKit" />
|
|
20
|
-
</js-module>
|
|
21
|
-
|
|
22
|
-
<platform name="android">
|
|
23
|
-
<preference name="ANDROID_MLKIT_MODEL_DELIVERY" default="install-time" />
|
|
24
|
-
<preference name="ANDROID_MLKIT_FACE_MODE" default="inherit" />
|
|
25
|
-
<preference name="ANDROID_MLKIT_BARCODE_MODE" default="inherit" />
|
|
26
|
-
<preference name="ANDROID_MLKIT_OCR_MODE" default="inherit" />
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<uses-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
android:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
android:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
android:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
android:
|
|
56
|
-
|
|
57
|
-
android:
|
|
58
|
-
android:
|
|
59
|
-
<
|
|
60
|
-
android:name="
|
|
61
|
-
android:
|
|
62
|
-
|
|
63
|
-
android:
|
|
64
|
-
|
|
65
|
-
android:
|
|
66
|
-
android:
|
|
67
|
-
|
|
68
|
-
android:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<
|
|
80
|
-
<
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
<source-file src="src/android/java/
|
|
84
|
-
<source-file src="src/android/java/
|
|
85
|
-
<source-file src="src/android/java/
|
|
86
|
-
<source-file src="src/android/java/
|
|
87
|
-
<source-file src="src/android/java/
|
|
88
|
-
<source-file src="src/android/java/
|
|
89
|
-
<source-file src="src/android/java/
|
|
90
|
-
<source-file src="src/android/java/
|
|
91
|
-
<source-file src="src/android/java/
|
|
92
|
-
<source-file src="src/android/java/
|
|
93
|
-
<source-file src="src/android/java/
|
|
94
|
-
<source-file src="src/android/java/
|
|
95
|
-
<source-file src="src/android/java/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<source-file src="src/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
<
|
|
119
|
-
<
|
|
120
|
-
<
|
|
121
|
-
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
+
xmlns:tools="http://schemas.android.com/tools"
|
|
5
|
+
id="cordova-plugin-mlkit-suite"
|
|
6
|
+
version="0.2.0">
|
|
7
|
+
<name>ML Kit Suite</name>
|
|
8
|
+
<description>Extensible Google ML Kit suite for document, text, barcode, image labeling, selfie and subject segmentation, and guided face processing.</description>
|
|
9
|
+
<license>MIT</license>
|
|
10
|
+
<keywords>cordova,android,ios,mlkit,ml-kit,document-scanner,text-recognition,ocr,face-detection,barcode-scanning,image-labeling,selfie-segmentation,subject-segmentation,background-removal,pdf417,qr-code,camera,camerax,avfoundation</keywords>
|
|
11
|
+
|
|
12
|
+
<engines>
|
|
13
|
+
<engine name="cordova" version=">=11.0.0" />
|
|
14
|
+
<engine name="cordova-android" version=">=12.0.0 <16.0.0" />
|
|
15
|
+
<engine name="cordova-ios" version=">=8.0.0 <9.0.0" />
|
|
16
|
+
</engines>
|
|
17
|
+
|
|
18
|
+
<js-module src="www/MlKit.js" name="MlKit">
|
|
19
|
+
<clobbers target="MlKit" />
|
|
20
|
+
</js-module>
|
|
21
|
+
|
|
22
|
+
<platform name="android">
|
|
23
|
+
<preference name="ANDROID_MLKIT_MODEL_DELIVERY" default="install-time" />
|
|
24
|
+
<preference name="ANDROID_MLKIT_FACE_MODE" default="inherit" />
|
|
25
|
+
<preference name="ANDROID_MLKIT_BARCODE_MODE" default="inherit" />
|
|
26
|
+
<preference name="ANDROID_MLKIT_OCR_MODE" default="inherit" />
|
|
27
|
+
<preference name="ANDROID_MLKIT_IMAGE_LABELING_MODE" default="inherit" />
|
|
28
|
+
<preference name="ANDROID_MLKIT_SUBJECT_SEGMENTATION_MODE" default="inherit" />
|
|
29
|
+
|
|
30
|
+
<config-file target="res/xml/config.xml" parent="/*">
|
|
31
|
+
<feature name="MlKitSuite">
|
|
32
|
+
<param name="android-package" value="com.andreszs.plugins.mlkitsuite.MlKitSuitePlugin" />
|
|
33
|
+
<param name="onload" value="true" />
|
|
34
|
+
</feature>
|
|
35
|
+
</config-file>
|
|
36
|
+
|
|
37
|
+
<config-file target="AndroidManifest.xml" parent="/manifest">
|
|
38
|
+
<uses-sdk xmlns:tools="http://schemas.android.com/tools"
|
|
39
|
+
tools:overrideLibrary="com.google.mlkit.vision.documentscanner" />
|
|
40
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
41
|
+
</config-file>
|
|
42
|
+
|
|
43
|
+
<config-file target="AndroidManifest.xml" parent="/manifest/application">
|
|
44
|
+
<meta-data
|
|
45
|
+
android:name="com.andreszs.plugins.mlkitsuite.FACE_MODE"
|
|
46
|
+
android:value="${mlKitSuiteFaceMode}" />
|
|
47
|
+
<meta-data
|
|
48
|
+
android:name="com.andreszs.plugins.mlkitsuite.BARCODE_MODE"
|
|
49
|
+
android:value="${mlKitSuiteBarcodeMode}" />
|
|
50
|
+
<meta-data
|
|
51
|
+
android:name="com.andreszs.plugins.mlkitsuite.OCR_MODE"
|
|
52
|
+
android:value="${mlKitSuiteOcrMode}" />
|
|
53
|
+
<meta-data
|
|
54
|
+
android:name="com.andreszs.plugins.mlkitsuite.IMAGE_LABELING_MODE"
|
|
55
|
+
android:value="${mlKitSuiteImageLabelingMode}" />
|
|
56
|
+
<meta-data
|
|
57
|
+
android:name="com.andreszs.plugins.mlkitsuite.SUBJECT_SEGMENTATION_MODE"
|
|
58
|
+
android:value="${mlKitSuiteSubjectSegmentationMode}" />
|
|
59
|
+
<meta-data
|
|
60
|
+
android:name="${mlKitSuiteDependencyMetadataName}"
|
|
61
|
+
android:value="${mlKitSuiteDependencyMetadataValue}" />
|
|
62
|
+
<activity
|
|
63
|
+
android:name="com.andreszs.plugins.mlkitsuite.FaceCaptureActivity"
|
|
64
|
+
android:exported="false"
|
|
65
|
+
android:screenOrientation="sensorPortrait"
|
|
66
|
+
android:theme="@style/MlKitSuiteFaceCaptureTheme" />
|
|
67
|
+
<activity
|
|
68
|
+
android:name="com.andreszs.plugins.mlkitsuite.BarcodeScanActivity"
|
|
69
|
+
android:exported="false"
|
|
70
|
+
android:screenOrientation="sensorPortrait"
|
|
71
|
+
android:theme="@style/MlKitSuiteCameraTheme" />
|
|
72
|
+
<activity
|
|
73
|
+
android:name="com.andreszs.plugins.mlkitsuite.DocumentScanActivity"
|
|
74
|
+
android:exported="false"
|
|
75
|
+
android:screenOrientation="sensorPortrait"
|
|
76
|
+
android:theme="@style/MlKitSuiteCameraTheme" />
|
|
77
|
+
</config-file>
|
|
78
|
+
|
|
79
|
+
<framework src="src/android/mlkit-suite.gradle" custom="true" type="gradleReference" />
|
|
80
|
+
<resource-file src="src/android/res/values/mlkit_suite_styles.xml" target="res/values/mlkit_suite_styles.xml" />
|
|
81
|
+
<resource-file src="src/android/res/values/mlkit_suite_strings.xml" target="res/values/mlkit_suite_strings.xml" />
|
|
82
|
+
<resource-file src="src/android/res/values-es/mlkit_suite_strings.xml" target="res/values-es/mlkit_suite_strings.xml" />
|
|
83
|
+
<source-file src="src/android/java/MlKitLocalization.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
84
|
+
<source-file src="src/android/java/MlKitSuitePlugin.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
85
|
+
<source-file src="src/android/java/FaceCaptureActivity.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
86
|
+
<source-file src="src/android/java/FaceCaptureConfig.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
87
|
+
<source-file src="src/android/java/FaceCaptureModels.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
88
|
+
<source-file src="src/android/java/FaceFrameAnalyzer.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
89
|
+
<source-file src="src/android/java/FaceOverlayView.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
90
|
+
<source-file src="src/android/java/FaceStillProcessor.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
91
|
+
<source-file src="src/android/java/BarcodeScanActivity.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
92
|
+
<source-file src="src/android/java/BarcodeScanConfig.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
93
|
+
<source-file src="src/android/java/BarcodeConfirmationTracker.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
94
|
+
<source-file src="src/android/java/BarcodeScanRegion.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
95
|
+
<source-file src="src/android/java/BarcodeIconDrawable.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
96
|
+
<source-file src="src/android/java/BarcodeFrameAnalyzer.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
97
|
+
<source-file src="src/android/java/BarcodeOverlayView.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
98
|
+
<source-file src="src/android/java/DocumentScanConfig.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
99
|
+
<source-file src="src/android/java/DocumentScanActivity.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
100
|
+
<source-file src="src/android/java/DocumentScannerModuleInstaller.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
101
|
+
<source-file src="src/android/java/MlKitModelsModuleInstaller.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
102
|
+
<source-file src="src/android/java/MlKitLoadingDialog.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
103
|
+
<source-file src="src/android/java/StaticImageProcessor.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
104
|
+
<source-file src="src/android/java/SelfieSegmentationProcessor.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
105
|
+
<source-file src="src/android/java/SubjectSegmentationModuleInstaller.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
106
|
+
<source-file src="src/android/java/SubjectSegmentationProcessor.java" target-dir="app/src/main/java/com/andreszs/plugins/mlkitsuite" />
|
|
107
|
+
</platform>
|
|
108
|
+
|
|
109
|
+
<platform name="ios">
|
|
110
|
+
<config-file target="config.xml" parent="/*">
|
|
111
|
+
<feature name="MlKitSuite">
|
|
112
|
+
<param name="ios-package" value="MlKitSuitePlugin" />
|
|
113
|
+
<param name="onload" value="true" />
|
|
114
|
+
</feature>
|
|
115
|
+
</config-file>
|
|
116
|
+
|
|
117
|
+
<source-file src="src/ios/FaceCaptureTypes.swift" />
|
|
118
|
+
<source-file src="src/ios/MlKitLocalization.swift" />
|
|
119
|
+
<source-file src="src/ios/FaceOverlayView.swift" />
|
|
120
|
+
<source-file src="src/ios/FaceStillProcessor.swift" />
|
|
121
|
+
<source-file src="src/ios/FaceCaptureViewController.swift" />
|
|
122
|
+
<source-file src="src/ios/BarcodeScanTypes.swift" />
|
|
123
|
+
<source-file src="src/ios/BarcodeOverlayView.swift" />
|
|
124
|
+
<source-file src="src/ios/BarcodeScanViewController.swift" />
|
|
125
|
+
<source-file src="src/ios/TextRecognitionProcessor.swift" />
|
|
126
|
+
<source-file src="src/ios/SelfieSegmentationProcessor.swift" />
|
|
127
|
+
<source-file src="src/ios/MlKitSuitePlugin.swift" />
|
|
128
|
+
<resource-file src="src/ios/MlKitSuitePrivacy.bundle" target="MlKitSuitePrivacy.bundle" />
|
|
129
|
+
<resource-file src="src/ios/MlKitSuiteResources.bundle" target="MlKitSuiteResources.bundle" />
|
|
130
|
+
|
|
131
|
+
<framework src="AVFoundation.framework" />
|
|
132
|
+
<framework src="CoreImage.framework" />
|
|
133
|
+
<framework src="WebKit.framework" />
|
|
134
|
+
|
|
135
|
+
<podspec>
|
|
136
|
+
<config>
|
|
137
|
+
<source url="https://cdn.cocoapods.org/" />
|
|
138
|
+
</config>
|
|
139
|
+
<pods>
|
|
140
|
+
<pod name="GoogleMLKit/FaceDetection" spec="8.0.0" />
|
|
141
|
+
<pod name="GoogleMLKit/TextRecognition" spec="8.0.0" />
|
|
142
|
+
<pod name="GoogleMLKit/BarcodeScanning" spec="8.0.0" />
|
|
143
|
+
<pod name="GoogleMLKit/ImageLabeling" spec="8.0.0" />
|
|
144
|
+
<pod name="GoogleMLKit/SegmentationSelfie" spec="8.0.0" />
|
|
145
|
+
</pods>
|
|
146
|
+
</podspec>
|
|
147
|
+
</platform>
|
|
148
|
+
</plugin>
|
|
149
|
+
|
|
@@ -1,111 +1,115 @@
|
|
|
1
|
-
package com.andreszs.plugins.mlkitsuite;
|
|
2
|
-
|
|
3
|
-
import android.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import androidx.
|
|
7
|
-
import androidx.camera.core.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import com.google.mlkit.vision.barcode.
|
|
11
|
-
import com.google.mlkit.vision.barcode.
|
|
12
|
-
import com.google.mlkit.vision.barcode.
|
|
13
|
-
import com.google.mlkit.vision.common.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import java.util.
|
|
17
|
-
import java.util.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
void
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
void
|
|
26
|
-
void
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
private final
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
int
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
package com.andreszs.plugins.mlkitsuite;
|
|
2
|
+
|
|
3
|
+
import android.graphics.Rect;
|
|
4
|
+
import android.media.Image;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.camera.core.ImageAnalysis;
|
|
8
|
+
import androidx.camera.core.ImageProxy;
|
|
9
|
+
|
|
10
|
+
import com.google.mlkit.vision.barcode.BarcodeScanner;
|
|
11
|
+
import com.google.mlkit.vision.barcode.BarcodeScannerOptions;
|
|
12
|
+
import com.google.mlkit.vision.barcode.BarcodeScanning;
|
|
13
|
+
import com.google.mlkit.vision.barcode.common.Barcode;
|
|
14
|
+
import com.google.mlkit.vision.common.InputImage;
|
|
15
|
+
|
|
16
|
+
import java.util.Arrays;
|
|
17
|
+
import java.util.List;
|
|
18
|
+
import java.util.concurrent.Executor;
|
|
19
|
+
|
|
20
|
+
final class BarcodeFrameAnalyzer implements ImageAnalysis.Analyzer, AutoCloseable {
|
|
21
|
+
interface Listener {
|
|
22
|
+
void onSearching();
|
|
23
|
+
void onOutsideGuide();
|
|
24
|
+
boolean isInsideGuide(Barcode barcode, int imageWidth, int imageHeight);
|
|
25
|
+
void onCandidate(String text, String format, int confirmedFrames, int requiredFrames);
|
|
26
|
+
void onConfirmed(String text, String format, Rect bounds,
|
|
27
|
+
int imageWidth, int imageHeight);
|
|
28
|
+
void onAnalyzerError(Exception error);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private final BarcodeScanner scanner;
|
|
32
|
+
private final BarcodeConfirmationTracker tracker =
|
|
33
|
+
new BarcodeConfirmationTracker(BarcodeScanConfig.CONFIRMATION_FRAMES);
|
|
34
|
+
private final Listener listener;
|
|
35
|
+
private final Executor callbackExecutor;
|
|
36
|
+
private boolean completed;
|
|
37
|
+
|
|
38
|
+
BarcodeFrameAnalyzer(BarcodeScanConfig config, Listener listener, Executor callbackExecutor) {
|
|
39
|
+
int[] values = config.formatValues;
|
|
40
|
+
int[] additional = Arrays.copyOfRange(values, 1, values.length);
|
|
41
|
+
BarcodeScannerOptions options = new BarcodeScannerOptions.Builder()
|
|
42
|
+
.setBarcodeFormats(values[0], additional)
|
|
43
|
+
.build();
|
|
44
|
+
scanner = BarcodeScanning.getClient(options);
|
|
45
|
+
this.listener = listener;
|
|
46
|
+
this.callbackExecutor = callbackExecutor;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public void analyze(@NonNull ImageProxy imageProxy) {
|
|
51
|
+
if (completed) {
|
|
52
|
+
imageProxy.close();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
Image mediaImage = imageProxy.getImage();
|
|
56
|
+
if (mediaImage == null) {
|
|
57
|
+
tracker.reset();
|
|
58
|
+
callbackExecutor.execute(listener::onSearching);
|
|
59
|
+
imageProxy.close();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
InputImage image = InputImage.fromMediaImage(mediaImage,
|
|
63
|
+
imageProxy.getImageInfo().getRotationDegrees());
|
|
64
|
+
int rotation = imageProxy.getImageInfo().getRotationDegrees();
|
|
65
|
+
int imageWidth = rotation % 180 == 0 ? imageProxy.getWidth() : imageProxy.getHeight();
|
|
66
|
+
int imageHeight = rotation % 180 == 0 ? imageProxy.getHeight() : imageProxy.getWidth();
|
|
67
|
+
scanner.process(image)
|
|
68
|
+
.addOnSuccessListener(callbackExecutor,
|
|
69
|
+
barcodes -> handleBarcodes(barcodes, imageWidth, imageHeight))
|
|
70
|
+
.addOnFailureListener(callbackExecutor, error -> {
|
|
71
|
+
tracker.reset();
|
|
72
|
+
listener.onAnalyzerError(error);
|
|
73
|
+
})
|
|
74
|
+
.addOnCompleteListener(task -> imageProxy.close());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private void handleBarcodes(List<Barcode> barcodes, int imageWidth, int imageHeight) {
|
|
78
|
+
if (completed) return;
|
|
79
|
+
Barcode selected = null;
|
|
80
|
+
boolean detectedOutsideGuide = false;
|
|
81
|
+
for (Barcode barcode : barcodes) {
|
|
82
|
+
String rawValue = barcode.getRawValue();
|
|
83
|
+
if (rawValue != null && !rawValue.isEmpty()) {
|
|
84
|
+
if (listener.isInsideGuide(barcode, imageWidth, imageHeight)) {
|
|
85
|
+
selected = barcode;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
detectedOutsideGuide = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (selected == null) {
|
|
92
|
+
tracker.reset();
|
|
93
|
+
if (detectedOutsideGuide) listener.onOutsideGuide();
|
|
94
|
+
else listener.onSearching();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
String text = selected.getRawValue();
|
|
99
|
+
String format = BarcodeScanConfig.nameForFormat(selected.getFormat());
|
|
100
|
+
int frames = tracker.observe(text, format);
|
|
101
|
+
listener.onCandidate(text, format, frames, BarcodeScanConfig.CONFIRMATION_FRAMES);
|
|
102
|
+
if (tracker.isConfirmed()) {
|
|
103
|
+
completed = true;
|
|
104
|
+
Rect bounds = selected.getBoundingBox();
|
|
105
|
+
listener.onConfirmed(text, format, bounds == null ? null : new Rect(bounds),
|
|
106
|
+
imageWidth, imageHeight);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Override
|
|
111
|
+
public void close() {
|
|
112
|
+
completed = true;
|
|
113
|
+
scanner.close();
|
|
114
|
+
}
|
|
115
|
+
}
|