├── .DS_Store
├── LICENSE
├── README.md
├── android
├── .DS_Store
├── build.gradle
├── gradlew
├── gradlew.bat
└── src
│ ├── .DS_Store
│ └── main
│ ├── .DS_Store
│ ├── AndroidManifest.xml
│ └── java
│ ├── .DS_Store
│ └── com
│ ├── .DS_Store
│ └── mlkit
│ ├── RNMlKitModule.java
│ ├── RNMlKitPackage.java
│ └── Utils.java
├── index.js
├── ios
├── RNMlKit.h
├── RNMlKit.m
├── RNMlKit.podspec
├── RNMlKit.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcuserdata
│ │ │ └── trackingtrade.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── trackingtrade.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── RNMlKit.xcworkspace
│ └── contents.xcworkspacedata
├── package-lock.json
└── package.json
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/.DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Mateus Cardoso
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # react-native-firebase-mlkit
3 | React Native wrapper for functionality of https://developers.google.com/ml-kit/
4 |
5 | ## Getting started
6 |
7 | `$ npm install react-native-firebase-mlkit --save`
8 |
9 | ## Compatibility
10 |
11 | As of the moment, this wrapper of firebase Ml Kit supports Android and iOS.
12 |
13 | ## Mostly automatic installation
14 |
15 | `$ react-native link react-native-firebase-mlkit`
16 |
17 | *Don't forget to ...*
18 | - *add google-services.json to the appropriate folder (/android/app/) __(Android only)__*
19 | - *add GoogleService-Info.plist to the appropriate folder (/ios/) __(iOS only)__*
20 | - *install [CocoaPods](https://cocoapods.org/) in your react-native project and add the following line to your Podfile then run `pod install` __(iOS only)__*
21 | ```
22 | pod 'Firebase/Core'
23 | pod 'Firebase/MLVision'
24 | pod 'Firebase/MLVisionTextModel'
25 | pod 'Firebase/MLVisionBarcodeModel'
26 | ```
27 |
28 | ### Manual installation
29 |
30 |
31 | #### iOS
32 |
33 | 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
34 | 2. Go to `node_modules` ➜ `react-native-firebase-mlkit` and add `RNMlKit.xcodeproj`
35 | 3. In XCode, in the project navigator, select your project. Add `libRNMlKit.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
36 | 4. Run your project (`Cmd+R`)<
37 |
38 | ```
39 | Error: MLVisionTextModel duplicate symbols with React Native
40 |
41 | Solved enabling the dead code stripping in xcode for debug.
42 | You can enable it in Target > Build Settings > search for "Dead code stripping".
43 |
44 | ```
45 |
46 | #### Android
47 |
48 | 1. Open up `android/app/src/main/java/[...]/MainActivity.java`
49 | - Add `import com.mlkit.RNMlKitPackage;` to the imports at the top of the file
50 | - Add `new RNMlKitPackage()` to the list returned by the `getPackages()` method
51 | 2. Append the following lines to `android/settings.gradle`:
52 | ```
53 | include ':react-native-firebase-mlkit'
54 | project(':react-native-firebase-mlkit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase-mlkit/android')
55 | ```
56 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
57 |
58 | ```
59 | ...
60 | dependencies {
61 | implementation 'com.google.firebase:firebase-core:16.0.1'
62 | implementation 'com.google.firebase:firebase-ml-vision:17.0.0'
63 |
64 | implementation (project(':react-native-firebase-mlkit')) {
65 | exclude group: 'com.google.firebase'
66 | }
67 | }
68 |
69 | // Place this line at the end of file
70 |
71 | apply plugin: 'com.google.gms.google-services'
72 |
73 | // Work around for onesignal-gradle-plugin compatibility
74 | com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
75 | ```
76 |
77 | 4. Insert the following lines inside the dependencies block in `android/build.gradle`:
78 |
79 | ```
80 | buildscript {
81 | repositories {
82 | google()
83 | ...
84 | }
85 | dependencies {
86 | classpath 'com.android.tools.build:gradle:3.0.1'
87 | classpath 'com.google.gms:google-services:4.0.2' // google-services plugin
88 | }
89 | }
90 | ```
91 |
92 |
93 | ## Usage (Example using [react-native-camera](https://github.com/react-native-community/react-native-camera))
94 |
95 | ```javascript
96 |
97 | import RNMlKit from 'react-native-firebase-mlkit';
98 |
99 | export class textRecognition extends Component {
100 | ...
101 |
102 | async takePicture() {
103 | if (this.camera) {
104 | const options = { quality: 0.5, base64: true, skipProcessing: true, forceUpOrientation: true };
105 | const data = await this.camera.takePictureAsync(options);
106 | // for on-device (Supports Android and iOS)
107 | const deviceTextRecognition = await RNMlKit.deviceTextRecognition(data.uri);
108 | console.log('Text Recognition On-Device', deviceTextRecognition);
109 | // for cloud (At the moment supports only Android)
110 | const cloudTextRecognition = await RNMlKit.cloudTextRecognition(data.uri);
111 | console.log('Text Recognition Cloud', cloudTextRecognition);
112 | }
113 | };
114 |
115 | ...
116 | }
117 | ```
118 |
119 |
--------------------------------------------------------------------------------
/android/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/android/.DS_Store
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | buildscript {
3 | repositories {
4 | jcenter()
5 | }
6 |
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.1'
9 | }
10 | }
11 |
12 | apply plugin: 'com.android.library'
13 |
14 | android {
15 | compileSdkVersion 27
16 |
17 | defaultConfig {
18 | minSdkVersion 16
19 | targetSdkVersion 27
20 | versionCode 1
21 | versionName "1.0"
22 | }
23 | lintOptions {
24 | abortOnError false
25 | }
26 | }
27 |
28 | repositories {
29 | mavenCentral()
30 | }
31 |
32 | dependencies {
33 | implementation 'com.google.firebase:firebase-core:+'
34 | implementation 'com.google.firebase:firebase-ml-vision:+'
35 | implementation 'com.facebook.react:react-native:+'
36 | }
--------------------------------------------------------------------------------
/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/android/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/android/src/.DS_Store
--------------------------------------------------------------------------------
/android/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/android/src/main/.DS_Store
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/android/src/main/java/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/android/src/main/java/.DS_Store
--------------------------------------------------------------------------------
/android/src/main/java/com/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/android/src/main/java/com/.DS_Store
--------------------------------------------------------------------------------
/android/src/main/java/com/mlkit/RNMlKitModule.java:
--------------------------------------------------------------------------------
1 |
2 | package com.mlkit;
3 |
4 | import android.graphics.Rect;
5 | import android.support.annotation.NonNull;
6 | import android.util.Log;
7 |
8 | import com.facebook.react.bridge.Arguments;
9 | import com.facebook.react.bridge.Promise;
10 | import com.facebook.react.bridge.ReactApplicationContext;
11 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
12 | import com.facebook.react.bridge.ReactMethod;
13 | import com.facebook.react.bridge.WritableArray;
14 | import com.facebook.react.bridge.WritableMap;
15 | import com.google.android.gms.tasks.OnFailureListener;
16 | import com.google.android.gms.tasks.OnSuccessListener;
17 | import com.google.android.gms.tasks.Task;
18 | import com.google.firebase.ml.vision.FirebaseVision;
19 | import com.google.firebase.ml.vision.common.FirebaseVisionPoint;
20 | import com.google.firebase.ml.vision.face.FirebaseVisionFace;
21 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceContour;
22 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetector;
23 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetectorOptions;
24 | import com.google.firebase.ml.vision.text.FirebaseVisionCloudTextRecognizerOptions;
25 | import com.google.firebase.ml.vision.common.FirebaseVisionImage;
26 | import com.google.firebase.ml.vision.text.FirebaseVisionText;
27 | import com.google.firebase.ml.vision.text.FirebaseVisionTextRecognizer;
28 | import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
29 | import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
30 | import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions;
31 |
32 | import java.io.IOException;
33 | import java.util.List;
34 | import java.util.ArrayList;
35 |
36 | public class RNMlKitModule extends ReactContextBaseJavaModule {
37 |
38 | private final ReactApplicationContext reactContext;
39 | private FirebaseVisionTextRecognizer textDetector;
40 | private FirebaseVisionTextRecognizer cloudTextDetector;
41 | private FirebaseVisionFaceDetector faceDetector;
42 |
43 | public RNMlKitModule(ReactApplicationContext reactContext) {
44 | super(reactContext);
45 | this.reactContext = reactContext;
46 | }
47 |
48 | @ReactMethod
49 | public void deviceBarcodeRecognition(String uri, final Promise promise) {
50 | try {
51 | FirebaseVisionBarcodeDetectorOptions options =
52 | new FirebaseVisionBarcodeDetectorOptions.Builder()
53 | .setBarcodeFormats(FirebaseVisionBarcode. FORMAT_ALL_FORMATS)
54 | .build();
55 | FirebaseVisionImage image = FirebaseVisionImage.fromFilePath(this.reactContext, android.net.Uri.parse(uri));
56 | FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance()
57 | .getVisionBarcodeDetector(options);
58 |
59 | Task> result = detector.detectInImage(image)
60 | .addOnSuccessListener(new OnSuccessListener>() {
61 | @Override
62 | public void onSuccess(List barcodes) {
63 | WritableArray data = Arguments.createArray();
64 | WritableMap info = Arguments.createMap();
65 |
66 | for (FirebaseVisionBarcode barcode: barcodes) {
67 | info = Arguments.createMap();
68 | info.putString("format", barcodeFormat(barcode.getFormat()));
69 | info.putString("value", barcode.getRawValue());
70 | data.pushMap(info);
71 | }
72 | promise.resolve(data);
73 | }
74 | })
75 | .addOnFailureListener(new OnFailureListener() {
76 | @Override
77 | public void onFailure(@NonNull Exception e) {
78 | e.printStackTrace();
79 | promise.reject(e);
80 | }
81 | });
82 | } catch (IOException e) {
83 | promise.reject(e);
84 | e.printStackTrace();
85 | }
86 | }
87 |
88 | @ReactMethod
89 | public void deviceTextRecognition(String uri, final Promise promise) {
90 | try {
91 | FirebaseVisionImage image = FirebaseVisionImage.fromFilePath(this.reactContext, android.net.Uri.parse(uri));
92 | FirebaseVisionTextRecognizer detector = this.getTextRecognizerInstance();
93 | Task result =
94 | detector.processImage(image)
95 | .addOnSuccessListener(new OnSuccessListener() {
96 | @Override
97 | public void onSuccess(FirebaseVisionText firebaseVisionText) {
98 | promise.resolve(processDeviceResult(firebaseVisionText));
99 | }
100 | })
101 | .addOnFailureListener(
102 | new OnFailureListener() {
103 | @Override
104 | public void onFailure(@NonNull Exception e) {
105 | e.printStackTrace();
106 | promise.reject(e);
107 | }
108 | });;
109 | } catch (IOException e) {
110 | promise.reject(e);
111 | e.printStackTrace();
112 | }
113 | }
114 | @ReactMethod
115 | public void deviceFaceRecognition(String uri, final Promise promise){
116 | try{
117 | FirebaseVisionImage image = FirebaseVisionImage.fromFilePath(this.reactContext, android.net.Uri.parse(uri));
118 | FirebaseVisionFaceDetector detector = this.getFaceDetectorInstance();
119 |
120 | Task> result = detector.detectInImage(image)
121 | .addOnSuccessListener(new OnSuccessListener>() {
122 | @Override
123 | public void onSuccess(List firebaseVisionFaces) {
124 | promise.resolve(processFaceDetectionResult(firebaseVisionFaces));
125 | }
126 | })
127 | .addOnFailureListener(new OnFailureListener() {
128 | @Override
129 | public void onFailure(@NonNull Exception e) {
130 | e.printStackTrace();
131 | promise.reject(e);
132 | }
133 | });
134 | }catch (Exception e){
135 | promise.reject(e);
136 | e.printStackTrace();
137 | }
138 | }
139 | private FirebaseVisionTextRecognizer getTextRecognizerInstance() {
140 | if (this.textDetector == null) {
141 | this.textDetector = FirebaseVision.getInstance().getOnDeviceTextRecognizer();
142 | }
143 |
144 | return this.textDetector;
145 | }
146 | private FirebaseVisionFaceDetector getFaceDetectorInstance(){
147 | if(this.faceDetector == null){
148 | //=====Set options=====
149 | FirebaseVisionFaceDetectorOptions options =
150 | new FirebaseVisionFaceDetectorOptions.Builder()
151 | .setClassificationMode(FirebaseVisionFaceDetectorOptions.ALL_CONTOURS)
152 | .setLandmarkMode(FirebaseVisionFaceDetectorOptions.ALL_LANDMARKS)
153 | .setContourMode(FirebaseVisionFaceDetectorOptions.ALL_CONTOURS)
154 | .setClassificationMode(FirebaseVisionFaceDetectorOptions.ALL_CLASSIFICATIONS)
155 | .setMinFaceSize(0.15f)
156 | .enableTracking()
157 | .build();
158 | //=====================
159 | this.faceDetector = FirebaseVision.getInstance().getVisionFaceDetector(options);
160 | }
161 | return this.faceDetector;
162 | }
163 |
164 | @ReactMethod
165 | public void close(final Promise promise) {
166 | if(this.textDetector != null) {
167 | try {
168 | this.textDetector.close();
169 | this.textDetector = null;
170 | promise.resolve(true);
171 | } catch (IOException e) {
172 | e.printStackTrace();
173 | promise.reject(e);
174 | }
175 | }
176 |
177 | if(this.cloudTextDetector != null) {
178 | try {
179 | this.cloudTextDetector.close();
180 | this.cloudTextDetector = null;
181 | promise.resolve(true);
182 | } catch (IOException e) {
183 | e.printStackTrace();
184 | promise.reject(e);
185 | }
186 | }
187 | if(this.faceDetector != null) {
188 | try {
189 | this.faceDetector.close();
190 | this.faceDetector = null;
191 | promise.resolve(true);
192 | } catch (IOException e) {
193 | e.printStackTrace();
194 | promise.reject(e);
195 | }
196 | }
197 | }
198 |
199 | private FirebaseVisionTextRecognizer getCloudTextRecognizerInstance() {
200 | if (this.cloudTextDetector == null) {
201 | this.cloudTextDetector = FirebaseVision.getInstance().getCloudTextRecognizer();
202 | }
203 |
204 | return this.cloudTextDetector;
205 | }
206 |
207 | @ReactMethod
208 | public void cloudTextRecognition(String uri, final Promise promise) {
209 | try {
210 | FirebaseVisionTextRecognizer detector = this.getCloudTextRecognizerInstance();
211 | FirebaseVisionImage image = FirebaseVisionImage.fromFilePath(this.reactContext, android.net.Uri.parse(uri));
212 | Task result =
213 | detector.processImage(image)
214 | .addOnSuccessListener(new OnSuccessListener() {
215 | @Override
216 | public void onSuccess(FirebaseVisionText firebaseVisionText) {
217 | promise.resolve(processCloudResult(firebaseVisionText));
218 | }
219 | })
220 | .addOnFailureListener(
221 | new OnFailureListener() {
222 | @Override
223 | public void onFailure(@NonNull Exception e) {
224 | e.printStackTrace();
225 | promise.reject(e);
226 | }
227 | });
228 | } catch (IOException e) {
229 | promise.reject(e);
230 | e.printStackTrace();
231 | }
232 | }
233 |
234 | private String barcodeFormat(int format) {
235 | switch (format) {
236 | case FirebaseVisionBarcode.FORMAT_CODE_128:
237 | return "CODE_128";
238 |
239 | case FirebaseVisionBarcode.FORMAT_CODE_39:
240 | return "CODE_39";
241 |
242 | case FirebaseVisionBarcode.FORMAT_CODE_93:
243 | return "CODE_93";
244 |
245 | case FirebaseVisionBarcode.FORMAT_CODABAR:
246 | return "CODABAR";
247 |
248 | case FirebaseVisionBarcode.FORMAT_DATA_MATRIX:
249 | return "DATA_MATRIX";
250 |
251 | case FirebaseVisionBarcode.FORMAT_EAN_13:
252 | return "EAN_13";
253 |
254 | case FirebaseVisionBarcode.FORMAT_EAN_8:
255 | return "EAN_8";
256 |
257 | case FirebaseVisionBarcode.FORMAT_ITF:
258 | return "ITF";
259 |
260 | case FirebaseVisionBarcode.FORMAT_QR_CODE:
261 | return "QR_CODE";
262 |
263 | case FirebaseVisionBarcode.FORMAT_UPC_A:
264 | return "UPC_A";
265 |
266 | case FirebaseVisionBarcode.FORMAT_UPC_E:
267 | return "UPC_E";
268 |
269 | case FirebaseVisionBarcode.FORMAT_PDF417:
270 | return "PDF417";
271 |
272 | case FirebaseVisionBarcode.FORMAT_AZTEC:
273 | return "AZTEC";
274 |
275 | default:
276 | return "UNKNOWN";
277 | }
278 | }
279 |
280 |
281 | /**
282 | * Converts firebaseVisionText into a map
283 | *
284 | * @param firebaseVisionText
285 | * @return
286 | */
287 | private WritableArray processDeviceResult(FirebaseVisionText firebaseVisionText) {
288 | WritableArray data = Arguments.createArray();
289 | WritableMap info = Arguments.createMap();
290 | WritableMap coordinates = Arguments.createMap();
291 | List blocks = firebaseVisionText.getTextBlocks();
292 |
293 | if (blocks.size() == 0) {
294 | return data;
295 | }
296 |
297 | for (int i = 0; i < blocks.size(); i++) {
298 | List lines = blocks.get(i).getLines();
299 | info = Arguments.createMap();
300 | coordinates = Arguments.createMap();
301 |
302 | Rect boundingBox = blocks.get(i).getBoundingBox();
303 |
304 | coordinates.putInt("top", boundingBox.top);
305 | coordinates.putInt("left", boundingBox.left);
306 | coordinates.putInt("width", boundingBox.width());
307 | coordinates.putInt("height", boundingBox.height());
308 |
309 | info.putMap("blockCoordinates", coordinates);
310 | info.putString("blockText", blocks.get(i).getText());
311 | info.putString("resultText", firebaseVisionText.getText());
312 |
313 | for (int j = 0; j < lines.size(); j++) {
314 | List elements = lines.get(j).getElements();
315 | info.putString("lineText", lines.get(j).getText());
316 |
317 | for (int k = 0; k < elements.size(); k++) {
318 | info.putString("elementText", elements.get(k).getText());
319 | }
320 | }
321 |
322 | data.pushMap(info);
323 | }
324 |
325 | return data;
326 | }
327 |
328 | private WritableArray processCloudResult(FirebaseVisionText firebaseVisionText) {
329 | WritableArray data = Arguments.createArray();
330 | WritableMap info = Arguments.createMap();
331 | WritableMap coordinates = Arguments.createMap();
332 | List blocks = firebaseVisionText.getTextBlocks();
333 |
334 | if (blocks.size() == 0) {
335 | return data;
336 | }
337 |
338 | for (int i = 0; i < blocks.size(); i++) {
339 | List lines = blocks.get(i).getLines();
340 | info = Arguments.createMap();
341 | coordinates = Arguments.createMap();
342 |
343 | Rect boundingBox = blocks.get(i).getBoundingBox();
344 |
345 | coordinates.putInt("top", boundingBox.top);
346 | coordinates.putInt("left", boundingBox.left);
347 | coordinates.putInt("width", boundingBox.width());
348 | coordinates.putInt("height", boundingBox.height());
349 |
350 | info.putMap("blockCoordinates", coordinates);
351 | info.putString("blockText", blocks.get(i).getText());
352 |
353 | for (int j = 0; j < lines.size(); j++) {
354 | List elements = lines.get(j).getElements();
355 | info.putString("lineText", lines.get(j).getText());
356 |
357 | for (int k = 0; k < elements.size(); k++) {
358 | info.putString("elementText", elements.get(k).getText());
359 | }
360 | }
361 |
362 | data.pushMap(info);
363 | }
364 |
365 | return data;
366 | }
367 |
368 | private WritableArray processFaceDetectionResult(List firebaseVisionFaces){
369 | WritableArray data = Arguments.createArray();
370 |
371 | if(firebaseVisionFaces.size() > 0){
372 | WritableMap info = Arguments.createMap();
373 | for (FirebaseVisionFace face : firebaseVisionFaces){
374 | info = Arguments.createMap();
375 | //face bounding box
376 | Rect faceBounding = face.getBoundingBox();
377 |
378 | WritableMap faceBox = Arguments.createMap();
379 | faceBox.putInt("top", faceBounding.top);
380 | faceBox.putInt("right", faceBounding.right);
381 | faceBox.putInt("bottom", faceBounding.bottom);
382 | faceBox.putInt("left", faceBounding.left);
383 |
384 | info.putMap("faceBoundingRect", faceBox);
385 |
386 | // If classification was enabled:
387 | if (face.getSmilingProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
388 | float smileProb = face.getSmilingProbability();
389 | info.putDouble("smileProbability", (double)smileProb);
390 | }
391 | if (face.getRightEyeOpenProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
392 | float rightEyeOpenProb = face.getRightEyeOpenProbability();
393 | info.putDouble("rightEyeOpenProbability", (double)rightEyeOpenProb);
394 | }
395 |
396 | // If face tracking was enabled:
397 | if (face.getTrackingId() != FirebaseVisionFace.INVALID_ID) {
398 | int id = face.getTrackingId();
399 | info.putInt("faceTrackingId", id);
400 | }
401 | //eyes
402 | info.putArray("leftEyeContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LEFT_EYE));
403 | info.putArray("rightEyeContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.RIGHT_EYE));
404 | //face
405 | info.putArray("faceContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.FACE));
406 | //lower lip
407 | info.putArray("lowerLipBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LOWER_LIP_BOTTOM));
408 | info.putArray("lowerLipBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LOWER_LIP_TOP));
409 | //upper lip
410 | info.putArray("upperLipTopContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.UPPER_LIP_TOP));
411 | info.putArray("upperLipBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.UPPER_LIP_BOTTOM));
412 | //nose
413 | info.putArray("noiseBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.NOSE_BOTTOM));
414 | info.putArray("noiseBridgeContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.NOSE_BRIDGE));
415 | //left eyebrow
416 | info.putArray("leftEyeBrowBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LEFT_EYEBROW_BOTTOM));
417 | info.putArray("leftEyeBrowTopContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LEFT_EYEBROW_TOP));
418 | // right eyebrow
419 | info.putArray("rightEyeBrowBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.RIGHT_EYEBROW_BOTTOM));
420 | info.putArray("rightEyeBrowTopContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.RIGHT_EYEBROW_TOP));
421 |
422 |
423 |
424 | data.pushMap(info);
425 | }
426 | }
427 |
428 | return data;
429 | }
430 | @Override
431 | public String getName() {
432 | return "RNMlKit";
433 | }
434 | }
435 |
--------------------------------------------------------------------------------
/android/src/main/java/com/mlkit/RNMlKitPackage.java:
--------------------------------------------------------------------------------
1 |
2 | package com.mlkit;
3 |
4 | import java.util.Arrays;
5 | import java.util.Collections;
6 | import java.util.List;
7 |
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.react.bridge.NativeModule;
10 | import com.facebook.react.bridge.ReactApplicationContext;
11 | import com.facebook.react.uimanager.ViewManager;
12 | import com.facebook.react.bridge.JavaScriptModule;
13 |
14 | public class RNMlKitPackage implements ReactPackage {
15 | @Override
16 | public List createNativeModules(ReactApplicationContext reactContext) {
17 | return Arrays.asList(new RNMlKitModule(reactContext));
18 | }
19 |
20 | // Deprecated from RN 0.47
21 | public List> createJSModules() {
22 | return Collections.emptyList();
23 | }
24 |
25 | @Override
26 | public List createViewManagers(ReactApplicationContext reactContext) {
27 | return Collections.emptyList();
28 | }
29 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/mlkit/Utils.java:
--------------------------------------------------------------------------------
1 | package com.mlkit;
2 |
3 | import com.facebook.react.bridge.Arguments;
4 | import com.facebook.react.bridge.WritableArray;
5 | import com.facebook.react.bridge.WritableMap;
6 | import com.google.firebase.ml.vision.common.FirebaseVisionPoint;
7 | import com.google.firebase.ml.vision.face.FirebaseVisionFace;
8 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceContour;
9 |
10 | import java.util.List;
11 |
12 | public class Utils {
13 | public static WritableArray getContourPointsWritableArray(FirebaseVisionFace face, int contourType){
14 | WritableArray data = Arguments.createArray();
15 | List points = face.getContour(contourType).getPoints();
16 | for (FirebaseVisionPoint point : points){
17 | WritableMap info = Arguments.createMap();
18 | info.putDouble("x", point.getX());
19 | info.putDouble("y", point.getY());
20 |
21 | data.pushMap(info);
22 | }
23 | return data;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 |
2 | import { NativeModules } from 'react-native';
3 |
4 | const { RNMlKit } = NativeModules;
5 |
6 | export default RNMlKit;
7 |
--------------------------------------------------------------------------------
/ios/RNMlKit.h:
--------------------------------------------------------------------------------
1 | #if __has_include()
2 | #import
3 | #else
4 | #import "RCTBridgeModule.h"
5 | #endif
6 |
7 | @interface RNMlKit : NSObject
8 |
9 | @end
--------------------------------------------------------------------------------
/ios/RNMlKit.m:
--------------------------------------------------------------------------------
1 |
2 | #import "RNMlKit.h"
3 |
4 | #import
5 |
6 | #import
7 | #import
8 |
9 | @implementation RNMlKit
10 |
11 | - (dispatch_queue_t)methodQueue
12 | {
13 | return dispatch_get_main_queue();
14 | }
15 | RCT_EXPORT_MODULE()
16 |
17 | static NSString *const detectionNoResultsMessage = @"Something went wrong";
18 |
19 |
20 | - (NSString *)barcodeFormat:(FIRVisionBarcodeFormat)format {
21 | switch (format) {
22 | case FIRVisionBarcodeFormatCode128:
23 | return @"CODE_128";
24 | case FIRVisionBarcodeFormatCode39:
25 | return @"CODE_39";
26 | case FIRVisionBarcodeFormatCode93:
27 | return @"CODE_93";
28 | case FIRVisionBarcodeFormatCodaBar:
29 | return @"CODABAR";
30 | case FIRVisionBarcodeFormatDataMatrix:
31 | return @"DATA_MATRIX";
32 | case FIRVisionBarcodeFormatEAN13:
33 | return @"EAN_13";
34 | case FIRVisionBarcodeFormatEAN8:
35 | return @"EAN_8";
36 | case FIRVisionBarcodeFormatITF:
37 | return @"ITF";
38 | case FIRVisionBarcodeFormatQRCode:
39 | return @"QR_CODE";
40 | case FIRVisionBarcodeFormatUPCA:
41 | return @"UPC_A";
42 | case FIRVisionBarcodeFormatUPCE:
43 | return @"UPC_E";
44 | case FIRVisionBarcodeFormatPDF417:
45 | return @"PDF417";
46 | case FIRVisionBarcodeFormatAztec:
47 | return @"AZTEC";
48 | default:
49 | return @"UNKNOWN";
50 | }
51 | }
52 |
53 |
54 |
55 | RCT_REMAP_METHOD(deviceBarcodeRecognition, deviceBarcodeRecognition:(NSString *)imagePath resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
56 | if (!imagePath) {
57 | resolve(@NO);
58 | return;
59 | }
60 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
61 | FIRVisionBarcodeDetectorOptions *options = [[FIRVisionBarcodeDetectorOptions alloc] initWithFormats: FIRVisionBarcodeFormatAll];
62 | FIRVision *vision = [FIRVision vision];
63 | FIRVisionBarcodeDetector *barcodeDetector = [vision barcodeDetectorWithOptions: options];
64 | NSDictionary *d = [[NSDictionary alloc] init];
65 | NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]];
66 | UIImage *image = [UIImage imageWithData:imageData];
67 |
68 | if (!image) {
69 | dispatch_async(dispatch_get_main_queue(), ^{
70 | resolve(@NO);
71 | });
72 | return;
73 | }
74 |
75 | FIRVisionImage *handler = [[FIRVisionImage alloc] initWithImage:image];
76 |
77 | [barcodeDetector detectInImage:handler completion:^(NSArray *barcodes, NSError *_Nullable error) {
78 | if (error != nil) {
79 | NSString *errorString = error ? error.localizedDescription : detectionNoResultsMessage;
80 | NSDictionary *pData = @{
81 | @"error": [NSMutableString stringWithFormat:@"On-Device text detection failed with error: %@", errorString],
82 | };
83 | // Running on background thread, don't call UIKit
84 | dispatch_async(dispatch_get_main_queue(), ^{
85 | resolve(pData);
86 | });
87 | return;
88 | }
89 |
90 | NSMutableArray *output = [NSMutableArray array];
91 | for (FIRVisionBarcode *barcode in barcodes) {
92 | NSMutableDictionary *result = [NSMutableDictionary dictionary];
93 | NSString *format = [self barcodeFormat: barcode.format];
94 |
95 | result[@"value"] = barcode.rawValue;
96 | result[@"format"] = format;
97 | [output addObject:result];
98 | }
99 |
100 | dispatch_async(dispatch_get_main_queue(), ^{
101 | resolve(output);
102 | });
103 | }];
104 | });
105 | }
106 |
107 | RCT_REMAP_METHOD(deviceTextRecognition, deviceTextRecognition:(NSString *)imagePath resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
108 | if (!imagePath) {
109 | resolve(@NO);
110 | return;
111 | }
112 |
113 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
114 | FIRVision *vision = [FIRVision vision];
115 | FIRVisionTextRecognizer *textRecognizer = [vision onDeviceTextRecognizer];
116 | NSDictionary *d = [[NSDictionary alloc] init];
117 | NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]];
118 | UIImage *image = [UIImage imageWithData:imageData];
119 |
120 | if (!image) {
121 | dispatch_async(dispatch_get_main_queue(), ^{
122 | resolve(@NO);
123 | });
124 | return;
125 | }
126 |
127 | FIRVisionImage *handler = [[FIRVisionImage alloc] initWithImage:image];
128 |
129 | [textRecognizer processImage:handler completion:^(FIRVisionText *_Nullable result, NSError *_Nullable error) {
130 | if (error != nil || result == nil) {
131 | NSString *errorString = error ? error.localizedDescription : detectionNoResultsMessage;
132 | NSDictionary *pData = @{
133 | @"error": [NSMutableString stringWithFormat:@"On-Device text detection failed with error: %@", errorString],
134 | };
135 | // Running on background thread, don't call UIKit
136 | dispatch_async(dispatch_get_main_queue(), ^{
137 | resolve(pData);
138 | });
139 | return;
140 | }
141 |
142 | CGRect boundingBox;
143 | CGSize size;
144 | CGPoint origin;
145 | NSMutableArray *output = [NSMutableArray array];
146 |
147 | for (FIRVisionTextBlock *block in result.blocks) {
148 | NSMutableDictionary *blocks = [NSMutableDictionary dictionary];
149 | NSMutableDictionary *bounding = [NSMutableDictionary dictionary];
150 | NSString *blockText = block.text;
151 |
152 | bounding[@"left"]=[NSString stringWithFormat: @"%f", block.cornerPoints[0].CGVectorValue.dx];
153 | bounding[@"top"]=[NSString stringWithFormat: @"%f", block.cornerPoints[0].CGVectorValue.dy];
154 |
155 | bounding[@"width"]=[NSString stringWithFormat: @"%f", block.cornerPoints[2].CGVectorValue.dx-block.cornerPoints[0].CGVectorValue.dx];
156 | bounding[@"height"]=[NSString stringWithFormat: @"%f", block.cornerPoints[2].CGVectorValue.dy - block.cornerPoints[0].CGVectorValue.dy];
157 |
158 | blocks[@"resultText"] = result.text;
159 | blocks[@"blockText"] = block.text;
160 | blocks[@"blockCoordinates"] = bounding;
161 |
162 | [output addObject:blocks];
163 |
164 | for (FIRVisionTextLine *line in block.lines) {
165 | NSMutableDictionary *lines = [NSMutableDictionary dictionary];
166 | lines[@"lineText"] = line.text;
167 | [output addObject:lines];
168 |
169 | for (FIRVisionTextElement *element in line.elements) {
170 | NSMutableDictionary *elements = [NSMutableDictionary dictionary];
171 | elements[@"elementText"] = element.text;
172 | [output addObject:elements];
173 |
174 | }
175 | }
176 | }
177 |
178 | dispatch_async(dispatch_get_main_queue(), ^{
179 | resolve(output);
180 | });
181 | }];
182 | });
183 |
184 | }
185 |
186 | @end
--------------------------------------------------------------------------------
/ios/RNMlKit.podspec:
--------------------------------------------------------------------------------
1 | package = JSON.parse(File.read(File.join(__dir__, '../package.json')))
2 |
3 | Pod::Spec.new do |s|
4 | s.name = "RNMlKit"
5 | s.version = package['version']
6 | s.summary = package['summary']
7 | s.description = package['description']
8 | s.license = package['license']
9 | s.author = package['author']
10 | s.homepage = package['homepage']
11 | s.platform = :ios, "7.0"
12 | s.source = { :git => "https://github.com/mateusc42/react-native-firebase-mlkit.git", :tag => "master" }
13 | s.source_files = "*.{h,m}"
14 | s.requires_arc = true
15 |
16 |
17 | s.dependency "React"
18 | s.dependency "Firebase"
19 | end
--------------------------------------------------------------------------------
/ios/RNMlKit.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | B3E7B58A1CC2AC0600A0062D /* RNMlKit.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNMlKit.m */; };
11 | /* End PBXBuildFile section */
12 |
13 | /* Begin PBXCopyFilesBuildPhase section */
14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = {
15 | isa = PBXCopyFilesBuildPhase;
16 | buildActionMask = 2147483647;
17 | dstPath = "include/$(PRODUCT_NAME)";
18 | dstSubfolderSpec = 16;
19 | files = (
20 | );
21 | runOnlyForDeploymentPostprocessing = 0;
22 | };
23 | /* End PBXCopyFilesBuildPhase section */
24 |
25 | /* Begin PBXFileReference section */
26 | 134814201AA4EA6300B7C361 /* libRNMlKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMlKit.a; sourceTree = BUILT_PRODUCTS_DIR; };
27 | B3E7B5881CC2AC0600A0062D /* RNMlKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNMlKit.h; sourceTree = ""; };
28 | B3E7B5891CC2AC0600A0062D /* RNMlKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNMlKit.m; sourceTree = ""; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | 58B511D81A9E6C8500147676 /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | );
37 | runOnlyForDeploymentPostprocessing = 0;
38 | };
39 | /* End PBXFrameworksBuildPhase section */
40 |
41 | /* Begin PBXGroup section */
42 | 134814211AA4EA7D00B7C361 /* Products */ = {
43 | isa = PBXGroup;
44 | children = (
45 | 134814201AA4EA6300B7C361 /* libRNMlKit.a */,
46 | );
47 | name = Products;
48 | sourceTree = "";
49 | };
50 | 58B511D21A9E6C8500147676 = {
51 | isa = PBXGroup;
52 | children = (
53 | B3E7B5881CC2AC0600A0062D /* RNMlKit.h */,
54 | B3E7B5891CC2AC0600A0062D /* RNMlKit.m */,
55 | 134814211AA4EA7D00B7C361 /* Products */,
56 | );
57 | sourceTree = "";
58 | };
59 | /* End PBXGroup section */
60 |
61 | /* Begin PBXNativeTarget section */
62 | 58B511DA1A9E6C8500147676 /* RNMlKit */ = {
63 | isa = PBXNativeTarget;
64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNMlKit" */;
65 | buildPhases = (
66 | 58B511D71A9E6C8500147676 /* Sources */,
67 | 58B511D81A9E6C8500147676 /* Frameworks */,
68 | 58B511D91A9E6C8500147676 /* CopyFiles */,
69 | );
70 | buildRules = (
71 | );
72 | dependencies = (
73 | );
74 | name = RNMlKit;
75 | productName = RCTDataManager;
76 | productReference = 134814201AA4EA6300B7C361 /* libRNMlKit.a */;
77 | productType = "com.apple.product-type.library.static";
78 | };
79 | /* End PBXNativeTarget section */
80 |
81 | /* Begin PBXProject section */
82 | 58B511D31A9E6C8500147676 /* Project object */ = {
83 | isa = PBXProject;
84 | attributes = {
85 | LastUpgradeCheck = 0830;
86 | ORGANIZATIONNAME = Facebook;
87 | TargetAttributes = {
88 | 58B511DA1A9E6C8500147676 = {
89 | CreatedOnToolsVersion = 6.1.1;
90 | };
91 | };
92 | };
93 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNMlKit" */;
94 | compatibilityVersion = "Xcode 3.2";
95 | developmentRegion = English;
96 | hasScannedForEncodings = 0;
97 | knownRegions = (
98 | en,
99 | );
100 | mainGroup = 58B511D21A9E6C8500147676;
101 | productRefGroup = 58B511D21A9E6C8500147676;
102 | projectDirPath = "";
103 | projectRoot = "";
104 | targets = (
105 | 58B511DA1A9E6C8500147676 /* RNMlKit */,
106 | );
107 | };
108 | /* End PBXProject section */
109 |
110 | /* Begin PBXSourcesBuildPhase section */
111 | 58B511D71A9E6C8500147676 /* Sources */ = {
112 | isa = PBXSourcesBuildPhase;
113 | buildActionMask = 2147483647;
114 | files = (
115 | B3E7B58A1CC2AC0600A0062D /* RNMlKit.m in Sources */,
116 | );
117 | runOnlyForDeploymentPostprocessing = 0;
118 | };
119 | /* End PBXSourcesBuildPhase section */
120 |
121 | /* Begin XCBuildConfiguration section */
122 | 58B511ED1A9E6C8500147676 /* Debug */ = {
123 | isa = XCBuildConfiguration;
124 | buildSettings = {
125 | ALWAYS_SEARCH_USER_PATHS = NO;
126 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
127 | CLANG_CXX_LIBRARY = "libc++";
128 | CLANG_ENABLE_MODULES = YES;
129 | CLANG_ENABLE_OBJC_ARC = YES;
130 | CLANG_WARN_BOOL_CONVERSION = YES;
131 | CLANG_WARN_CONSTANT_CONVERSION = YES;
132 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
133 | CLANG_WARN_EMPTY_BODY = YES;
134 | CLANG_WARN_ENUM_CONVERSION = YES;
135 | CLANG_WARN_INFINITE_RECURSION = YES;
136 | CLANG_WARN_INT_CONVERSION = YES;
137 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
138 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
139 | CLANG_WARN_UNREACHABLE_CODE = YES;
140 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
141 | COPY_PHASE_STRIP = NO;
142 | ENABLE_STRICT_OBJC_MSGSEND = YES;
143 | ENABLE_TESTABILITY = YES;
144 | GCC_C_LANGUAGE_STANDARD = gnu99;
145 | GCC_DYNAMIC_NO_PIC = NO;
146 | GCC_NO_COMMON_BLOCKS = YES;
147 | GCC_OPTIMIZATION_LEVEL = 0;
148 | GCC_PREPROCESSOR_DEFINITIONS = (
149 | "DEBUG=1",
150 | "$(inherited)",
151 | );
152 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
153 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
154 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
155 | GCC_WARN_UNDECLARED_SELECTOR = YES;
156 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
157 | GCC_WARN_UNUSED_FUNCTION = YES;
158 | GCC_WARN_UNUSED_VARIABLE = YES;
159 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
160 | MTL_ENABLE_DEBUG_INFO = YES;
161 | ONLY_ACTIVE_ARCH = YES;
162 | SDKROOT = iphoneos;
163 | };
164 | name = Debug;
165 | };
166 | 58B511EE1A9E6C8500147676 /* Release */ = {
167 | isa = XCBuildConfiguration;
168 | buildSettings = {
169 | ALWAYS_SEARCH_USER_PATHS = NO;
170 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
171 | CLANG_CXX_LIBRARY = "libc++";
172 | CLANG_ENABLE_MODULES = YES;
173 | CLANG_ENABLE_OBJC_ARC = YES;
174 | CLANG_WARN_BOOL_CONVERSION = YES;
175 | CLANG_WARN_CONSTANT_CONVERSION = YES;
176 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
177 | CLANG_WARN_EMPTY_BODY = YES;
178 | CLANG_WARN_ENUM_CONVERSION = YES;
179 | CLANG_WARN_INFINITE_RECURSION = YES;
180 | CLANG_WARN_INT_CONVERSION = YES;
181 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
182 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
183 | CLANG_WARN_UNREACHABLE_CODE = YES;
184 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
185 | COPY_PHASE_STRIP = YES;
186 | ENABLE_NS_ASSERTIONS = NO;
187 | ENABLE_STRICT_OBJC_MSGSEND = YES;
188 | GCC_C_LANGUAGE_STANDARD = gnu99;
189 | GCC_NO_COMMON_BLOCKS = YES;
190 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
191 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
192 | GCC_WARN_UNDECLARED_SELECTOR = YES;
193 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
194 | GCC_WARN_UNUSED_FUNCTION = YES;
195 | GCC_WARN_UNUSED_VARIABLE = YES;
196 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
197 | MTL_ENABLE_DEBUG_INFO = NO;
198 | SDKROOT = iphoneos;
199 | VALIDATE_PRODUCT = YES;
200 | };
201 | name = Release;
202 | };
203 | 58B511F01A9E6C8500147676 /* Debug */ = {
204 | isa = XCBuildConfiguration;
205 | buildSettings = {
206 | HEADER_SEARCH_PATHS = (
207 | "$(inherited)",
208 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
209 | "$(SRCROOT)/../../../React/**",
210 | "$(SRCROOT)/../../react-native/React/**",
211 | "$(PROJECT_DIR)/../../../ios/Frameworks/**",
212 | "$(PROJECT_DIR)/../../../ios/Pods/Firebase/**",
213 | "$(PROJECT_DIR)/../../../ios/Pods/Headers/Public/**",
214 | "$(PROJECT_DIR)/../../../ios/**",
215 | );
216 | LIBRARY_SEARCH_PATHS = (
217 | "$(inherited)",
218 | "$(PROJECT_DIR)/../../../ios/**",
219 | );
220 | OTHER_LDFLAGS = "-ObjC";
221 | PRODUCT_NAME = RNMlKit;
222 | SKIP_INSTALL = YES;
223 | };
224 | name = Debug;
225 | };
226 | 58B511F11A9E6C8500147676 /* Release */ = {
227 | isa = XCBuildConfiguration;
228 | buildSettings = {
229 | HEADER_SEARCH_PATHS = (
230 | "$(inherited)",
231 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
232 | "$(SRCROOT)/../../../React/**",
233 | "$(SRCROOT)/../../react-native/React/**",
234 | "$(PROJECT_DIR)/../../../ios/Frameworks/**",
235 | "$(PROJECT_DIR)/../../../ios/Pods/Firebase/**",
236 | "$(PROJECT_DIR)/../../../ios/Pods/Headers/Public/**",
237 | "$(PROJECT_DIR)/../../../ios/**",
238 | );
239 | LIBRARY_SEARCH_PATHS = (
240 | "$(inherited)",
241 | "$(PROJECT_DIR)/../../../ios/**",
242 | );
243 | OTHER_LDFLAGS = "-ObjC";
244 | PRODUCT_NAME = RNMlKit;
245 | SKIP_INSTALL = YES;
246 | };
247 | name = Release;
248 | };
249 | /* End XCBuildConfiguration section */
250 |
251 | /* Begin XCConfigurationList section */
252 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNMlKit" */ = {
253 | isa = XCConfigurationList;
254 | buildConfigurations = (
255 | 58B511ED1A9E6C8500147676 /* Debug */,
256 | 58B511EE1A9E6C8500147676 /* Release */,
257 | );
258 | defaultConfigurationIsVisible = 0;
259 | defaultConfigurationName = Release;
260 | };
261 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNMlKit" */ = {
262 | isa = XCConfigurationList;
263 | buildConfigurations = (
264 | 58B511F01A9E6C8500147676 /* Debug */,
265 | 58B511F11A9E6C8500147676 /* Release */,
266 | );
267 | defaultConfigurationIsVisible = 0;
268 | defaultConfigurationName = Release;
269 | };
270 | /* End XCConfigurationList section */
271 | };
272 | rootObject = 58B511D31A9E6C8500147676 /* Project object */;
273 | }
274 |
--------------------------------------------------------------------------------
/ios/RNMlKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/RNMlKit.xcodeproj/project.xcworkspace/xcuserdata/trackingtrade.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mateuscardosogs/react-native-firebase-mlkit/6530579cd393bb53765fd5120612e8236fb4fbb0/ios/RNMlKit.xcodeproj/project.xcworkspace/xcuserdata/trackingtrade.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/ios/RNMlKit.xcodeproj/xcuserdata/trackingtrade.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | RNMlKit.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ios/RNMlKit.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 |
3 |
5 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-ml-kit-ocr",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1
5 | }
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-firebase-mlkit",
3 | "version": "0.6.2",
4 | "description": "Text Recognition in image for react native using firebase ML Kit",
5 | "homepage": "https://github.com/mateusc42/react-native-firebase-mlkit",
6 | "main": "index.js",
7 | "scripts": {
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [
11 | "react-native"
12 | ],
13 | "author": "Mateus Cardoso",
14 | "license": "MIT",
15 | "peerDependencies": {
16 | "react-native": "^0.55.3"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------