feat(mlkit): Migrate Face, Barcode and Text Recognition to Firebase MLKit (iOS - text, Android - all) (#2075)

* switch to firebase mlkit for text recognition

* migrate android to MLKit

migrate Text detection android to MLKit
update gradle of example app
Update build.gradle
separate gms vision facedetector to general flavor

migrate faceDetector to mlkit and fix incorrect bounds due to padding

migrate barCode detector to mlkit
update android instructions in readme
safe face implementation move gms to generalImplementation

* add mlkit example

setup android of mlkit example

setup ios of mlkit example
fix typo in readme
update example project readme

* amend mlkit migration to include raw data

add barcode detection in basic and mlkit examples

* fix duplicate bridgeDidBackground method

BREAKING CHANGE: We migrated to MLKit instead of Google Mobile Vision
This commit is contained in:
Daniil Ovoshchnikov 2019-03-11 12:56:24 +01:00 committed by Sibelius Seraphini
parent 1a89d7981a
commit 0ab570a636
115 changed files with 14514 additions and 1348 deletions

5
.gitignore vendored
View File

@ -45,4 +45,7 @@ android/keystores/debug.keystore
package-json.lock
# vscode
.vscode
.vscode
examples/mlkit/android/app/google-services.json
examples/mlkit/ios/Pods
examples/mlkit/ios/mlkit/GoogleService-Info.plist

190
README.md
View File

@ -256,7 +256,31 @@ pod 'react-native-camera', path: '../node_modules/react-native-camera', subspecs
'TextDetector'
]
```
*Note:* Text recognition is available only via CocoaPods Path. If you have issues with duplicate symbols you will need to enable dead code stripping option in your Xcode (Target > Build Settings > search for "Dead code stripping") see: https://github.com/firebase/quickstart-ios/issues/487#issuecomment-415313053.
###### Additional steps for Text Recognition
Text recognition for iOS uses Firebase MLKit which requires setting up Firebase project for your app.
If you have not already added Firebase to your app, please follow the steps described in [getting started guide](https://firebase.google.com/docs/ios/setup).
In short, you would need to
1. Register your app in Firebase console.
2. Download `GoogleService-Info.plist` and add it to your project
3. Add `pod 'Firebase/Core'` to your podfile
4. In your `AppDelegate.m` file add the following lines:
```objective-c
#import <Firebase.h> // <--- add this
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure]; // <--- add this
...
}
```
Add pods `Firebase/MLVision` and `Firebase/MLVisionTextModel`
*Note:* Text recognition is currently available only via CocoaPods Path.
- If you have issues with duplicate symbols you will need to enable dead code stripping option in your Xcode (Target > Build Settings > search for "Dead code stripping") [see here](https://github.com/firebase/quickstart-ios/issues/487#issuecomment-415313053).
- If you are using `pod Firebase/Core` with a version set below 5.13 you might want to add `pod 'GoogleAppMeasurement', '~> 5.3.0'` to your podfile
###### Non-CocoaPods Path
1. Download:
@ -291,23 +315,42 @@ Google Symbol Utilities: https://www.gstatic.com/cpdc/dbffca986f6337f8-GoogleSym
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
```
4. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
4. Insert the following lines in `android/app/build.gradle`:
inside the dependencies block:
```gradle
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
compile 'com.android.support:exifinterface:25.+'
compile ('com.google.android.gms:play-services-vision:12.0.1') {
force = true
}
}
implementation project(':react-native-camera')
```
> You may need to use different exifinterface versions, e.g. `27.+` instead of `25.+`.
inside defaultConfig block insert either:
```gradle
android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
}
}
```
or, if using MLKit for text/face/barcode recognition:
```gradle
android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'mlkit' <-- insert this line
}
}
```
5. Declare the permissions in your Android Manifest (required for `video recording` feature)
```java
```xml
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@ -323,6 +366,38 @@ allprojects {
}
```
7. Additional steps for using MLKit for text/face/barcode recognition
7.1. Using Firebase MLKit requires seting up Firebase project for your app. If you have not already added Firebase to your app, please follow the steps described in [getting started guide](https://firebase.google.com/docs/android/setup).
In short, you would need to
- Register your app in Firebase console.
- Download google-services.json and place it in `android/app/`
- add the folowing to project level build.gradle:
```gradle
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:4.0.1' <-- you might want to use different version
}
}
```
- add to the bottom of `android/app/build.gradle` file
```gradle
apply plugin: com.google.gms.google-services'
```
7.2. Configure your app to automatically download the ML model to the device after your app is installed from the Play Store. If you do not enable install-time model downloads, the model will be downloaded the first time you run the on-device detector. Requests you make before the download has completed will produce no results.
```xml
<application ...>
...
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr" />
<!-- To use multiple models, list all needed models: android:value="ocr, face, barcode" -->
</application>
```
The current Android library defaults to the below values for the Google SDK and Libraries,
```gradle
@ -359,45 +434,88 @@ The above settings in the ReactNative project over-rides the values present in t
module. For your reference below is the `android/build.gradle` file of the module.
```gradle
buildscript {
...
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
def DEFAULT_COMPILE_SDK_VERSION = 26
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.2"
def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "12.0.1"
def DEFAULT_SUPPORT_LIBRARY_VERSION = "27.1.0"
buildscript {
repositories {
google()
maven {
url 'https://maven.google.com'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
compileSdkVersion safeExtGet('compileSdkVersion', 26)
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.2')
defaultConfig {
minSdkVersion 16
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
versionCode 1
versionName "1.0.0"
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
}
flavorDimensions "react-native-camera"
productFlavors {
general {
dimension "react-native-camera"
}
mlkit {
dimension "react-native-camera"
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
general {
java.srcDirs = ['src/general/java']
}
mlkit {
java.srcDirs = ['src/mlkit/java']
}
}
lintOptions {
abortOnError false
warning 'InvalidPackage'
}
}
...
repositories {
google()
mavenCentral()
maven {
url 'https://maven.google.com'
}
maven { url "https://jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
dependencies {
def googlePlayServicesVersion = rootProject.hasProperty('googlePlayServicesVersion') ? rootProject.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
def supportLibVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIBRARY_VERSION
compile 'com.facebook.react:react-native:+'
compile "com.google.zxing:core:3.2.1"
compile "com.drewnoakes:metadata-extractor:2.9.1"
compile 'com.google.android.gms:play-services-vision:$googlePlayServicesVersion'
compile 'com.android.support:exifinterface:$supportLibVersion'
compile 'com.github.react-native-community:cameraview:cc47bb28ed2fc54a8c56a4ce9ce53edd1f0af3a5'
compileOnly 'com.facebook.react:react-native:+'
compileOnly 'com.facebook.infer.annotation:infer-annotation:+'
implementation "com.google.zxing:core:3.3.0"
implementation "com.drewnoakes:metadata-extractor:2.9.1"
generalImplementation "com.google.android.gms:play-services-vision:${safeExtGet('google-services', '17.0.2')}"
implementation "com.android.support:exifinterface:${safeExtGet('supportLibVersion', '27.1.0')}"
implementation "com.android.support:support-annotations:${safeExtGet('supportLibVersion', '27.1.0')}"
implementation "com.android.support:support-v4:${safeExtGet('supportLibVersion', '27.1.0')}"
mlkitImplementation "com.google.firebase:firebase-ml-vision:${safeExtGet('firebase-ml-vision', '18.0.2')}"
mlkitImplementation "com.google.firebase:firebase-ml-vision-face-model:17.0.2"
}
```

View File

@ -26,6 +26,30 @@ android {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
}
flavorDimensions "react-native-camera"
productFlavors {
general {
dimension "react-native-camera"
}
mlkit {
dimension "react-native-camera"
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
general {
java.srcDirs = ['src/general/java']
}
mlkit {
java.srcDirs = ['src/mlkit/java']
}
}
lintOptions {
abortOnError false
warning 'InvalidPackage'
@ -46,14 +70,16 @@ repositories {
}
dependencies {
def googlePlayServicesVisionVersion = safeExtGet('googlePlayServicesVisionVersion', safeExtGet('googlePlayServicesVersion', '15.0.2'))
def googlePlayServicesVisionVersion = safeExtGet('googlePlayServicesVisionVersion', safeExtGet('googlePlayServicesVersion', '17.0.2'))
compileOnly 'com.facebook.react:react-native:+'
compileOnly 'com.facebook.infer.annotation:infer-annotation:+'
implementation "com.google.zxing:core:3.3.0"
implementation "com.drewnoakes:metadata-extractor:2.9.1"
implementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
generalImplementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
implementation "com.android.support:exifinterface:${safeExtGet('supportLibVersion', '27.1.0')}"
implementation "com.android.support:support-annotations:${safeExtGet('supportLibVersion', '27.1.0')}"
implementation "com.android.support:support-v4:${safeExtGet('supportLibVersion', '27.1.0')}"
mlkitImplementation "com.google.firebase:firebase-ml-vision:${safeExtGet('firebase-ml-vision', '18.0.2')}"
mlkitImplementation "com.google.firebase:firebase-ml-vision-face-model:${safeExtGet('firebase-ml-vision-face-model', '17.0.2')}"
}

View File

@ -0,0 +1,128 @@
package org.reactnative.camera.tasks;
import android.graphics.Rect;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.android.gms.vision.barcode.Barcode;
import org.reactnative.barcodedetector.BarcodeFormatUtils;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.frame.RNFrame;
import org.reactnative.frame.RNFrameFactory;
import org.reactnative.barcodedetector.RNBarcodeDetector;
public class BarcodeDetectorAsyncTask extends android.os.AsyncTask<Void, Void, SparseArray<Barcode>> {
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private RNBarcodeDetector mBarcodeDetector;
private BarcodeDetectorAsyncTaskDelegate mDelegate;
private double mScaleX;
private double mScaleY;
private ImageDimensions mImageDimensions;
private int mPaddingLeft;
private int mPaddingTop;
public BarcodeDetectorAsyncTask(
BarcodeDetectorAsyncTaskDelegate delegate,
RNBarcodeDetector barcodeDetector,
byte[] imageData,
int width,
int height,
int rotation,
float density,
int facing,
int viewWidth,
int viewHeight,
int viewPaddingLeft,
int viewPaddingTop
) {
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mDelegate = delegate;
mBarcodeDetector = barcodeDetector;
mImageDimensions = new ImageDimensions(width, height, rotation, facing);
mScaleX = (double) (viewWidth) / (mImageDimensions.getWidth() * density);
mScaleY = (double) (viewHeight) / (mImageDimensions.getHeight() * density);
mPaddingLeft = viewPaddingLeft;
mPaddingTop = viewPaddingTop;
}
@Override
protected SparseArray<Barcode> doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mBarcodeDetector == null || !mBarcodeDetector.isOperational()) {
return null;
}
RNFrame frame = RNFrameFactory.buildFrame(mImageData, mWidth, mHeight, mRotation);
return mBarcodeDetector.detect(frame);
}
@Override
protected void onPostExecute(SparseArray<Barcode> barcodes) {
super.onPostExecute(barcodes);
if (barcodes == null) {
mDelegate.onBarcodeDetectionError(mBarcodeDetector);
} else {
if (barcodes.size() > 0) {
mDelegate.onBarcodesDetected(serializeEventData(barcodes));
}
mDelegate.onBarcodeDetectingTaskCompleted();
}
}
private WritableArray serializeEventData(SparseArray<Barcode> barcodes) {
WritableArray barcodesList = Arguments.createArray();
for (int i = 0; i < barcodes.size(); i++) {
Barcode barcode = barcodes.valueAt(i);
WritableMap serializedBarcode = Arguments.createMap();
serializedBarcode.putString("data", barcode.displayValue);
serializedBarcode.putString("rawData", barcode.rawValue);
serializedBarcode.putString("type", BarcodeFormatUtils.get(barcode.format));
serializedBarcode.putMap("bounds", processBounds(barcode.getBoundingBox()));
barcodesList.pushMap(serializedBarcode);
}
return barcodesList;
}
private WritableMap processBounds(Rect frame) {
WritableMap origin = Arguments.createMap();
int x = frame.left;
int y = frame.top;
if (frame.left < mWidth / 2) {
x = x + mPaddingLeft / 2;
} else if (frame.left > mWidth /2) {
x = x - mPaddingLeft / 2;
}
if (frame.top < mHeight / 2) {
y = y + mPaddingTop / 2;
} else if (frame.top > mHeight / 2) {
y = y - mPaddingTop / 2;
}
origin.putDouble("x", x * mScaleX);
origin.putDouble("y", y * mScaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", frame.width() * mScaleX);
size.putDouble("height", frame.height() * mScaleY);
WritableMap bounds = Arguments.createMap();
bounds.putMap("origin", origin);
bounds.putMap("size", size);
return bounds;
}
}

View File

@ -0,0 +1,97 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.vision.face.Face;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.facedetector.FaceDetectorUtils;
import org.reactnative.frame.RNFrame;
import org.reactnative.frame.RNFrameFactory;
import org.reactnative.facedetector.RNFaceDetector;
public class FaceDetectorAsyncTask extends android.os.AsyncTask<Void, Void, SparseArray<Face>> {
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private RNFaceDetector mFaceDetector;
private FaceDetectorAsyncTaskDelegate mDelegate;
private ImageDimensions mImageDimensions;
private double mScaleX;
private double mScaleY;
private int mPaddingLeft;
private int mPaddingTop;
public FaceDetectorAsyncTask(
FaceDetectorAsyncTaskDelegate delegate,
RNFaceDetector faceDetector,
byte[] imageData,
int width,
int height,
int rotation,
float density,
int facing,
int viewWidth,
int viewHeight,
int viewPaddingLeft,
int viewPaddingTop
) {
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mDelegate = delegate;
mFaceDetector = faceDetector;
mImageDimensions = new ImageDimensions(width, height, rotation, facing);
mScaleX = (double) (viewWidth) / (mImageDimensions.getWidth() * density);
mScaleY = (double) (viewHeight) / (mImageDimensions.getHeight() * density);
mPaddingLeft = viewPaddingLeft;
mPaddingTop = viewPaddingTop;
}
@Override
protected SparseArray<Face> doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mFaceDetector == null || !mFaceDetector.isOperational()) {
return null;
}
RNFrame frame = RNFrameFactory.buildFrame(mImageData, mWidth, mHeight, mRotation);
return mFaceDetector.detect(frame);
}
@Override
protected void onPostExecute(SparseArray<Face> faces) {
super.onPostExecute(faces);
if (faces == null) {
mDelegate.onFaceDetectionError(mFaceDetector);
} else {
if (faces.size() > 0) {
mDelegate.onFacesDetected(serializeEventData(faces));
}
mDelegate.onFaceDetectingTaskCompleted();
}
}
private WritableArray serializeEventData(SparseArray<Face> faces) {
WritableArray facesList = Arguments.createArray();
for(int i = 0; i < faces.size(); i++) {
Face face = faces.valueAt(i);
WritableMap serializedFace = FaceDetectorUtils.serializeFace(face, mScaleX, mScaleY, mWidth, mHeight, mPaddingLeft, mPaddingTop);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedFace = FaceDetectorUtils.rotateFaceX(serializedFace, mImageDimensions.getWidth(), mScaleX);
} else {
serializedFace = FaceDetectorUtils.changeAnglesDirection(serializedFace);
}
facesList.pushMap(serializedFace);
}
return facesList;
}
}

View File

@ -0,0 +1,178 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.vision.text.Line;
import com.google.android.gms.vision.text.Text;
import com.google.android.gms.vision.text.TextBlock;
import com.google.android.gms.vision.text.TextRecognizer;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.facedetector.FaceDetectorUtils;
import org.reactnative.frame.RNFrame;
import org.reactnative.frame.RNFrameFactory;
public class TextRecognizerAsyncTask extends android.os.AsyncTask<Void, Void, SparseArray<TextBlock>> {
private TextRecognizerAsyncTaskDelegate mDelegate;
private ThemedReactContext mThemedReactContext;
private TextRecognizer mTextRecognizer;
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private ImageDimensions mImageDimensions;
private double mScaleX;
private double mScaleY;
private int mPaddingLeft;
private int mPaddingTop;
public TextRecognizerAsyncTask(
TextRecognizerAsyncTaskDelegate delegate,
ThemedReactContext themedReactContext,
byte[] imageData,
int width,
int height,
int rotation,
float density,
int facing,
int viewWidth,
int viewHeight,
int viewPaddingLeft,
int viewPaddingTop
) {
mDelegate = delegate;
mThemedReactContext = themedReactContext;
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mImageDimensions = new ImageDimensions(width, height, rotation, facing);
mScaleX = (double) (viewWidth) / (mImageDimensions.getWidth() * density);
mScaleY = (double) (viewHeight) / (mImageDimensions.getHeight() * density);
mPaddingLeft = viewPaddingLeft;
mPaddingTop = viewPaddingTop;
}
@Override
protected SparseArray<TextBlock> doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null) {
return null;
}
mTextRecognizer = new TextRecognizer.Builder(mThemedReactContext).build();
RNFrame frame = RNFrameFactory.buildFrame(mImageData, mWidth, mHeight, mRotation);
return mTextRecognizer.detect(frame.getFrame());
}
@Override
protected void onPostExecute(SparseArray<TextBlock> textBlocks) {
super.onPostExecute(textBlocks);
if (mTextRecognizer != null) {
mTextRecognizer.release();
}
if (textBlocks != null) {
WritableArray textBlocksList = Arguments.createArray();
for (int i = 0; i < textBlocks.size(); ++i) {
TextBlock textBlock = textBlocks.valueAt(i);
WritableMap serializedTextBlock = serializeText(textBlock);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedTextBlock = rotateTextX(serializedTextBlock);
}
textBlocksList.pushMap(serializedTextBlock);
}
mDelegate.onTextRecognized(textBlocksList);
}
mDelegate.onTextRecognizerTaskCompleted();
}
private WritableMap serializeText(Text text) {
WritableMap encodedText = Arguments.createMap();
WritableArray components = Arguments.createArray();
for (Text component : text.getComponents()) {
components.pushMap(serializeText(component));
}
encodedText.putArray("components", components);
encodedText.putString("value", text.getValue());
int x = text.getBoundingBox().left;
int y = text.getBoundingBox().top;
if (text.getBoundingBox().left < mWidth / 2) {
x = x + mPaddingLeft / 2;
} else if (text.getBoundingBox().left > mWidth /2) {
x = x - mPaddingLeft / 2;
}
if (text.getBoundingBox().height() < mHeight / 2) {
y = y + mPaddingTop / 2;
} else if (text.getBoundingBox().height() > mHeight / 2) {
y = y - mPaddingTop / 2;
}
WritableMap origin = Arguments.createMap();
origin.putDouble("x", x * this.mScaleX);
origin.putDouble("y", y * this.mScaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", text.getBoundingBox().width() * this.mScaleX);
size.putDouble("height", text.getBoundingBox().height() * this.mScaleY);
WritableMap bounds = Arguments.createMap();
bounds.putMap("origin", origin);
bounds.putMap("size", size);
encodedText.putMap("bounds", bounds);
String type_;
if (text instanceof TextBlock) {
type_ = "block";
} else if (text instanceof Line) {
type_ = "line";
} else /*if (text instanceof Element)*/ {
type_ = "element";
}
encodedText.putString("type", type_);
return encodedText;
}
private WritableMap rotateTextX(WritableMap text) {
ReadableMap faceBounds = text.getMap("bounds");
ReadableMap oldOrigin = faceBounds.getMap("origin");
WritableMap mirroredOrigin = FaceDetectorUtils.positionMirroredHorizontally(
oldOrigin, mImageDimensions.getWidth(), mScaleX);
double translateX = -faceBounds.getMap("size").getDouble("width");
WritableMap translatedMirroredOrigin = FaceDetectorUtils.positionTranslatedHorizontally(mirroredOrigin, translateX);
WritableMap newBounds = Arguments.createMap();
newBounds.merge(faceBounds);
newBounds.putMap("origin", translatedMirroredOrigin);
text.putMap("bounds", newBounds);
ReadableArray oldComponents = text.getArray("components");
WritableArray newComponents = Arguments.createArray();
for (int i = 0; i < oldComponents.size(); ++i) {
WritableMap component = Arguments.createMap();
component.merge(oldComponents.getMap(i));
rotateTextX(component);
newComponents.pushMap(component);
}
text.putArray("components", newComponents);
return text;
}
}

View File

@ -18,10 +18,10 @@ public class FaceDetectorUtils {
};
public static WritableMap serializeFace(Face face) {
return serializeFace(face, 1, 1);
return serializeFace(face, 1, 1, 0, 0, 0, 0);
}
public static WritableMap serializeFace(Face face, double scaleX, double scaleY) {
public static WritableMap serializeFace(Face face, double scaleX, double scaleY, int width, int height, int paddingLeft, int paddingTop) {
WritableMap encodedFace = Arguments.createMap();
encodedFace.putInt("faceID", face.getId());
@ -39,12 +39,25 @@ public class FaceDetectorUtils {
}
for(Landmark landmark : face.getLandmarks()) {
encodedFace.putMap(landmarkNames[landmark.getType()], mapFromPoint(landmark.getPosition(), scaleX, scaleY));
encodedFace.putMap(landmarkNames[landmark.getType()], mapFromPoint(landmark.getPosition(), scaleX, scaleY, width, height, paddingLeft, paddingTop));
}
WritableMap origin = Arguments.createMap();
origin.putDouble("x", face.getPosition().x * scaleX);
origin.putDouble("y", face.getPosition().y * scaleY);
Float x = face.getPosition().x;
Float y = face.getPosition().y;
if (face.getPosition().x < width / 2) {
x = x + paddingLeft / 2;
} else if (face.getPosition().x > width / 2) {
x = x - paddingLeft / 2;
}
if (face.getPosition().y < height / 2) {
y = y + paddingTop / 2;
} else if (face.getPosition().y > height / 2) {
y = y - paddingTop / 2;
}
origin.putDouble("x", x * scaleX);
origin.putDouble("y", y * scaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", face.getWidth() * scaleX);
@ -91,8 +104,21 @@ public class FaceDetectorUtils {
return face;
}
public static WritableMap mapFromPoint(PointF point, double scaleX, double scaleY) {
public static WritableMap mapFromPoint(PointF point, double scaleX, double scaleY, int width, int height, int paddingLeft, int paddingTop) {
WritableMap map = Arguments.createMap();
Float x = point.x;
Float y = point.y;
if (point.x < width / 2) {
x = (x + paddingLeft / 2);
} else if (point.x > width / 2) {
x = (x - paddingLeft / 2);
}
if (point.y < height / 2) {
y = (y + paddingTop / 2);
} else if (point.y > height / 2) {
y = (y - paddingTop / 2);
}
map.putDouble("x", point.x * scaleX);
map.putDouble("y", point.y * scaleY);
return map;

View File

@ -8,23 +8,18 @@ import android.media.CamcorderProfile;
import android.media.MediaActionSound;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.SparseArray;
import android.view.View;
import android.os.AsyncTask;
import com.facebook.react.bridge.*;
import com.facebook.react.uimanager.ThemedReactContext;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.text.TextBlock;
import com.google.android.gms.vision.text.TextRecognizer;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import org.reactnative.barcodedetector.RNBarcodeDetector;
import org.reactnative.camera.tasks.*;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.camera.utils.RNFileUtils;
import org.reactnative.facedetector.RNFaceDetector;
@ -60,7 +55,6 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
private MultiFormatReader mMultiFormatReader;
private RNFaceDetector mFaceDetector;
private RNBarcodeDetector mGoogleBarcodeDetector;
private TextRecognizer mTextRecognizer;
private boolean mShouldDetectFaces = false;
private boolean mShouldGoogleDetectBarcodes = false;
private boolean mShouldScanBarCodes = false;
@ -70,6 +64,8 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
private int mFaceDetectionClassifications = RNFaceDetector.NO_CLASSIFICATIONS;
private int mGoogleVisionBarCodeType = Barcode.ALL_FORMATS;
private int mGoogleVisionBarCodeMode = RNBarcodeDetector.NORMAL_MODE;
private int mPaddingX;
private int mPaddingY;
public RNCameraView(ThemedReactContext themedReactContext) {
super(themedReactContext, true);
@ -148,7 +144,7 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
if (willCallFaceTask) {
faceDetectorTaskLock = true;
FaceDetectorAsyncTaskDelegate delegate = (FaceDetectorAsyncTaskDelegate) cameraView;
new FaceDetectorAsyncTask(delegate, mFaceDetector, data, width, height, correctRotation).execute();
new FaceDetectorAsyncTask(delegate, mFaceDetector, data, width, height, correctRotation, getResources().getDisplayMetrics().density, getFacing(), getWidth(), getHeight(), mPaddingX, mPaddingY).execute();
}
if (willCallGoogleBarcodeTask) {
@ -166,13 +162,13 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
}
}
BarcodeDetectorAsyncTaskDelegate delegate = (BarcodeDetectorAsyncTaskDelegate) cameraView;
new BarcodeDetectorAsyncTask(delegate, mGoogleBarcodeDetector, data, width, height, correctRotation).execute();
new BarcodeDetectorAsyncTask(delegate, mGoogleBarcodeDetector, data, width, height, correctRotation, getResources().getDisplayMetrics().density, getFacing(), getWidth(), getHeight(), mPaddingX, mPaddingY).execute();
}
if (willCallTextTask) {
textRecognizerTaskLock = true;
TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate) cameraView;
new TextRecognizerAsyncTask(delegate, mTextRecognizer, data, width, height, correctRotation).execute();
new TextRecognizerAsyncTask(delegate, mThemedReactContext, data, width, height, correctRotation, getResources().getDisplayMetrics().density, getFacing(), getWidth(), getHeight(), mPaddingX, mPaddingY).execute();
}
}
});
@ -210,6 +206,8 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
}
int paddingX = (int) ((width - correctWidth) / 2);
int paddingY = (int) ((height - correctHeight) / 2);
mPaddingX = paddingX;
mPaddingY = paddingY;
preview.layout(paddingX, paddingY, correctWidth + paddingX, correctHeight + paddingY);
}
@ -373,23 +371,12 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
setScanning(mShouldDetectFaces || mShouldGoogleDetectBarcodes || mShouldScanBarCodes || mShouldRecognizeText);
}
public void setShouldGoogleDetectBarcodes(boolean shouldDetectBarcodes) {
if (shouldDetectBarcodes && mGoogleBarcodeDetector == null) {
setupBarcodeDetector();
}
this.mShouldGoogleDetectBarcodes = shouldDetectBarcodes;
setScanning(mShouldDetectFaces || mShouldGoogleDetectBarcodes || mShouldScanBarCodes || mShouldRecognizeText);
}
public void onFacesDetected(SparseArray<Face> facesReported, int sourceWidth, int sourceHeight, int sourceRotation) {
public void onFacesDetected(WritableArray data) {
if (!mShouldDetectFaces) {
return;
}
SparseArray<Face> facesDetected = facesReported == null ? new SparseArray<Face>() : facesReported;
ImageDimensions dimensions = new ImageDimensions(sourceWidth, sourceHeight, sourceRotation, getFacing());
RNCameraViewHelper.emitFacesDetectedEvent(this, facesDetected, dimensions);
RNCameraViewHelper.emitFacesDetectedEvent(this, data);
}
public void onFaceDetectionError(RNFaceDetector faceDetector) {
@ -413,11 +400,12 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
mGoogleBarcodeDetector.setBarcodeType(mGoogleVisionBarCodeType);
}
/**
* Initial setup of the text recongizer
*/
private void setupTextRecongnizer() {
mTextRecognizer = new TextRecognizer.Builder(mThemedReactContext).build();
public void setShouldGoogleDetectBarcodes(boolean shouldDetectBarcodes) {
if (shouldDetectBarcodes && mGoogleBarcodeDetector == null) {
setupBarcodeDetector();
}
this.mShouldGoogleDetectBarcodes = shouldDetectBarcodes;
setScanning(mShouldDetectFaces || mShouldGoogleDetectBarcodes || mShouldScanBarCodes || mShouldRecognizeText);
}
public void setGoogleVisionBarcodeType(int barcodeType) {
@ -431,14 +419,11 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
mGoogleVisionBarCodeMode = barcodeMode;
}
public void onBarcodesDetected(SparseArray<Barcode> barcodesReported, int sourceWidth, int sourceHeight, int sourceRotation) {
public void onBarcodesDetected(WritableArray barcodesDetected) {
if (!mShouldGoogleDetectBarcodes) {
return;
}
SparseArray<Barcode> barcodesDetected = barcodesReported == null ? new SparseArray<Barcode>() : barcodesReported;
RNCameraViewHelper.emitBarcodesDetectedEvent(this, barcodesDetected, sourceWidth, sourceHeight, sourceRotation);
RNCameraViewHelper.emitBarcodesDetectedEvent(this, barcodesDetected);
}
public void onBarcodeDetectionError(RNBarcodeDetector barcodeDetector) {
@ -454,24 +439,22 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
googleBarcodeDetectorTaskLock = false;
}
/**
*
* Text recognition
*/
public void setShouldRecognizeText(boolean shouldRecognizeText) {
if (shouldRecognizeText && mTextRecognizer == null) {
setupTextRecongnizer();
}
this.mShouldRecognizeText = shouldRecognizeText;
setScanning(mShouldDetectFaces || mShouldGoogleDetectBarcodes || mShouldScanBarCodes || mShouldRecognizeText);
}
@Override
public void onTextRecognized(SparseArray<TextBlock> textBlocks, int sourceWidth, int sourceHeight, int sourceRotation) {
public void onTextRecognized(WritableArray serializedData) {
if (!mShouldRecognizeText) {
return;
}
SparseArray<TextBlock> textBlocksDetected = textBlocks == null ? new SparseArray<TextBlock>() : textBlocks;
ImageDimensions dimensions = new ImageDimensions(sourceWidth, sourceHeight, sourceRotation, getFacing());
RNCameraViewHelper.emitTextRecognizedEvent(this, textBlocksDetected, dimensions);
RNCameraViewHelper.emitTextRecognizedEvent(this, serializedData);
}
@Override
@ -479,6 +462,10 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
textRecognizerTaskLock = false;
}
/**
*
* End Text Recognition */
@Override
public void onHostResume() {
if (hasCameraPermissions()) {
@ -511,9 +498,6 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
if (mGoogleBarcodeDetector != null) {
mGoogleBarcodeDetector.release();
}
if (mTextRecognizer != null) {
mTextRecognizer.release();
}
mMultiFormatReader = null;
stop();
mThemedReactContext.removeLifecycleEventListener(this);

View File

@ -7,19 +7,15 @@ import android.graphics.Paint;
import android.media.CamcorderProfile;
import android.os.Build;
import android.support.media.ExifInterface;
import android.util.SparseArray;
import android.view.ViewGroup;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.uimanager.UIManagerModule;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.text.TextBlock;
import com.google.zxing.Result;
import org.reactnative.camera.events.*;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.barcodedetector.RNBarcodeDetector;
import org.reactnative.facedetector.RNFaceDetector;
@ -193,24 +189,8 @@ public class RNCameraViewHelper {
// Face detection events
public static void emitFacesDetectedEvent(
ViewGroup view,
SparseArray<Face> faces,
ImageDimensions dimensions
) {
float density = view.getResources().getDisplayMetrics().density;
double scaleX = (double) view.getWidth() / (dimensions.getWidth() * density);
double scaleY = (double) view.getHeight() / (dimensions.getHeight() * density);
FacesDetectedEvent event = FacesDetectedEvent.obtain(
view.getId(),
faces,
dimensions,
scaleX,
scaleY
);
public static void emitFacesDetectedEvent(ViewGroup view, WritableArray data) {
FacesDetectedEvent event = FacesDetectedEvent.obtain(view.getId(), data);
ReactContext reactContext = (ReactContext) view.getContext();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(event);
}
@ -223,21 +203,8 @@ public class RNCameraViewHelper {
// Barcode detection events
public static void emitBarcodesDetectedEvent(
ViewGroup view,
SparseArray<Barcode> barcodes,
int sourceWidth,
int sourceHeight,
int sourceRotation
) {
BarcodesDetectedEvent event = BarcodesDetectedEvent.obtain(
view.getId(),
barcodes,
sourceWidth,
sourceHeight,
sourceRotation
);
public static void emitBarcodesDetectedEvent(ViewGroup view, WritableArray barcodes) {
BarcodesDetectedEvent event = BarcodesDetectedEvent.obtain(view.getId(), barcodes);
ReactContext reactContext = (ReactContext) view.getContext();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(event);
}
@ -258,23 +225,8 @@ public class RNCameraViewHelper {
// Text recognition event
public static void emitTextRecognizedEvent(
ViewGroup view,
SparseArray<TextBlock> textBlocks,
ImageDimensions dimensions) {
float density = view.getResources().getDisplayMetrics().density;
double scaleX = (double) view.getWidth() / (dimensions.getWidth() * density);
double scaleY = (double) view.getHeight() / (dimensions.getHeight() * density);
TextRecognizedEvent event = TextRecognizedEvent.obtain(
view.getId(),
textBlocks,
dimensions,
scaleX,
scaleY
);
public static void emitTextRecognizedEvent(ViewGroup view, WritableArray data) {
TextRecognizedEvent event = TextRecognizedEvent.obtain(view.getId(), data);
ReactContext reactContext = (ReactContext) view.getContext();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(event);
}

View File

@ -1,17 +1,11 @@
package org.reactnative.camera.events;
import android.graphics.Rect;
import android.support.v4.util.Pools;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.google.android.gms.vision.barcode.Barcode;
import org.reactnative.barcodedetector.BarcodeFormatUtils;
import org.reactnative.camera.CameraViewManager;
public class BarcodesDetectedEvent extends Event<BarcodesDetectedEvent> {
@ -19,41 +13,29 @@ public class BarcodesDetectedEvent extends Event<BarcodesDetectedEvent> {
private static final Pools.SynchronizedPool<BarcodesDetectedEvent> EVENTS_POOL =
new Pools.SynchronizedPool<>(3);
private SparseArray<Barcode> mBarcodes;
private int mSourceWidth;
private int mSourceHeight;
private int mSourceRotation;
private WritableArray mBarcodes;
private BarcodesDetectedEvent() {
}
public static BarcodesDetectedEvent obtain(
int viewTag,
SparseArray<Barcode> barcodes,
int sourceWidth,
int sourceHeight,
int sourceRotation
WritableArray barcodes
) {
BarcodesDetectedEvent event = EVENTS_POOL.acquire();
if (event == null) {
event = new BarcodesDetectedEvent();
}
event.init(viewTag, barcodes, sourceWidth, sourceHeight, sourceRotation);
event.init(viewTag, barcodes);
return event;
}
private void init(
int viewTag,
SparseArray<Barcode> barcodes,
int sourceWidth,
int sourceHeight,
int sourceRotation
WritableArray barcodes
) {
super.init(viewTag);
mBarcodes = barcodes;
mSourceWidth = sourceWidth;
mSourceHeight= sourceHeight;
mSourceRotation = sourceRotation;
}
/**
@ -81,39 +63,9 @@ public class BarcodesDetectedEvent extends Event<BarcodesDetectedEvent> {
}
private WritableMap serializeEventData() {
WritableArray barcodesList = Arguments.createArray();
for (int i = 0; i < mBarcodes.size(); i++) {
Barcode barcode = mBarcodes.valueAt(i);
WritableMap serializedBarcode = Arguments.createMap();
serializedBarcode.putString("data", barcode.displayValue);
serializedBarcode.putString("rawData", barcode.rawValue);
serializedBarcode.putString("type", BarcodeFormatUtils.get(barcode.format));
Rect barcodeBoundingBox = barcode.getBoundingBox();
if (barcodeBoundingBox != null) {
WritableMap serializedBounds = Arguments.createMap();
WritableMap serializedSize = Arguments.createMap();
serializedSize.putString("width", String.valueOf(barcodeBoundingBox.width()));
serializedSize.putString("height", String.valueOf(barcodeBoundingBox.height()));
serializedBounds.putMap("size", serializedSize);
WritableMap serializedOrigin = Arguments.createMap();
serializedOrigin.putString("x", String.valueOf(barcodeBoundingBox.left));
serializedOrigin.putString("y", String.valueOf(barcodeBoundingBox.top));
serializedBounds.putMap("origin", serializedOrigin);
serializedBarcode.putMap("bounds", serializedBounds);
barcodesList.pushMap(serializedBarcode);
}
}
WritableMap event = Arguments.createMap();
event.putString("type", "barcode");
event.putInt("sourceWidth", mSourceWidth);
event.putInt("sourceHeight", mSourceHeight);
event.putInt("sourceRotation", mSourceRotation);
event.putArray("barcodes", barcodesList);
event.putArray("barcodes", mBarcodes);
event.putInt("target", getViewTag());
return event;
}

View File

@ -1,57 +1,34 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import android.util.SparseArray;
import org.reactnative.camera.CameraViewManager;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.facedetector.FaceDetectorUtils;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.vision.face.Face;
public class FacesDetectedEvent extends Event<FacesDetectedEvent> {
private static final Pools.SynchronizedPool<FacesDetectedEvent> EVENTS_POOL =
new Pools.SynchronizedPool<>(3);
private double mScaleX;
private double mScaleY;
private SparseArray<Face> mFaces;
private ImageDimensions mImageDimensions;
private WritableArray mData;
private FacesDetectedEvent() {}
public static FacesDetectedEvent obtain(
int viewTag,
SparseArray<Face> faces,
ImageDimensions dimensions,
double scaleX,
double scaleY
) {
public static FacesDetectedEvent obtain(int viewTag, WritableArray data) {
FacesDetectedEvent event = EVENTS_POOL.acquire();
if (event == null) {
event = new FacesDetectedEvent();
}
event.init(viewTag, faces, dimensions, scaleX, scaleY);
event.init(viewTag, data);
return event;
}
private void init(
int viewTag,
SparseArray<Face> faces,
ImageDimensions dimensions,
double scaleX,
double scaleY
) {
private void init(int viewTag, WritableArray data) {
super.init(viewTag);
mFaces = faces;
mImageDimensions = dimensions;
mScaleX = scaleX;
mScaleY = scaleY;
mData = data;
}
/**
@ -61,11 +38,11 @@ public class FacesDetectedEvent extends Event<FacesDetectedEvent> {
*/
@Override
public short getCoalescingKey() {
if (mFaces.size() > Short.MAX_VALUE) {
if (mData.size() > Short.MAX_VALUE) {
return Short.MAX_VALUE;
}
return (short) mFaces.size();
return (short) mData.size();
}
@Override
@ -79,22 +56,9 @@ public class FacesDetectedEvent extends Event<FacesDetectedEvent> {
}
private WritableMap serializeEventData() {
WritableArray facesList = Arguments.createArray();
for(int i = 0; i < mFaces.size(); i++) {
Face face = mFaces.valueAt(i);
WritableMap serializedFace = FaceDetectorUtils.serializeFace(face, mScaleX, mScaleY);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedFace = FaceDetectorUtils.rotateFaceX(serializedFace, mImageDimensions.getWidth(), mScaleX);
} else {
serializedFace = FaceDetectorUtils.changeAnglesDirection(serializedFace);
}
facesList.pushMap(serializedFace);
}
WritableMap event = Arguments.createMap();
event.putString("type", "face");
event.putArray("faces", facesList);
event.putArray("faces", mData);
event.putInt("target", getViewTag());
return event;
}

View File

@ -1,22 +1,14 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.vision.text.Line;
import com.google.android.gms.vision.text.Text;
import com.google.android.gms.vision.text.TextBlock;
import org.reactnative.camera.CameraViewManager;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.facedetector.FaceDetectorUtils;
public class TextRecognizedEvent extends Event<TextRecognizedEvent> {
@ -24,39 +16,22 @@ public class TextRecognizedEvent extends Event<TextRecognizedEvent> {
private static final Pools.SynchronizedPool<TextRecognizedEvent> EVENTS_POOL =
new Pools.SynchronizedPool<>(3);
private double mScaleX;
private double mScaleY;
private SparseArray<TextBlock> mTextBlocks;
private ImageDimensions mImageDimensions;
private WritableArray mData;
private TextRecognizedEvent() {}
public static TextRecognizedEvent obtain(
int viewTag,
SparseArray<TextBlock> textBlocks,
ImageDimensions dimensions,
double scaleX,
double scaleY) {
public static TextRecognizedEvent obtain(int viewTag, WritableArray data) {
TextRecognizedEvent event = EVENTS_POOL.acquire();
if (event == null) {
event = new TextRecognizedEvent();
}
event.init(viewTag, textBlocks, dimensions, scaleX, scaleY);
event.init(viewTag, data);
return event;
}
private void init(
int viewTag,
SparseArray<TextBlock> textBlocks,
ImageDimensions dimensions,
double scaleX,
double scaleY) {
private void init(int viewTag, WritableArray data) {
super.init(viewTag);
mTextBlocks = textBlocks;
mImageDimensions = dimensions;
mScaleX = scaleX;
mScaleY = scaleY;
mData = data;
}
@Override
@ -66,92 +41,14 @@ public class TextRecognizedEvent extends Event<TextRecognizedEvent> {
@Override
public void dispatch(RCTEventEmitter rctEventEmitter) {
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), createEvent());
}
private WritableMap serializeEventData() {
WritableArray textBlocksList = Arguments.createArray();
for (int i = 0; i < mTextBlocks.size(); ++i) {
TextBlock textBlock = mTextBlocks.valueAt(i);
WritableMap serializedTextBlock = serializeText(textBlock);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedTextBlock = rotateTextX(serializedTextBlock);
}
textBlocksList.pushMap(serializedTextBlock);
}
private WritableMap createEvent() {
WritableMap event = Arguments.createMap();
event.putString("type", "textBlock");
event.putArray("textBlocks", textBlocksList);
event.putArray("textBlocks", mData);
event.putInt("target", getViewTag());
return event;
}
private WritableMap serializeText(Text text) {
WritableMap encodedText = Arguments.createMap();
WritableArray components = Arguments.createArray();
for (Text component : text.getComponents()) {
components.pushMap(serializeText(component));
}
encodedText.putArray("components", components);
encodedText.putString("value", text.getValue());
WritableMap origin = Arguments.createMap();
origin.putDouble("x", text.getBoundingBox().left * this.mScaleX);
origin.putDouble("y", text.getBoundingBox().top * this.mScaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", text.getBoundingBox().width() * this.mScaleX);
size.putDouble("height", text.getBoundingBox().height() * this.mScaleY);
WritableMap bounds = Arguments.createMap();
bounds.putMap("origin", origin);
bounds.putMap("size", size);
encodedText.putMap("bounds", bounds);
String type_;
if (text instanceof TextBlock) {
type_ = "block";
} else if (text instanceof Line) {
type_ = "line";
} else /*if (text instanceof Element)*/ {
type_ = "element";
}
encodedText.putString("type", type_);
return encodedText;
}
private WritableMap rotateTextX(WritableMap text) {
ReadableMap faceBounds = text.getMap("bounds");
ReadableMap oldOrigin = faceBounds.getMap("origin");
WritableMap mirroredOrigin = FaceDetectorUtils.positionMirroredHorizontally(
oldOrigin, mImageDimensions.getWidth(), mScaleX);
double translateX = -faceBounds.getMap("size").getDouble("width");
WritableMap translatedMirroredOrigin = FaceDetectorUtils.positionTranslatedHorizontally(mirroredOrigin, translateX);
WritableMap newBounds = Arguments.createMap();
newBounds.merge(faceBounds);
newBounds.putMap("origin", translatedMirroredOrigin);
text.putMap("bounds", newBounds);
ReadableArray oldComponents = text.getArray("components");
WritableArray newComponents = Arguments.createArray();
for (int i = 0; i < oldComponents.size(); ++i) {
WritableMap component = Arguments.createMap();
component.merge(oldComponents.getMap(i));
rotateTextX(component);
newComponents.pushMap(component);
}
text.putArray("components", newComponents);
return text;
}
}

View File

@ -1,57 +0,0 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.google.android.gms.vision.barcode.Barcode;
import org.reactnative.frame.RNFrame;
import org.reactnative.frame.RNFrameFactory;
import org.reactnative.barcodedetector.RNBarcodeDetector;
public class BarcodeDetectorAsyncTask extends android.os.AsyncTask<Void, Void, SparseArray<Barcode>> {
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private RNBarcodeDetector mBarcodeDetector;
private BarcodeDetectorAsyncTaskDelegate mDelegate;
public BarcodeDetectorAsyncTask(
BarcodeDetectorAsyncTaskDelegate delegate,
RNBarcodeDetector barcodeDetector,
byte[] imageData,
int width,
int height,
int rotation
) {
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mDelegate = delegate;
mBarcodeDetector = barcodeDetector;
}
@Override
protected SparseArray<Barcode> doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mBarcodeDetector == null || !mBarcodeDetector.isOperational()) {
return null;
}
RNFrame frame = RNFrameFactory.buildFrame(mImageData, mWidth, mHeight, mRotation);
return mBarcodeDetector.detect(frame);
}
@Override
protected void onPostExecute(SparseArray<Barcode> barcodes) {
super.onPostExecute(barcodes);
if (barcodes == null) {
mDelegate.onBarcodeDetectionError(mBarcodeDetector);
} else {
if (barcodes.size() > 0) {
mDelegate.onBarcodesDetected(barcodes, mWidth, mHeight, mRotation);
}
mDelegate.onBarcodeDetectingTaskCompleted();
}
}
}

View File

@ -1,12 +1,11 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.google.android.gms.vision.barcode.Barcode;
import com.facebook.react.bridge.WritableArray;
import org.reactnative.barcodedetector.RNBarcodeDetector;
public interface BarcodeDetectorAsyncTaskDelegate {
void onBarcodesDetected(SparseArray<Barcode> barcodes, int sourceWidth, int sourceHeight, int sourceRotation);
void onBarcodesDetected(WritableArray barcodes);
void onBarcodeDetectionError(RNBarcodeDetector barcodeDetector);

View File

@ -1,56 +0,0 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.google.android.gms.vision.face.Face;
import org.reactnative.frame.RNFrame;
import org.reactnative.frame.RNFrameFactory;
import org.reactnative.facedetector.RNFaceDetector;
public class FaceDetectorAsyncTask extends android.os.AsyncTask<Void, Void, SparseArray<Face>> {
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private RNFaceDetector mFaceDetector;
private FaceDetectorAsyncTaskDelegate mDelegate;
public FaceDetectorAsyncTask(
FaceDetectorAsyncTaskDelegate delegate,
RNFaceDetector faceDetector,
byte[] imageData,
int width,
int height,
int rotation
) {
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mDelegate = delegate;
mFaceDetector = faceDetector;
}
@Override
protected SparseArray<Face> doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mFaceDetector == null || !mFaceDetector.isOperational()) {
return null;
}
RNFrame frame = RNFrameFactory.buildFrame(mImageData, mWidth, mHeight, mRotation);
return mFaceDetector.detect(frame);
}
@Override
protected void onPostExecute(SparseArray<Face> faces) {
super.onPostExecute(faces);
if (faces == null) {
mDelegate.onFaceDetectionError(mFaceDetector);
} else {
if (faces.size() > 0) {
mDelegate.onFacesDetected(faces, mWidth, mHeight, mRotation);
}
mDelegate.onFaceDetectingTaskCompleted();
}
}
}

View File

@ -1,12 +1,11 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import org.reactnative.facedetector.RNFaceDetector;
import com.google.android.gms.vision.face.Face;
import com.facebook.react.bridge.WritableArray;
public interface FaceDetectorAsyncTaskDelegate {
void onFacesDetected(SparseArray<Face> face, int sourceWidth, int sourceHeight, int sourceRotation);
void onFacesDetected(WritableArray faces);
void onFaceDetectionError(RNFaceDetector faceDetector);
void onFaceDetectingTaskCompleted();
}

View File

@ -1,55 +0,0 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.google.android.gms.vision.text.TextBlock;
import com.google.android.gms.vision.text.TextRecognizer;
import org.reactnative.frame.RNFrame;
import org.reactnative.frame.RNFrameFactory;
public class TextRecognizerAsyncTask extends android.os.AsyncTask<Void, Void, SparseArray<TextBlock>> {
private TextRecognizerAsyncTaskDelegate mDelegate;
private TextRecognizer mTextRecognizer;
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
public TextRecognizerAsyncTask(
TextRecognizerAsyncTaskDelegate delegate,
TextRecognizer textRecognizer,
byte[] imageData,
int width,
int height,
int rotation
) {
mDelegate = delegate;
mTextRecognizer = textRecognizer;
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
}
@Override
protected SparseArray<TextBlock> doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mTextRecognizer == null || !mTextRecognizer.isOperational()) {
return null;
}
RNFrame frame = RNFrameFactory.buildFrame(mImageData, mWidth, mHeight, mRotation);
return mTextRecognizer.detect(frame.getFrame());
}
@Override
protected void onPostExecute(SparseArray<TextBlock> textBlocks) {
super.onPostExecute(textBlocks);
if (textBlocks != null) {
mDelegate.onTextRecognized(textBlocks, mWidth, mHeight, mRotation);
}
mDelegate.onTextRecognizerTaskCompleted();
}
}

View File

@ -1,10 +1,8 @@
package org.reactnative.camera.tasks;
import android.util.SparseArray;
import com.google.android.gms.vision.text.TextBlock;
import com.facebook.react.bridge.WritableArray;
public interface TextRecognizerAsyncTaskDelegate {
void onTextRecognized(SparseArray<TextBlock> textBlocks, int sourceWidth, int sourceHeight, int sourceRotation);
void onTextRecognized(WritableArray serializedData);
void onTextRecognizerTaskCompleted();
}

View File

@ -0,0 +1,91 @@
package org.reactnative.barcodedetector;
import android.util.SparseArray;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class BarcodeFormatUtils {
public static final SparseArray<String> FORMATS;
public static final Map<String, Integer> REVERSE_FORMATS;
public static final SparseArray<String> TYPES;
public static final Map<String, Integer> REVERSE_TYPES;
private static final int UNKNOWN_FORMAT_INT = FirebaseVisionBarcode.FORMAT_UNKNOWN;
private static final String UNKNOWN_TYPE_STRING = "UNKNOWN_TYPE";
static {
// Initialize integer to string map
SparseArray<String> map = new SparseArray<>();
map.put(FirebaseVisionBarcode.FORMAT_CODE_128, "CODE_128");
map.put(FirebaseVisionBarcode.FORMAT_CODE_39, "CODE_39");
map.put(FirebaseVisionBarcode.FORMAT_CODE_93, "CODE_93");
map.put(FirebaseVisionBarcode.FORMAT_CODABAR, "CODABAR");
map.put(FirebaseVisionBarcode.FORMAT_DATA_MATRIX, "DATA_MATRIX");
map.put(FirebaseVisionBarcode.FORMAT_EAN_13, "EAN_13");
map.put(FirebaseVisionBarcode.FORMAT_EAN_8, "EAN_8");
map.put(FirebaseVisionBarcode.FORMAT_ITF, "ITF");
map.put(FirebaseVisionBarcode.FORMAT_QR_CODE, "QR_CODE");
map.put(FirebaseVisionBarcode.FORMAT_UPC_A, "UPC_A");
map.put(FirebaseVisionBarcode.FORMAT_UPC_E, "UPC_E");
map.put(FirebaseVisionBarcode.FORMAT_PDF417, "PDF417");
map.put(FirebaseVisionBarcode.FORMAT_AZTEC, "AZTEC");
map.put(FirebaseVisionBarcode.FORMAT_ALL_FORMATS, "ALL");
map.put(FirebaseVisionBarcode.FORMAT_UPC_A, "UPC_A");
map.put(-1, "None");
FORMATS = map;
// Initialize string to integer map
Map<String, Integer> rmap = new HashMap<>();
for (int i = 0; i < map.size(); i++) {
rmap.put(map.valueAt(i), map.keyAt(i));
}
REVERSE_FORMATS = Collections.unmodifiableMap(rmap);
}
static {
// Initialize integer to string map
SparseArray<String> map = new SparseArray<>();
map.put(FirebaseVisionBarcode.TYPE_CALENDAR_EVENT, "CALENDAR_EVENT");
map.put(FirebaseVisionBarcode.TYPE_CONTACT_INFO, "CONTACT_INFO");
map.put(FirebaseVisionBarcode.TYPE_DRIVER_LICENSE, "DRIVER_LICENSE");
map.put(FirebaseVisionBarcode.TYPE_EMAIL, "EMAIL");
map.put(FirebaseVisionBarcode.TYPE_GEO, "GEO");
map.put(FirebaseVisionBarcode.TYPE_ISBN, "ISBN");
map.put(FirebaseVisionBarcode.TYPE_PHONE, "PHONE");
map.put(FirebaseVisionBarcode.TYPE_PRODUCT, "PRODUCT");
map.put(FirebaseVisionBarcode.TYPE_SMS, "SMS");
map.put(FirebaseVisionBarcode.TYPE_TEXT, "TEXT");
map.put(FirebaseVisionBarcode.TYPE_URL, "URL");
map.put(FirebaseVisionBarcode.TYPE_WIFI, "WIFI");
map.put(-1, "None");
TYPES = map;
// Initialize string to integer map
Map<String, Integer> rmap = new HashMap<>();
for (int i = 0; i < map.size(); i++) {
rmap.put(map.valueAt(i), map.keyAt(i));
}
REVERSE_TYPES = Collections.unmodifiableMap(rmap);
}
public static String get(int format) {
return TYPES.get(format, UNKNOWN_TYPE_STRING);
}
public static int get(String format) {
if (REVERSE_FORMATS.containsKey(format)) {
return REVERSE_FORMATS.get(format);
}
return UNKNOWN_FORMAT_INT;
}
}

View File

@ -0,0 +1,66 @@
package org.reactnative.barcodedetector;
import android.content.Context;
import android.util.Log;
import com.google.firebase.ml.vision.FirebaseVision;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions;
public class RNBarcodeDetector {
public static int NORMAL_MODE = 0;
public static int ALTERNATE_MODE = 1;
public static int INVERTED_MODE = 2;
private FirebaseVisionBarcodeDetector mBarcodeDetector = null;
private FirebaseVisionBarcodeDetectorOptions.Builder mBuilder;
private int mBarcodeType = FirebaseVisionBarcode.FORMAT_ALL_FORMATS;
public RNBarcodeDetector(Context context) {
mBuilder = new FirebaseVisionBarcodeDetectorOptions.Builder().setBarcodeFormats(mBarcodeType);
}
public boolean isOperational() {
// Legacy api from GMV
return true;
}
public FirebaseVisionBarcodeDetector getDetector() {
if (mBarcodeDetector == null) {
createBarcodeDetector();
}
return mBarcodeDetector;
}
public void setBarcodeType(int barcodeType) {
if (barcodeType != mBarcodeType) {
release();
mBuilder.setBarcodeFormats(barcodeType);
mBarcodeType = barcodeType;
}
}
public void release() {
if (mBarcodeDetector != null) {
try {
mBarcodeDetector.close();
} catch (Exception e) {
Log.e("RNCamera", "Attempt to close BarcodeDetector failed");
}
mBarcodeDetector = null;
}
}
private void createBarcodeDetector() {
FirebaseVisionBarcodeDetectorOptions options = mBuilder.build();
mBarcodeDetector = FirebaseVision.getInstance()
.getVisionBarcodeDetector();
}
}

View File

@ -0,0 +1,205 @@
package org.reactnative.camera.tasks;
//import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata;
import org.reactnative.barcodedetector.BarcodeFormatUtils;
import org.reactnative.barcodedetector.RNBarcodeDetector;
import org.reactnative.camera.utils.ImageDimensions;
import java.util.List;
public class BarcodeDetectorAsyncTask extends android.os.AsyncTask<Void, Void, Void> {
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private RNBarcodeDetector mBarcodeDetector;
private BarcodeDetectorAsyncTaskDelegate mDelegate;
private double mScaleX;
private double mScaleY;
private ImageDimensions mImageDimensions;
private int mPaddingLeft;
private int mPaddingTop;
private String TAG = "RNCamera";
public BarcodeDetectorAsyncTask(
BarcodeDetectorAsyncTaskDelegate delegate,
RNBarcodeDetector barcodeDetector,
byte[] imageData,
int width,
int height,
int rotation,
float density,
int facing,
int viewWidth,
int viewHeight,
int viewPaddingLeft,
int viewPaddingTop
) {
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mDelegate = delegate;
mBarcodeDetector = barcodeDetector;
mImageDimensions = new ImageDimensions(width, height, rotation, facing);
mScaleX = (double) (viewWidth) / (mImageDimensions.getWidth() * density);
mScaleY = (double) (viewHeight) / (mImageDimensions.getHeight() * density);
mPaddingLeft = viewPaddingLeft;
mPaddingTop = viewPaddingTop;
}
@Override
protected Void doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mBarcodeDetector == null) {
return null;
}
final FirebaseVisionImageMetadata metadata = new FirebaseVisionImageMetadata.Builder()
.setWidth(mWidth)
.setHeight(mHeight)
.setFormat(FirebaseVisionImageMetadata.IMAGE_FORMAT_YV12)
.setRotation(getFirebaseRotation())
.build();
FirebaseVisionImage image = FirebaseVisionImage.fromByteArray(mImageData, metadata);
FirebaseVisionBarcodeDetector barcode = mBarcodeDetector.getDetector();
barcode.detectInImage(image)
.addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
@Override
public void onSuccess(List<FirebaseVisionBarcode> barcodes) {
WritableArray serializedBarcodes = serializeEventData(barcodes);
mDelegate.onBarcodesDetected(serializedBarcodes);
mDelegate.onBarcodeDetectingTaskCompleted();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e(TAG, "Text recognition task failed" + e);
mDelegate.onBarcodeDetectingTaskCompleted();
}
});
return null;
}
private int getFirebaseRotation(){
int result;
switch (mRotation) {
case 0:
result = FirebaseVisionImageMetadata.ROTATION_0;
break;
case 90:
result = FirebaseVisionImageMetadata.ROTATION_90;
break;
case 180:
result = FirebaseVisionImageMetadata.ROTATION_180;
break;
case -90:
result = FirebaseVisionImageMetadata.ROTATION_270;
break;
default:
result = FirebaseVisionImageMetadata.ROTATION_0;
Log.e(TAG, "Bad rotation value: " + mRotation);
}
return result;
}
private WritableArray serializeEventData(List<FirebaseVisionBarcode> barcodes) {
WritableArray barcodesList = Arguments.createArray();
for (FirebaseVisionBarcode barcode: barcodes) {
// TODO implement position and data from all barcode types
Rect bounds = barcode.getBoundingBox();
// Point[] corners = barcode.getCornerPoints();
String rawValue = barcode.getRawValue();
int valueType = barcode.getValueType();
WritableMap serializedBarcode = Arguments.createMap();
switch (valueType) {
case FirebaseVisionBarcode.TYPE_WIFI:
String ssid = barcode.getWifi().getSsid();
String password = barcode.getWifi().getPassword();
int type = barcode.getWifi().getEncryptionType();
String typeString = "UNKNOWN";
switch (type) {
case FirebaseVisionBarcode.WiFi.TYPE_OPEN:
typeString = "Open";
break;
case FirebaseVisionBarcode.WiFi.TYPE_WEP:
typeString = "WEP";
break;
case FirebaseVisionBarcode.WiFi.TYPE_WPA:
typeString = "WPA";
break;
}
serializedBarcode.putString("encryptionType", typeString);
serializedBarcode.putString("password", password);
serializedBarcode.putString("ssid", ssid);
break;
case FirebaseVisionBarcode.TYPE_URL:
String title = barcode.getUrl().getTitle();
String url = barcode.getUrl().getUrl();
serializedBarcode.putString("url", url);
serializedBarcode.putString("title", title);
break;
}
serializedBarcode.putString("data", barcode.getDisplayValue());
serializedBarcode.putString("dataRaw", rawValue);
serializedBarcode.putString("type", BarcodeFormatUtils.get(valueType));
serializedBarcode.putMap("bounds", processBounds(bounds));
barcodesList.pushMap(serializedBarcode);
}
return barcodesList;
}
private WritableMap processBounds(Rect frame) {
WritableMap origin = Arguments.createMap();
int x = frame.left;
int y = frame.top;
if (frame.left < mWidth / 2) {
x = x + mPaddingLeft / 2;
} else if (frame.left > mWidth /2) {
x = x - mPaddingLeft / 2;
}
if (frame.top < mHeight / 2) {
y = y + mPaddingTop / 2;
} else if (frame.top > mHeight / 2) {
y = y - mPaddingTop / 2;
}
origin.putDouble("x", x * mScaleX);
origin.putDouble("y", y * mScaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", frame.width() * mScaleX);
size.putDouble("height", frame.height() * mScaleY);
WritableMap bounds = Arguments.createMap();
bounds.putMap("origin", origin);
bounds.putMap("size", size);
return bounds;
}
}

View File

@ -0,0 +1,136 @@
package org.reactnative.camera.tasks;
import android.util.Log;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata;
import com.google.firebase.ml.vision.face.FirebaseVisionFace;
import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetector;
import org.reactnative.camera.utils.ImageDimensions;
import org.reactnative.facedetector.FaceDetectorUtils;
import org.reactnative.facedetector.RNFaceDetector;
import java.util.List;
public class FaceDetectorAsyncTask extends android.os.AsyncTask<Void, Void, Void> {
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private RNFaceDetector mFaceDetector;
private FaceDetectorAsyncTaskDelegate mDelegate;
private double mScaleX;
private double mScaleY;
private ImageDimensions mImageDimensions;
private int mPaddingLeft;
private int mPaddingTop;
private String TAG = "RNCamera";
public FaceDetectorAsyncTask(
FaceDetectorAsyncTaskDelegate delegate,
RNFaceDetector faceDetector,
byte[] imageData,
int width,
int height,
int rotation,
float density,
int facing,
int viewWidth,
int viewHeight,
int viewPaddingLeft,
int viewPaddingTop
) {
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mDelegate = delegate;
mFaceDetector = faceDetector;
mImageDimensions = new ImageDimensions(width, height, rotation, facing);
mScaleX = (double) (viewWidth) / (mImageDimensions.getWidth() * density);
mScaleY = (double) (viewHeight) / (mImageDimensions.getHeight() * density);
mPaddingLeft = viewPaddingLeft;
mPaddingTop = viewPaddingTop;
}
@Override
protected Void doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null || mFaceDetector == null) {
return null;
}
FirebaseVisionImageMetadata metadata = new FirebaseVisionImageMetadata.Builder()
.setWidth(mWidth)
.setHeight(mHeight)
.setFormat(FirebaseVisionImageMetadata.IMAGE_FORMAT_YV12)
.setRotation(getFirebaseRotation())
.build();
FirebaseVisionImage image = FirebaseVisionImage.fromByteArray(mImageData, metadata);
FirebaseVisionFaceDetector detector = mFaceDetector.getDetector();
detector.detectInImage(image)
.addOnSuccessListener(
new OnSuccessListener<List<FirebaseVisionFace>>() {
@Override
public void onSuccess(List<FirebaseVisionFace> faces) {
WritableArray facesList = serializeEventData(faces);
mDelegate.onFacesDetected(facesList);
mDelegate.onFaceDetectingTaskCompleted();
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e(TAG, "Text recognition task failed" + e);
mDelegate.onFaceDetectingTaskCompleted();
}
});
return null;
}
private int getFirebaseRotation(){
int result;
switch (mRotation) {
case 0:
result = FirebaseVisionImageMetadata.ROTATION_0;
break;
case 90:
result = FirebaseVisionImageMetadata.ROTATION_90;
break;
case 180:
result = FirebaseVisionImageMetadata.ROTATION_180;
break;
case -90:
result = FirebaseVisionImageMetadata.ROTATION_270;
break;
default:
result = FirebaseVisionImageMetadata.ROTATION_0;
Log.e(TAG, "Bad rotation value: " + mRotation);
}
return result;
}
private WritableArray serializeEventData(List<FirebaseVisionFace> faces) {
WritableArray facesList = Arguments.createArray();
for (FirebaseVisionFace face : faces) {
WritableMap serializedFace = FaceDetectorUtils.serializeFace(face, mScaleX, mScaleY, mWidth, mHeight, mPaddingLeft, mPaddingTop);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedFace = FaceDetectorUtils.rotateFaceX(serializedFace, mImageDimensions.getWidth(), mScaleX);
} else {
serializedFace = FaceDetectorUtils.changeAnglesDirection(serializedFace);
}
facesList.pushMap(serializedFace);
}
return facesList;
}
}

View File

@ -0,0 +1,267 @@
package org.reactnative.camera.tasks;
import android.graphics.Rect;
import android.util.Log;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.google.android.cameraview.CameraView;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.ml.vision.FirebaseVision;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata;
import com.google.firebase.ml.vision.text.FirebaseVisionText;
import com.google.firebase.ml.vision.text.FirebaseVisionTextRecognizer;
import org.reactnative.camera.utils.ImageDimensions;
import java.util.List;
public class TextRecognizerAsyncTask extends android.os.AsyncTask<Void, Void, Void> {
private TextRecognizerAsyncTaskDelegate mDelegate;
private ThemedReactContext mThemedReactContext;
private byte[] mImageData;
private int mWidth;
private int mHeight;
private int mRotation;
private double mScaleX;
private double mScaleY;
private ImageDimensions mImageDimensions;
private int mPaddingLeft;
private int mPaddingTop;
private String TAG = "RNCamera";
public TextRecognizerAsyncTask(
TextRecognizerAsyncTaskDelegate delegate,
ThemedReactContext themedReactContext,
byte[] imageData,
int width,
int height,
int rotation,
float density,
int facing,
int viewWidth,
int viewHeight,
int viewPaddingLeft,
int viewPaddingTop
) {
mDelegate = delegate;
mImageData = imageData;
mWidth = width;
mHeight = height;
mRotation = rotation;
mImageDimensions = new ImageDimensions(width, height, rotation, facing);
mScaleX = (double) (viewWidth) / (mImageDimensions.getWidth() * density);
mScaleY = (double) (viewHeight) / (mImageDimensions.getHeight() * density);
mPaddingLeft = viewPaddingLeft;
mPaddingTop = viewPaddingTop;
}
@Override
protected Void doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null) {
return null;
}
FirebaseVisionImageMetadata metadata = new FirebaseVisionImageMetadata.Builder()
.setWidth(mWidth)
.setHeight(mHeight)
.setFormat(FirebaseVisionImageMetadata.IMAGE_FORMAT_YV12)
.setRotation(getFirebaseRotation())
.build();
FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance().getOnDeviceTextRecognizer();
FirebaseVisionImage image = FirebaseVisionImage.fromByteArray(mImageData, metadata);
detector.processImage(image)
.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText firebaseVisionText) {
List<FirebaseVisionText.TextBlock> textBlocks = firebaseVisionText.getTextBlocks();
WritableArray serializedData = serializeEventData(textBlocks);
mDelegate.onTextRecognized(serializedData);
mDelegate.onTextRecognizerTaskCompleted();
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e(TAG, "Text recognition task failed" + e);
mDelegate.onTextRecognizerTaskCompleted();
}
});
return null;
}
private int getFirebaseRotation(){
int result;
switch (mRotation) {
case 0:
result = FirebaseVisionImageMetadata.ROTATION_0;
break;
case 90:
result = FirebaseVisionImageMetadata.ROTATION_90;
break;
case 180:
result = FirebaseVisionImageMetadata.ROTATION_180;
break;
case -90:
result = FirebaseVisionImageMetadata.ROTATION_270;
break;
default:
result = FirebaseVisionImageMetadata.ROTATION_0;
Log.e(TAG, "Bad rotation value: " + mRotation);
}
return result;
}
private WritableArray serializeEventData(List<FirebaseVisionText.TextBlock> textBlocks) {
WritableArray textBlocksList = Arguments.createArray();
for (FirebaseVisionText.TextBlock block: textBlocks) {
WritableMap serializedTextBlock = serializeBloc(block);
if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
serializedTextBlock = rotateTextX(serializedTextBlock);
}
textBlocksList.pushMap(serializedTextBlock);
}
return textBlocksList;
}
private WritableMap serializeBloc(FirebaseVisionText.TextBlock block) {
WritableMap encodedText = Arguments.createMap();
WritableArray lines = Arguments.createArray();
for (FirebaseVisionText.Line line : block.getLines()) {
lines.pushMap(serializeLine(line));
}
encodedText.putArray("components", lines);
encodedText.putString("value", block.getText());
WritableMap bounds = processBounds(block.getBoundingBox());
encodedText.putMap("bounds", bounds);
encodedText.putString("type", "block");
return encodedText;
}
private WritableMap serializeLine(FirebaseVisionText.Line line) {
WritableMap encodedText = Arguments.createMap();
WritableArray lines = Arguments.createArray();
for (FirebaseVisionText.Element element : line.getElements()) {
lines.pushMap(serializeElement(element));
}
encodedText.putArray("components", lines);
encodedText.putString("value", line.getText());
WritableMap bounds = processBounds(line.getBoundingBox());
encodedText.putMap("bounds", bounds);
encodedText.putString("type", "line");
return encodedText;
}
private WritableMap serializeElement(FirebaseVisionText.Element element) {
WritableMap encodedText = Arguments.createMap();
encodedText.putString("value", element.getText());
WritableMap bounds = processBounds(element.getBoundingBox());
encodedText.putMap("bounds", bounds);
encodedText.putString("type", "element");
return encodedText;
}
private WritableMap processBounds(Rect frame) {
WritableMap origin = Arguments.createMap();
int x = frame.left;
int y = frame.top;
if (frame.left < mWidth / 2) {
x = x + mPaddingLeft / 2;
} else if (frame.left > mWidth /2) {
x = x - mPaddingLeft / 2;
}
if (frame.top < mHeight / 2) {
y = y + mPaddingTop / 2;
} else if (frame.top > mHeight / 2) {
y = y - mPaddingTop / 2;
}
origin.putDouble("x", x * mScaleX);
origin.putDouble("y", y * mScaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", frame.width() * mScaleX);
size.putDouble("height", frame.height() * mScaleY);
WritableMap bounds = Arguments.createMap();
bounds.putMap("origin", origin);
bounds.putMap("size", size);
return bounds;
}
private WritableMap rotateTextX(WritableMap text) {
ReadableMap faceBounds = text.getMap("bounds");
ReadableMap oldOrigin = faceBounds.getMap("origin");
WritableMap mirroredOrigin = positionMirroredHorizontally(
oldOrigin, mImageDimensions.getWidth(), mScaleX);
double translateX = -faceBounds.getMap("size").getDouble("width");
WritableMap translatedMirroredOrigin = positionTranslatedHorizontally(mirroredOrigin, translateX);
WritableMap newBounds = Arguments.createMap();
newBounds.merge(faceBounds);
newBounds.putMap("origin", translatedMirroredOrigin);
text.putMap("bounds", newBounds);
ReadableArray oldComponents = text.getArray("components");
WritableArray newComponents = Arguments.createArray();
for (int i = 0; i < oldComponents.size(); ++i) {
WritableMap component = Arguments.createMap();
component.merge(oldComponents.getMap(i));
rotateTextX(component);
newComponents.pushMap(component);
}
text.putArray("components", newComponents);
return text;
}
public static WritableMap positionTranslatedHorizontally(ReadableMap position, double translateX) {
WritableMap newPosition = Arguments.createMap();
newPosition.merge(position);
newPosition.putDouble("x", position.getDouble("x") + translateX);
return newPosition;
}
public static WritableMap positionMirroredHorizontally(ReadableMap position, int containerWidth, double scaleX) {
WritableMap newPosition = Arguments.createMap();
newPosition.merge(position);
newPosition.putDouble("x", valueMirroredHorizontally(position.getDouble("x"), containerWidth, scaleX));
return newPosition;
}
public static double valueMirroredHorizontally(double elementX, int containerWidth, double scaleX) {
double originalX = elementX / scaleX;
double mirroredX = containerWidth - originalX;
return mirroredX * scaleX;
}
}

View File

@ -0,0 +1,74 @@
package org.reactnative.facedetector;
import org.reactnative.facedetector.tasks.FileFaceDetectionAsyncTask;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
public class FaceDetectorModule extends ReactContextBaseJavaModule {
private static final String TAG = "RNFaceDetector";
// private ScopedContext mScopedContext;
private static ReactApplicationContext mScopedContext;
public FaceDetectorModule(ReactApplicationContext reactContext) {
super(reactContext);
mScopedContext = reactContext;
}
@Override
public String getName() {
return TAG;
}
@Nullable
@Override
public Map<String, Object> getConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
put("Mode", getFaceDetectionModeConstants());
put("Landmarks", getFaceDetectionLandmarksConstants());
put("Classifications", getFaceDetectionClassificationsConstants());
}
private Map<String, Object> getFaceDetectionModeConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
put("fast", RNFaceDetector.FAST_MODE);
put("accurate", RNFaceDetector.ACCURATE_MODE);
}
});
}
private Map<String, Object> getFaceDetectionClassificationsConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
put("all", RNFaceDetector.ALL_CLASSIFICATIONS);
put("none", RNFaceDetector.NO_CLASSIFICATIONS);
}
});
}
private Map<String, Object> getFaceDetectionLandmarksConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
put("all", RNFaceDetector.ALL_LANDMARKS);
put("none", RNFaceDetector.NO_LANDMARKS);
}
});
}
});
}
@ReactMethod
public void detectFaces(ReadableMap options, final Promise promise) {
new FileFaceDetectionAsyncTask(mScopedContext, options, promise).execute();
}
}

View File

@ -0,0 +1,166 @@
package org.reactnative.facedetector;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.google.firebase.ml.vision.common.FirebaseVisionPoint;
import com.google.firebase.ml.vision.face.FirebaseVisionFace;
import com.google.firebase.ml.vision.face.FirebaseVisionFaceLandmark;
public class FaceDetectorUtils {
private static final String[] landmarkNames = {
"bottomMouthPosition", "leftCheekPosition", "leftEarPosition",
"leftEyePosition", "leftMouthPosition", "noseBasePosition", "rightCheekPosition",
"rightEarPosition", "rightEyePosition", "rightMouthPosition"
};
public static WritableMap serializeFace(FirebaseVisionFace face) {
return serializeFace(face, 1, 1, 0, 0, 0, 0);
}
public static WritableMap serializeFace(FirebaseVisionFace face, double scaleX, double scaleY, int width, int height, int paddingLeft, int paddingTop) {
WritableMap encodedFace = Arguments.createMap();
int id = 0;
// If face tracking was enabled:
if (face.getTrackingId() != FirebaseVisionFace.INVALID_ID) {
id = face.getTrackingId();
}
encodedFace.putInt("faceID", id);
encodedFace.putDouble("rollAngle", face.getHeadEulerAngleZ());
encodedFace.putDouble("yawAngle", face.getHeadEulerAngleY());
// If classification was enabled:
if (face.getSmilingProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
encodedFace.putDouble("smilingProbability", face.getSmilingProbability());
}
if (face.getLeftEyeOpenProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
encodedFace.putDouble("leftEyeOpenProbability", face.getLeftEyeOpenProbability());
}
if (face.getRightEyeOpenProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) {
encodedFace.putDouble("rightEyeOpenProbability", face.getRightEyeOpenProbability());
}
int[] landmarks = {
FirebaseVisionFaceLandmark.MOUTH_BOTTOM,
FirebaseVisionFaceLandmark.LEFT_CHEEK,
FirebaseVisionFaceLandmark.LEFT_EAR,
FirebaseVisionFaceLandmark.LEFT_EYE,
FirebaseVisionFaceLandmark.MOUTH_LEFT,
FirebaseVisionFaceLandmark.NOSE_BASE,
FirebaseVisionFaceLandmark.RIGHT_CHEEK,
FirebaseVisionFaceLandmark.RIGHT_EAR,
FirebaseVisionFaceLandmark.RIGHT_EYE,
FirebaseVisionFaceLandmark.MOUTH_RIGHT};
for (int i = 0; i < landmarks.length; ++i) {
FirebaseVisionFaceLandmark landmark = face.getLandmark(landmarks[i]);
if (landmark != null) {
encodedFace.putMap(landmarkNames[i], mapFromPoint(landmark.getPosition(), scaleX, scaleY, width, height, paddingLeft, paddingTop));
}
}
WritableMap origin = Arguments.createMap();
Float x = face.getBoundingBox().exactCenterX() - (face.getBoundingBox().width() / 2 );
Float y = face.getBoundingBox().exactCenterY() - (face.getBoundingBox().height() / 2);
if (face.getBoundingBox().exactCenterX() < width / 2) {
x = x + paddingLeft / 2;
} else if (face.getBoundingBox().exactCenterX() > width / 2) {
x = x - paddingLeft / 2;
}
if (face.getBoundingBox().exactCenterY() < height / 2) {
y = y + paddingTop / 2;
} else if (face.getBoundingBox().exactCenterY() > height / 2) {
y = y - paddingTop / 2;
}
origin.putDouble("x", x * scaleX);
origin.putDouble("y", y * scaleY);
WritableMap size = Arguments.createMap();
size.putDouble("width", face.getBoundingBox().width() * scaleX);
size.putDouble("height", face.getBoundingBox().height() * scaleY);
WritableMap bounds = Arguments.createMap();
bounds.putMap("origin", origin);
bounds.putMap("size", size);
encodedFace.putMap("bounds", bounds);
return encodedFace;
}
public static WritableMap rotateFaceX(WritableMap face, int sourceWidth, double scaleX) {
ReadableMap faceBounds = face.getMap("bounds");
ReadableMap oldOrigin = faceBounds.getMap("origin");
WritableMap mirroredOrigin = positionMirroredHorizontally(oldOrigin, sourceWidth, scaleX);
double translateX = -faceBounds.getMap("size").getDouble("width");
WritableMap translatedMirroredOrigin = positionTranslatedHorizontally(mirroredOrigin, translateX);
WritableMap newBounds = Arguments.createMap();
newBounds.merge(faceBounds);
newBounds.putMap("origin", translatedMirroredOrigin);
for (String landmarkName : landmarkNames) {
ReadableMap landmark = face.hasKey(landmarkName) ? face.getMap(landmarkName) : null;
if (landmark != null) {
WritableMap mirroredPosition = positionMirroredHorizontally(landmark, sourceWidth, scaleX);
face.putMap(landmarkName, mirroredPosition);
}
}
face.putMap("bounds", newBounds);
return face;
}
public static WritableMap changeAnglesDirection(WritableMap face) {
face.putDouble("rollAngle", (-face.getDouble("rollAngle") + 360) % 360);
face.putDouble("yawAngle", (-face.getDouble("yawAngle") + 360) % 360);
return face;
}
public static WritableMap mapFromPoint(FirebaseVisionPoint point, double scaleX, double scaleY, int width, int height, int paddingLeft, int paddingTop) {
WritableMap map = Arguments.createMap();
Float x = point.getX();
Float y = point.getY();
if (point.getX() < width / 2) {
x = (x + paddingLeft / 2);
} else if (point.getX() > width / 2) {
x = (x - paddingLeft / 2);
}
if (point.getY() < height / 2) {
y = (y + paddingTop / 2);
} else if (point.getY() > height / 2) {
y = (y - paddingTop / 2);
}
map.putDouble("x", x * scaleX);
map.putDouble("y", y * scaleY);
return map;
}
public static WritableMap positionTranslatedHorizontally(ReadableMap position, double translateX) {
WritableMap newPosition = Arguments.createMap();
newPosition.merge(position);
newPosition.putDouble("x", position.getDouble("x") + translateX);
return newPosition;
}
public static WritableMap positionMirroredHorizontally(ReadableMap position, int containerWidth, double scaleX) {
WritableMap newPosition = Arguments.createMap();
newPosition.merge(position);
newPosition.putDouble("x", valueMirroredHorizontally(position.getDouble("x"), containerWidth, scaleX));
return newPosition;
}
public static double valueMirroredHorizontally(double elementX, int containerWidth, double scaleX) {
double originalX = elementX / scaleX;
double mirroredX = containerWidth - originalX;
return mirroredX * scaleX;
}
}

View File

@ -0,0 +1,104 @@
package org.reactnative.facedetector;
import android.content.Context;
import android.util.Log;
import com.google.firebase.ml.vision.FirebaseVision;
import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetector;
import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetectorOptions;
public class RNFaceDetector {
public static int ALL_CLASSIFICATIONS = FirebaseVisionFaceDetectorOptions.ALL_CLASSIFICATIONS;
public static int NO_CLASSIFICATIONS = FirebaseVisionFaceDetectorOptions.NO_CLASSIFICATIONS;
public static int ALL_LANDMARKS = FirebaseVisionFaceDetectorOptions.ALL_LANDMARKS;
public static int NO_LANDMARKS = FirebaseVisionFaceDetectorOptions.NO_LANDMARKS;
public static int ACCURATE_MODE = FirebaseVisionFaceDetectorOptions.ACCURATE;
public static int FAST_MODE = FirebaseVisionFaceDetectorOptions.FAST;
// TODO contours detection is possible for MLKit-based face detector, implement this feature
public static int ALL_CONTOURS = FirebaseVisionFaceDetectorOptions.ALL_CONTOURS;
public static int NO_CONTOURS = FirebaseVisionFaceDetectorOptions.NO_CONTOURS;
private FirebaseVisionFaceDetector mFaceDetector = null;
private FirebaseVisionFaceDetectorOptions.Builder mBuilder;
private int mClassificationType = NO_CLASSIFICATIONS;
private int mLandmarkType = NO_LANDMARKS;
private float mMinFaceSize = 0.15f;
private int mMode = FAST_MODE;
public RNFaceDetector(Context context) {
mBuilder = new FirebaseVisionFaceDetectorOptions.Builder()
.setPerformanceMode(mMode)
.setLandmarkMode(mLandmarkType)
.setClassificationMode(mClassificationType)
.setMinFaceSize(mMinFaceSize);
}
public boolean isOperational() {
// Legacy api from GMV
return true;
}
public FirebaseVisionFaceDetector getDetector() {
if (mFaceDetector == null) {
createFaceDetector();
}
return mFaceDetector;
}
public void setTracking(boolean trackingEnabled) {
release();
if (trackingEnabled) {
mBuilder.enableTracking();
}
}
public void setClassificationType(int classificationType) {
if (classificationType != mClassificationType) {
release();
mBuilder.setClassificationMode(classificationType);
mClassificationType = classificationType;
}
}
public void setLandmarkType(int landmarkType) {
if (landmarkType != mLandmarkType) {
release();
mBuilder.setLandmarkMode(landmarkType);
mLandmarkType = landmarkType;
}
}
public void setMode(int mode) {
if (mode != mMode) {
release();
mBuilder.setPerformanceMode(mode);
mMode = mode;
}
}
public void setTrackingEnabled(boolean tracking) {
release();
if (tracking) {
mBuilder.enableTracking();
}
}
public void release() {
if (mFaceDetector != null) {
try {
mFaceDetector.close();
} catch (Exception e) {
Log.e("RNCamera", "Attempt to close FaceDetector failed");
}
mFaceDetector = null;
}
}
private void createFaceDetector() {
FirebaseVisionFaceDetectorOptions options = mBuilder.build();
mFaceDetector = FirebaseVision.getInstance().getVisionFaceDetector(options);
}
}

View File

@ -0,0 +1,167 @@
package org.reactnative.facedetector.tasks;
import android.content.Context;
import android.support.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import org.reactnative.facedetector.RNFaceDetector;
import org.reactnative.facedetector.FaceDetectorUtils;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.google.firebase.ml.vision.face.FirebaseVisionFace;
import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetector;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class FileFaceDetectionAsyncTask extends AsyncTask<Void, Void, Void> {
private static final String ERROR_TAG = "E_FACE_DETECTION_FAILED";
private static final String MODE_OPTION_KEY = "mode";
private static final String DETECT_LANDMARKS_OPTION_KEY = "detectLandmarks";
private static final String RUN_CLASSIFICATIONS_OPTION_KEY = "runClassifications";
private String mUri;
private String mPath;
private Promise mPromise;
private int mWidth = 0;
private int mHeight = 0;
private Context mContext;
private ReadableMap mOptions;
private int mOrientation = ExifInterface.ORIENTATION_UNDEFINED;
private RNFaceDetector mRNFaceDetector;
public FileFaceDetectionAsyncTask(Context context, ReadableMap options, Promise promise) {
mUri = options.getString("uri");
mPromise = promise;
mOptions = options;
mContext = context;
}
@Override
protected void onPreExecute() {
if (mUri == null) {
mPromise.reject(ERROR_TAG, "You have to provide an URI of an image.");
cancel(true);
return;
}
Uri uri = Uri.parse(mUri);
mPath = uri.getPath();
if (mPath == null) {
mPromise.reject(ERROR_TAG, "Invalid URI provided: `" + mUri + "`.");
cancel(true);
return;
}
// We have to check if the requested image is in a directory safely accessible by our app.
boolean fileIsInSafeDirectories =
mPath.startsWith(mContext.getCacheDir().getPath()) || mPath.startsWith(mContext.getFilesDir().getPath());
if (!fileIsInSafeDirectories) {
mPromise.reject(ERROR_TAG, "The image has to be in the local app's directories.");
cancel(true);
return;
}
if(!new File(mPath).exists()) {
mPromise.reject(ERROR_TAG, "The file does not exist. Given path: `" + mPath + "`.");
cancel(true);
}
}
@Override
protected Void doInBackground(Void... voids) {
if (isCancelled()) {
return null;
}
mRNFaceDetector = detectorForOptions(mOptions, mContext);
try {
ExifInterface exif = new ExifInterface(mPath);
mOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
} catch (IOException e) {
Log.e(ERROR_TAG, "Reading orientation from file `" + mPath + "` failed.", e);
}
try {
FirebaseVisionImage image = FirebaseVisionImage.fromFilePath(mContext, Uri.parse(mUri));
FirebaseVisionFaceDetector detector = mRNFaceDetector.getDetector();
detector.detectInImage(image)
.addOnSuccessListener(
new OnSuccessListener<List<FirebaseVisionFace>>() {
@Override
public void onSuccess(List<FirebaseVisionFace> faces) {
serializeEventData(faces);
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e(ERROR_TAG, "Text recognition task failed", e);
mPromise.reject(ERROR_TAG, "Text recognition task failed", e);
}
});
} catch (IOException e) {
e.printStackTrace();
Log.e(ERROR_TAG, "Creating Firebase Image from uri" + mUri + "failed", e);
mPromise.reject(ERROR_TAG, "Creating Firebase Image from uri" + mUri + "failed", e);
}
return null;
}
private void serializeEventData(List<FirebaseVisionFace> faces) {
WritableMap result = Arguments.createMap();
WritableArray facesArray = Arguments.createArray();
for(FirebaseVisionFace face : faces) {
WritableMap encodedFace = FaceDetectorUtils.serializeFace(face);
encodedFace.putDouble("yawAngle", (-encodedFace.getDouble("yawAngle") + 360) % 360);
encodedFace.putDouble("rollAngle", (-encodedFace.getDouble("rollAngle") + 360) % 360);
facesArray.pushMap(encodedFace);
}
result.putArray("faces", facesArray);
WritableMap image = Arguments.createMap();
image.putInt("width", mWidth);
image.putInt("height", mHeight);
image.putInt("orientation", mOrientation);
image.putString("uri", mUri);
result.putMap("image", image);
mRNFaceDetector.release();
mPromise.resolve(result);
}
private static RNFaceDetector detectorForOptions(ReadableMap options, Context context) {
RNFaceDetector detector = new RNFaceDetector(context);
detector.setTrackingEnabled(false);
if(options.hasKey(MODE_OPTION_KEY)) {
detector.setMode(options.getInt(MODE_OPTION_KEY));
}
if(options.hasKey(RUN_CLASSIFICATIONS_OPTION_KEY)) {
detector.setClassificationType(options.getInt(RUN_CLASSIFICATIONS_OPTION_KEY));
}
if(options.hasKey(DETECT_LANDMARKS_OPTION_KEY)) {
detector.setLandmarkType(options.getInt(DETECT_LANDMARKS_OPTION_KEY));
}
return detector;
}
}

View File

@ -1,28 +1,476 @@
/* eslint-disable no-console */
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Slider } from 'react-native';
// eslint-disable-next-line import/no-unresolved
import { RNCamera } from 'react-native-camera';
// react-navigation
import { createStackNavigator, createAppContainer } from 'react-navigation';
const flashModeOrder = {
off: 'on',
on: 'auto',
auto: 'torch',
torch: 'off',
};
import MainScreen from './MainScreen';
import CameraScreen from './CameraScreen';
import BarcodeScannerScreen from './BarcodeScannerScreen';
const wbOrder = {
auto: 'sunny',
sunny: 'cloudy',
cloudy: 'shadow',
shadow: 'fluorescent',
fluorescent: 'incandescent',
incandescent: 'auto',
};
const AppNavigator = createStackNavigator(
{
Home: MainScreen,
Camera: CameraScreen,
BarcodeScanner: BarcodeScannerScreen,
},
{
initialRouteName: 'Home',
},
);
const landmarkSize = 2;
const AppContainer = createAppContainer(AppNavigator);
export default class CameraScreen extends React.Component {
state = {
flash: 'off',
zoom: 0,
autoFocus: 'on',
depth: 0,
type: 'back',
whiteBalance: 'auto',
ratio: '16:9',
recordOptions: {
mute: false,
maxDuration: 5,
quality: RNCamera.Constants.VideoQuality['288p'],
},
isRecording: false,
canDetectFaces: false,
canDetectText: false,
canDetectBarcode: false,
faces: [],
textBlocks: [],
barcodes: [],
};
toggleFacing() {
this.setState({
type: this.state.type === 'back' ? 'front' : 'back',
});
}
toggleFlash() {
this.setState({
flash: flashModeOrder[this.state.flash],
});
}
toggleWB() {
this.setState({
whiteBalance: wbOrder[this.state.whiteBalance],
});
}
toggleFocus() {
this.setState({
autoFocus: this.state.autoFocus === 'on' ? 'off' : 'on',
});
}
zoomOut() {
this.setState({
zoom: this.state.zoom - 0.1 < 0 ? 0 : this.state.zoom - 0.1,
});
}
zoomIn() {
this.setState({
zoom: this.state.zoom + 0.1 > 1 ? 1 : this.state.zoom + 0.1,
});
}
setFocusDepth(depth) {
this.setState({
depth,
});
}
takePicture = async function() {
if (this.camera) {
const data = await this.camera.takePictureAsync();
console.warn('takePicture ', data);
}
};
takeVideo = async function() {
if (this.camera) {
try {
const promise = this.camera.recordAsync(this.state.recordOptions);
if (promise) {
this.setState({ isRecording: true });
const data = await promise;
this.setState({ isRecording: false });
console.warn('takeVideo', data);
}
} catch (e) {
console.error(e);
}
}
};
toggle = value => () => this.setState(prevState => ({ [value]: !prevState[value] }));
facesDetected = ({ faces }) => this.setState({ faces });
renderFace = ({ bounds, faceID, rollAngle, yawAngle }) => (
<View
key={faceID}
transform={[
{ perspective: 600 },
{ rotateZ: `${rollAngle.toFixed(0)}deg` },
{ rotateY: `${yawAngle.toFixed(0)}deg` },
]}
style={[
styles.face,
{
...bounds.size,
left: bounds.origin.x,
top: bounds.origin.y,
},
]}
>
<Text style={styles.faceText}>ID: {faceID}</Text>
<Text style={styles.faceText}>rollAngle: {rollAngle.toFixed(0)}</Text>
<Text style={styles.faceText}>yawAngle: {yawAngle.toFixed(0)}</Text>
</View>
);
renderLandmarksOfFace(face) {
const renderLandmark = position =>
position && (
<View
style={[
styles.landmark,
{
left: position.x - landmarkSize / 2,
top: position.y - landmarkSize / 2,
},
]}
/>
);
return (
<View key={`landmarks-${face.faceID}`}>
{renderLandmark(face.leftEyePosition)}
{renderLandmark(face.rightEyePosition)}
{renderLandmark(face.leftEarPosition)}
{renderLandmark(face.rightEarPosition)}
{renderLandmark(face.leftCheekPosition)}
{renderLandmark(face.rightCheekPosition)}
{renderLandmark(face.leftMouthPosition)}
{renderLandmark(face.mouthPosition)}
{renderLandmark(face.rightMouthPosition)}
{renderLandmark(face.noseBasePosition)}
{renderLandmark(face.bottomMouthPosition)}
</View>
);
}
renderFaces = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.faces.map(this.renderFace)}
</View>
);
renderLandmarks = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.faces.map(this.renderLandmarksOfFace)}
</View>
);
renderTextBlocks = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.textBlocks.map(this.renderTextBlock)}
</View>
);
renderTextBlock = ({ bounds, value }) => (
<React.Fragment key={value + bounds.origin.x}>
<Text style={[styles.textBlock, { left: bounds.origin.x, top: bounds.origin.y }]}>
{value}
</Text>
<View
style={[
styles.text,
{
...bounds.size,
left: bounds.origin.x,
top: bounds.origin.y,
},
]}
/>
</React.Fragment>
);
textRecognized = object => {
const { textBlocks } = object;
this.setState({ textBlocks });
};
barcodeRecognized = ({ barcodes }) => this.setState({ barcodes });
renderBarcodes = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.barcodes.map(this.renderBarcode)}
</View>
);
renderBarcode = ({ bounds, data, type }) => (
<React.Fragment key={data + bounds.origin.x}>
<View
style={[
styles.text,
{
...bounds.size,
left: bounds.origin.x,
top: bounds.origin.y,
},
]}
>
<Text style={[styles.textBlock]}>{`${data} ${type}`}</Text>
</View>
</React.Fragment>
);
renderCamera() {
const { canDetectFaces, canDetectText, canDetectBarcode } = this.state;
return (
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={{
flex: 1,
}}
type={this.state.type}
flashMode={this.state.flash}
autoFocus={this.state.autoFocus}
zoom={this.state.zoom}
whiteBalance={this.state.whiteBalance}
ratio={this.state.ratio}
focusDepth={this.state.depth}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
faceDetectionLandmarks={
RNCamera.Constants.FaceDetection.Landmarks
? RNCamera.Constants.FaceDetection.Landmarks.all
: null
}
onFacesDetected={canDetectFaces ? this.facesDetected : null}
onTextRecognized={canDetectText ? this.textRecognized : null}
onGoogleVisionBarcodesDetected={canDetectBarcode ? this.barcodeRecognized : null}
>
<View
style={{
flex: 0.5,
}}
>
<View
style={{
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'space-around',
}}
>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleFacing.bind(this)}>
<Text style={styles.flipText}> FLIP </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleFlash.bind(this)}>
<Text style={styles.flipText}> FLASH: {this.state.flash} </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleWB.bind(this)}>
<Text style={styles.flipText}> WB: {this.state.whiteBalance} </Text>
</TouchableOpacity>
</View>
<View
style={{
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'space-around',
}}
>
<TouchableOpacity onPress={this.toggle('canDetectFaces')} style={styles.flipButton}>
<Text style={styles.flipText}>
{!canDetectFaces ? 'Detect Faces' : 'Detecting Faces'}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.toggle('canDetectText')} style={styles.flipButton}>
<Text style={styles.flipText}>
{!canDetectText ? 'Detect Text' : 'Detecting Text'}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.toggle('canDetectBarcode')} style={styles.flipButton}>
<Text style={styles.flipText}>
{!canDetectBarcode ? 'Detect Barcode' : 'Detecting Barcode'}
</Text>
</TouchableOpacity>
</View>
</View>
<View
style={{
flex: 0.4,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<Slider
style={{ width: 150, marginTop: 15, alignSelf: 'flex-end' }}
onValueChange={this.setFocusDepth.bind(this)}
step={0.1}
disabled={this.state.autoFocus === 'on'}
/>
</View>
<View
style={{
flex: 0.1,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<TouchableOpacity
style={[
styles.flipButton,
{
flex: 0.3,
alignSelf: 'flex-end',
backgroundColor: this.state.isRecording ? 'white' : 'darkred',
},
]}
onPress={this.state.isRecording ? () => {} : this.takeVideo.bind(this)}
>
{this.state.isRecording ? (
<Text style={styles.flipText}> </Text>
) : (
<Text style={styles.flipText}> REC </Text>
)}
</TouchableOpacity>
</View>
{this.state.zoom !== 0 && (
<Text style={[styles.flipText, styles.zoomText]}>Zoom: {this.state.zoom}</Text>
)}
<View
style={{
flex: 0.1,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.1, alignSelf: 'flex-end' }]}
onPress={this.zoomIn.bind(this)}
>
<Text style={styles.flipText}> + </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.1, alignSelf: 'flex-end' }]}
onPress={this.zoomOut.bind(this)}
>
<Text style={styles.flipText}> - </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.25, alignSelf: 'flex-end' }]}
onPress={this.toggleFocus.bind(this)}
>
<Text style={styles.flipText}> AF : {this.state.autoFocus} </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, styles.picButton, { flex: 0.3, alignSelf: 'flex-end' }]}
onPress={this.takePicture.bind(this)}
>
<Text style={styles.flipText}> SNAP </Text>
</TouchableOpacity>
</View>
{!!canDetectFaces && this.renderFaces()}
{!!canDetectFaces && this.renderLandmarks()}
{!!canDetectText && this.renderTextBlocks()}
{!!canDetectBarcode && this.renderBarcodes()}
</RNCamera>
);
}
export default class App extends React.Component {
render() {
return <AppContainer />;
return <View style={styles.container}>{this.renderCamera()}</View>;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
backgroundColor: '#000',
},
flipButton: {
flex: 0.3,
height: 40,
marginHorizontal: 2,
marginBottom: 10,
marginTop: 10,
borderRadius: 8,
borderColor: 'white',
borderWidth: 1,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
},
flipText: {
color: 'white',
fontSize: 15,
},
zoomText: {
position: 'absolute',
bottom: 70,
zIndex: 2,
left: 2,
},
picButton: {
backgroundColor: 'darkseagreen',
},
facesContainer: {
position: 'absolute',
bottom: 0,
right: 0,
left: 0,
top: 0,
},
face: {
padding: 10,
borderWidth: 2,
borderRadius: 2,
position: 'absolute',
borderColor: '#FFD700',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
landmark: {
width: landmarkSize,
height: landmarkSize,
position: 'absolute',
backgroundColor: 'red',
},
faceText: {
color: '#FFD700',
fontWeight: 'bold',
textAlign: 'center',
margin: 10,
backgroundColor: 'transparent',
},
text: {
padding: 10,
borderWidth: 2,
borderRadius: 2,
position: 'absolute',
borderColor: '#F00',
justifyContent: 'center',
},
textBlock: {
color: '#F00',
position: 'absolute',
textAlign: 'center',
backgroundColor: 'transparent',
},
});

View File

@ -1,117 +0,0 @@
'use strict';
// react
import React, { Component } from 'react';
import { StyleSheet, Dimensions, View, Text, Vibration } from 'react-native';
import { RNCamera } from 'react-native-camera';
export default class BarcodeScannerScreen extends React.Component {
static navigationOptions = {
title: 'Barcode Scanner',
};
state = {
barcode: '',
};
constructor(props) {
super(props);
let { width } = Dimensions.get('window');
this.maskLength = (width * 75) / 100;
}
_onBarCodeRead = event => {
console.log(JSON.stringify(event));
Vibration.vibrate(250);
this.setState({ barcode: event.data });
};
_onGoogleVisionBarCodeRead = event => {
console.log(JSON.stringify(event));
const barcodes = event.barcodes;
for (let i = 0; i < barcodes.length; i++) {
const barcode = barcodes[i].data;
if (this.state.barcode !== barcode) {
Vibration.vibrate(250);
this.setState({ barcode: barcode });
break;
}
}
};
render() {
return (
<View style={styles.container}>
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
type={RNCamera.Constants.Type.back}
autoFocus={RNCamera.Constants.AutoFocus.on}
defaultTouchToFocus
mirrorImage={false}
captureAudio={false}
// onBarCodeRead={this._onBarCodeRead}
googleVisionBarcodeDetectorEnabled={true}
onGoogleVisionBarcodesDetected={this._onGoogleVisionBarCodeRead}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'Allow this app to access camera in order to scan barcode.'}
>
<View style={styles.overlay} />
<View style={[styles.overlayContentRow, { height: this.maskLength / 2 }]}>
<View style={styles.overlay} />
<View
style={[
styles.overlayContent,
{ width: this.maskLength, height: this.maskLength / 2 },
]}
/>
<View style={styles.overlay} />
</View>
<View style={styles.overlay} />
</RNCamera>
<View style={styles.bottomContainer}>
<Text style={styles.text}>{this.state.barcode}</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
flexDirection: 'column',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
},
overlay: {
flex: 1,
},
overlayContentRow: {
flexDirection: 'row',
},
overlayContent: {
borderWidth: 3,
borderColor: 'red',
alignItems: 'center',
},
bottomContainer: {
flex: 0,
height: 80,
justifyContent: 'center',
},
text: {
alignSelf: 'stretch',
textAlign: 'center',
padding: 10,
color: 'gray',
backgroundColor: 'white',
},
});

View File

@ -1,261 +0,0 @@
/* eslint-disable no-console */
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Slider } from 'react-native';
// eslint-disable-next-line import/no-unresolved
import { RNCamera } from 'react-native-camera';
const flashModeOrder = {
off: 'on',
on: 'auto',
auto: 'torch',
torch: 'off',
};
const wbOrder = {
auto: 'sunny',
sunny: 'cloudy',
cloudy: 'shadow',
shadow: 'fluorescent',
fluorescent: 'incandescent',
incandescent: 'auto',
};
export default class CameraScreen extends React.Component {
state = {
flash: 'off',
zoom: 0,
autoFocus: 'on',
depth: 0,
type: 'back',
whiteBalance: 'auto',
ratio: '16:9',
recordOptions: {
mute: false,
maxDuration: 5,
quality: RNCamera.Constants.VideoQuality['288p'],
},
isRecording: false,
};
toggleFacing() {
this.setState({
type: this.state.type === 'back' ? 'front' : 'back',
});
}
toggleFlash() {
this.setState({
flash: flashModeOrder[this.state.flash],
});
}
toggleWB() {
this.setState({
whiteBalance: wbOrder[this.state.whiteBalance],
});
}
toggleFocus() {
this.setState({
autoFocus: this.state.autoFocus === 'on' ? 'off' : 'on',
});
}
zoomOut() {
this.setState({
zoom: this.state.zoom - 0.1 < 0 ? 0 : this.state.zoom - 0.1,
});
}
zoomIn() {
this.setState({
zoom: this.state.zoom + 0.1 > 1 ? 1 : this.state.zoom + 0.1,
});
}
setFocusDepth(depth) {
this.setState({
depth,
});
}
takePicture = async function() {
if (this.camera) {
const data = await this.camera.takePictureAsync();
console.warn('takePicture ', data);
}
};
takeVideo = async function() {
if (this.camera) {
try {
const promise = this.camera.recordAsync(this.state.recordOptions);
if (promise) {
this.setState({ isRecording: true });
const data = await promise;
this.setState({ isRecording: false });
console.warn('takeVideo', data);
}
} catch (e) {
console.error(e);
}
}
};
renderCamera() {
return (
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={{
flex: 1,
}}
type={this.state.type}
flashMode={this.state.flash}
autoFocus={this.state.autoFocus}
zoom={this.state.zoom}
whiteBalance={this.state.whiteBalance}
ratio={this.state.ratio}
focusDepth={this.state.depth}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
>
<View
style={{
flex: 0.5,
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'space-around',
}}
>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleFacing.bind(this)}>
<Text style={styles.flipText}> FLIP </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleFlash.bind(this)}>
<Text style={styles.flipText}> FLASH: {this.state.flash} </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleWB.bind(this)}>
<Text style={styles.flipText}> WB: {this.state.whiteBalance} </Text>
</TouchableOpacity>
</View>
<View
style={{
flex: 0.4,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<Slider
style={{ width: 150, marginTop: 15, alignSelf: 'flex-end' }}
onValueChange={this.setFocusDepth.bind(this)}
step={0.1}
disabled={this.state.autoFocus === 'on'}
/>
</View>
<View
style={{
flex: 0.1,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<TouchableOpacity
style={[
styles.flipButton,
{
flex: 0.3,
alignSelf: 'flex-end',
backgroundColor: this.state.isRecording ? 'white' : 'darkred',
},
]}
onPress={this.state.isRecording ? () => {} : this.takeVideo.bind(this)}
>
{this.state.isRecording ? (
<Text style={styles.flipText}> </Text>
) : (
<Text style={styles.flipText}> REC </Text>
)}
</TouchableOpacity>
</View>
{this.state.zoom !== 0 && (
<Text style={[styles.flipText, styles.zoomText]}>Zoom: {this.state.zoom}</Text>
)}
<View
style={{
flex: 0.1,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.1, alignSelf: 'flex-end' }]}
onPress={this.zoomIn.bind(this)}
>
<Text style={styles.flipText}> + </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.1, alignSelf: 'flex-end' }]}
onPress={this.zoomOut.bind(this)}
>
<Text style={styles.flipText}> - </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.25, alignSelf: 'flex-end' }]}
onPress={this.toggleFocus.bind(this)}
>
<Text style={styles.flipText}> AF : {this.state.autoFocus} </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, styles.picButton, { flex: 0.3, alignSelf: 'flex-end' }]}
onPress={this.takePicture.bind(this)}
>
<Text style={styles.flipText}> SNAP </Text>
</TouchableOpacity>
</View>
</RNCamera>
);
}
render() {
return <View style={styles.container}>{this.renderCamera()}</View>;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
backgroundColor: '#000',
},
flipButton: {
flex: 0.3,
height: 40,
marginHorizontal: 2,
marginBottom: 10,
marginTop: 20,
borderRadius: 8,
borderColor: 'white',
borderWidth: 1,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
},
flipText: {
color: 'white',
fontSize: 15,
},
zoomText: {
position: 'absolute',
bottom: 70,
zIndex: 2,
left: 2,
},
picButton: {
backgroundColor: 'darkseagreen',
},
});

View File

@ -1,58 +0,0 @@
/* eslint-disable no-console */
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Slider } from 'react-native';
export default class MainScreen extends React.Component {
static navigationOptions = {
title: 'React Native Camera',
};
_navigateToCameraScreen() {
this.props.navigation.navigate('Camera');
}
_navigateToBarcodeScannerScreen() {
this.props.navigation.navigate('BarcodeScanner');
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.button} onPress={this._navigateToCameraScreen.bind(this)}>
<Text style={styles.text}> Camera </Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={this._navigateToBarcodeScannerScreen.bind(this)}
>
<Text style={styles.text}> Barcode Scanner </Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingLeft: 20,
paddingRight: 20,
paddingBottom: 20,
backgroundColor: '#fff',
flexDirection: 'column',
},
button: {
flexDirection: 'row',
height: 60,
marginTop: 20,
borderRadius: 8,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'gray',
},
text: {
color: 'white',
fontSize: 15,
},
});

View File

@ -103,6 +103,7 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
missingDimensionStrategy 'react-native-camera', 'general'
ndk {
abiFilters "armeabi-v7a", "x86"
}
@ -137,7 +138,6 @@ android {
}
dependencies {
implementation project(':react-native-gesture-handler')
implementation project(':react-native-camera')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:23.0.1"

View File

@ -1,9 +1,6 @@
package com.rncameraexample;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
@ -15,14 +12,4 @@ public class MainActivity extends ReactActivity {
protected String getMainComponentName() {
return "RNCameraExample";
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}

View File

@ -3,7 +3,6 @@ package com.rncameraexample;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import org.reactnative.camera.RNCameraPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
@ -25,7 +24,6 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNGestureHandlerPackage(),
new RNCameraPackage()
);
}

View File

@ -1,6 +1,4 @@
rootProject.name = 'RNCameraExample'
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../../../android')

View File

@ -37,7 +37,6 @@
71169F7C2024F47400B79C53 /* libRNCamera.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 71169F7B2024F45100B79C53 /* libRNCamera.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; };
E240F68981B541E8BF76E057 /* libRNGestureHandler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 67CE77CC08464F1E9D5E8C16 /* libRNGestureHandler.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -350,8 +349,6 @@
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
90F54F19B2794F92AD4AE001 /* RNGestureHandler.xcodeproj */ = {isa = PBXFileReference; name = "RNGestureHandler.xcodeproj"; path = "../node_modules/react-native-gesture-handler/ios/RNGestureHandler.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
67CE77CC08464F1E9D5E8C16 /* libRNGestureHandler.a */ = {isa = PBXFileReference; name = "libRNGestureHandler.a"; path = "libRNGestureHandler.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -381,7 +378,6 @@
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
E240F68981B541E8BF76E057 /* libRNGestureHandler.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -568,7 +564,6 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
90F54F19B2794F92AD4AE001 /* RNGestureHandler.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@ -1204,15 +1199,12 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
);
INFOPLIST_FILE = RNCameraExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
@ -1234,15 +1226,12 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
);
INFOPLIST_FILE = RNCameraExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
@ -1267,7 +1256,6 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../../../ios/**",
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
);
INFOPLIST_FILE = RNCameraExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@ -1295,7 +1283,6 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../../../ios/**",
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
);
INFOPLIST_FILE = RNCameraExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@ -1326,14 +1313,11 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
);
INFOPLIST_FILE = "RNCameraExample-tvOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
@ -1362,14 +1346,11 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
);
INFOPLIST_FILE = "RNCameraExample-tvOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = (
"-ObjC",
@ -1398,8 +1379,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.RNCameraExample-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -1424,8 +1403,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.RNCameraExample-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@ -5,9 +5,7 @@
"@babel/runtime": "^7.1.2",
"babel": "^6.23.0",
"react": "16.5.0",
"react-native": "0.57.1",
"react-native-gesture-handler": "^1.0.15",
"react-navigation": "^3.1.4"
"react-native": "0.57.1"
},
"devDependencies": {
"babel-jest": "23.6.0",

View File

@ -11,6 +11,6 @@ const reactNativeCameraRoot = path.resolve(__dirname, '..', '..');
module.exports = {
watchFolders: [path.resolve(__dirname, 'node_modules'), reactNativeCameraRoot],
resolver: {
blacklistRE: blacklist([new RegExp(`${reactNativeCameraRoot}/node_modules/react-native/.*`)]),
blacklistRE: blacklist([new RegExp(`${reactNativeCameraRoot}/examples/mlkit/.*`), new RegExp(`${reactNativeCameraRoot}/node_modules/react-native/.*`)]),
},
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
[android]
target = Google Inc.:Google APIs:23
[maven_repositories]
central = https://repo1.maven.org/maven2

View File

@ -0,0 +1,70 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js
; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/
; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*
; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js
; Ignore polyfills
.*/Libraries/polyfills/.*
; Ignore metro
.*/node_modules/metro/.*
[include]
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/
[options]
emoji=true
esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable
module.system=haste
module.system.haste.use_name_reducers=true
# get basename
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
# strip .js or .js.flow suffix
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
# strip .ios suffix
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
munge_underscores=true
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js
suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
[version]
^0.86.0

1
examples/mlkit/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.pbxproj -text

58
examples/mlkit/.gitignore vendored Normal file
View File

@ -0,0 +1,58 @@
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# BUCK
buck-out/
\.buckd/
*.keystore
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
# Bundle artifact
*.jsbundle
examples/mlkit/ios/Pods

View File

@ -0,0 +1 @@
{}

476
examples/mlkit/App.js Normal file
View File

@ -0,0 +1,476 @@
/* eslint-disable no-console */
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Slider } from 'react-native';
// eslint-disable-next-line import/no-unresolved
import { RNCamera } from 'react-native-camera';
const flashModeOrder = {
off: 'on',
on: 'auto',
auto: 'torch',
torch: 'off',
};
const wbOrder = {
auto: 'sunny',
sunny: 'cloudy',
cloudy: 'shadow',
shadow: 'fluorescent',
fluorescent: 'incandescent',
incandescent: 'auto',
};
const landmarkSize = 2;
export default class CameraScreen extends React.Component {
state = {
flash: 'off',
zoom: 0,
autoFocus: 'on',
depth: 0,
type: 'back',
whiteBalance: 'auto',
ratio: '16:9',
recordOptions: {
mute: false,
maxDuration: 5,
quality: RNCamera.Constants.VideoQuality['288p'],
},
isRecording: false,
canDetectFaces: false,
canDetectText: false,
canDetectBarcode: false,
faces: [],
textBlocks: [],
barcodes: [],
};
toggleFacing() {
this.setState({
type: this.state.type === 'back' ? 'front' : 'back',
});
}
toggleFlash() {
this.setState({
flash: flashModeOrder[this.state.flash],
});
}
toggleWB() {
this.setState({
whiteBalance: wbOrder[this.state.whiteBalance],
});
}
toggleFocus() {
this.setState({
autoFocus: this.state.autoFocus === 'on' ? 'off' : 'on',
});
}
zoomOut() {
this.setState({
zoom: this.state.zoom - 0.1 < 0 ? 0 : this.state.zoom - 0.1,
});
}
zoomIn() {
this.setState({
zoom: this.state.zoom + 0.1 > 1 ? 1 : this.state.zoom + 0.1,
});
}
setFocusDepth(depth) {
this.setState({
depth,
});
}
takePicture = async function() {
if (this.camera) {
const data = await this.camera.takePictureAsync();
console.warn('takePicture ', data);
}
};
takeVideo = async function() {
if (this.camera) {
try {
const promise = this.camera.recordAsync(this.state.recordOptions);
if (promise) {
this.setState({ isRecording: true });
const data = await promise;
this.setState({ isRecording: false });
console.warn('takeVideo', data);
}
} catch (e) {
console.error(e);
}
}
};
toggle = value => () => this.setState(prevState => ({ [value]: !prevState[value] }));
facesDetected = ({ faces }) => this.setState({ faces });
renderFace = ({ bounds, faceID, rollAngle, yawAngle }) => (
<View
key={faceID}
transform={[
{ perspective: 600 },
{ rotateZ: `${rollAngle.toFixed(0)}deg` },
{ rotateY: `${yawAngle.toFixed(0)}deg` },
]}
style={[
styles.face,
{
...bounds.size,
left: bounds.origin.x,
top: bounds.origin.y,
},
]}
>
<Text style={styles.faceText}>ID: {faceID}</Text>
<Text style={styles.faceText}>rollAngle: {rollAngle.toFixed(0)}</Text>
<Text style={styles.faceText}>yawAngle: {yawAngle.toFixed(0)}</Text>
</View>
);
renderLandmarksOfFace(face) {
const renderLandmark = position =>
position && (
<View
style={[
styles.landmark,
{
left: position.x - landmarkSize / 2,
top: position.y - landmarkSize / 2,
},
]}
/>
);
return (
<View key={`landmarks-${face.faceID}`}>
{renderLandmark(face.leftEyePosition)}
{renderLandmark(face.rightEyePosition)}
{renderLandmark(face.leftEarPosition)}
{renderLandmark(face.rightEarPosition)}
{renderLandmark(face.leftCheekPosition)}
{renderLandmark(face.rightCheekPosition)}
{renderLandmark(face.leftMouthPosition)}
{renderLandmark(face.mouthPosition)}
{renderLandmark(face.rightMouthPosition)}
{renderLandmark(face.noseBasePosition)}
{renderLandmark(face.bottomMouthPosition)}
</View>
);
}
renderFaces = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.faces.map(this.renderFace)}
</View>
);
renderLandmarks = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.faces.map(this.renderLandmarksOfFace)}
</View>
);
renderTextBlocks = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.textBlocks.map(this.renderTextBlock)}
</View>
);
renderTextBlock = ({ bounds, value }) => (
<React.Fragment key={value + bounds.origin.x}>
<Text style={[styles.textBlock, { left: bounds.origin.x, top: bounds.origin.y }]}>
{value}
</Text>
<View
style={[
styles.text,
{
...bounds.size,
left: bounds.origin.x,
top: bounds.origin.y,
},
]}
/>
</React.Fragment>
);
textRecognized = object => {
const { textBlocks } = object;
this.setState({ textBlocks });
};
barcodeRecognized = ({ barcodes }) => this.setState({ barcodes });
renderBarcodes = () => (
<View style={styles.facesContainer} pointerEvents="none">
{this.state.barcodes.map(this.renderBarcode)}
</View>
);
renderBarcode = ({ bounds, data, type }) => (
<React.Fragment key={data + bounds.origin.x}>
<View
style={[
styles.text,
{
...bounds.size,
left: bounds.origin.x,
top: bounds.origin.y,
},
]}
>
<Text style={[styles.textBlock]}>{`${data} ${type}`}</Text>
</View>
</React.Fragment>
);
renderCamera() {
const { canDetectFaces, canDetectText, canDetectBarcode } = this.state;
return (
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={{
flex: 1,
}}
type={this.state.type}
flashMode={this.state.flash}
autoFocus={this.state.autoFocus}
zoom={this.state.zoom}
whiteBalance={this.state.whiteBalance}
ratio={this.state.ratio}
focusDepth={this.state.depth}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
faceDetectionLandmarks={
RNCamera.Constants.FaceDetection.Landmarks
? RNCamera.Constants.FaceDetection.Landmarks.all
: null
}
onFacesDetected={canDetectFaces ? this.facesDetected : null}
onTextRecognized={canDetectText ? this.textRecognized : null}
onGoogleVisionBarcodesDetected={canDetectBarcode ? this.barcodeRecognized : null}
>
<View
style={{
flex: 0.5,
}}
>
<View
style={{
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'space-around',
}}
>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleFacing.bind(this)}>
<Text style={styles.flipText}> FLIP </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleFlash.bind(this)}>
<Text style={styles.flipText}> FLASH: {this.state.flash} </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.flipButton} onPress={this.toggleWB.bind(this)}>
<Text style={styles.flipText}> WB: {this.state.whiteBalance} </Text>
</TouchableOpacity>
</View>
<View
style={{
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'space-around',
}}
>
<TouchableOpacity onPress={this.toggle('canDetectFaces')} style={styles.flipButton}>
<Text style={styles.flipText}>
{!canDetectFaces ? 'Detect Faces' : 'Detecting Faces'}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.toggle('canDetectText')} style={styles.flipButton}>
<Text style={styles.flipText}>
{!canDetectText ? 'Detect Text' : 'Detecting Text'}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.toggle('canDetectBarcode')} style={styles.flipButton}>
<Text style={styles.flipText}>
{!canDetectBarcode ? 'Detect Barcode' : 'Detecting Barcode'}
</Text>
</TouchableOpacity>
</View>
</View>
<View
style={{
flex: 0.4,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<Slider
style={{ width: 150, marginTop: 15, alignSelf: 'flex-end' }}
onValueChange={this.setFocusDepth.bind(this)}
step={0.1}
disabled={this.state.autoFocus === 'on'}
/>
</View>
<View
style={{
flex: 0.1,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<TouchableOpacity
style={[
styles.flipButton,
{
flex: 0.3,
alignSelf: 'flex-end',
backgroundColor: this.state.isRecording ? 'white' : 'darkred',
},
]}
onPress={this.state.isRecording ? () => {} : this.takeVideo.bind(this)}
>
{this.state.isRecording ? (
<Text style={styles.flipText}> </Text>
) : (
<Text style={styles.flipText}> REC </Text>
)}
</TouchableOpacity>
</View>
{this.state.zoom !== 0 && (
<Text style={[styles.flipText, styles.zoomText]}>Zoom: {this.state.zoom}</Text>
)}
<View
style={{
flex: 0.1,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}
>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.1, alignSelf: 'flex-end' }]}
onPress={this.zoomIn.bind(this)}
>
<Text style={styles.flipText}> + </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.1, alignSelf: 'flex-end' }]}
onPress={this.zoomOut.bind(this)}
>
<Text style={styles.flipText}> - </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, { flex: 0.25, alignSelf: 'flex-end' }]}
onPress={this.toggleFocus.bind(this)}
>
<Text style={styles.flipText}> AF : {this.state.autoFocus} </Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.flipButton, styles.picButton, { flex: 0.3, alignSelf: 'flex-end' }]}
onPress={this.takePicture.bind(this)}
>
<Text style={styles.flipText}> SNAP </Text>
</TouchableOpacity>
</View>
{!!canDetectFaces && this.renderFaces()}
{!!canDetectFaces && this.renderLandmarks()}
{!!canDetectText && this.renderTextBlocks()}
{!!canDetectBarcode && this.renderBarcodes()}
</RNCamera>
);
}
render() {
return <View style={styles.container}>{this.renderCamera()}</View>;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
backgroundColor: '#000',
},
flipButton: {
flex: 0.3,
height: 40,
marginHorizontal: 2,
marginBottom: 10,
marginTop: 10,
borderRadius: 8,
borderColor: 'white',
borderWidth: 1,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
},
flipText: {
color: 'white',
fontSize: 15,
},
zoomText: {
position: 'absolute',
bottom: 70,
zIndex: 2,
left: 2,
},
picButton: {
backgroundColor: 'darkseagreen',
},
facesContainer: {
position: 'absolute',
bottom: 0,
right: 0,
left: 0,
top: 0,
},
face: {
padding: 10,
borderWidth: 2,
borderRadius: 2,
position: 'absolute',
borderColor: '#FFD700',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
landmark: {
width: landmarkSize,
height: landmarkSize,
position: 'absolute',
backgroundColor: 'red',
},
faceText: {
color: '#FFD700',
fontWeight: 'bold',
textAlign: 'center',
margin: 10,
backgroundColor: 'transparent',
},
text: {
padding: 10,
borderWidth: 2,
borderRadius: 2,
position: 'absolute',
borderColor: '#F00',
justifyContent: 'center',
},
textBlock: {
color: '#F00',
position: 'absolute',
textAlign: 'center',
backgroundColor: 'transparent',
},
});

32
examples/mlkit/README.md Normal file
View File

@ -0,0 +1,32 @@
# React Native Camera MLKit Example
An example project demonstrating the use of MLKit-based Text and Face Recognition features of react-native-camera.
### Features
Features of Basic Example + Face and Text Recognition.
Face Recognition: draws polygons around faces and red circles on top of face landmarks (ears, mouth, nose, etc.).
Text Recognition: draws polygons around text blocks and recognized within them.
### Setup
1. Run `yarn install`.
2. Create Firebase project, generate `google-services.json` and place it into `./android/app` folder, generate `GoogleService-Info.plist` and place it into `./ios/mlkit` folder.
3. Build project (you will likely need to manage signing if you are building for ios device)
### Contributing
- Pull Requests are welcome, if you open a pull request we will do our best to get to it in a timely manner
- Pull Request Reviews and even more welcome! we need help testing, reviewing, and updating open PRs
- If you are interested in contributing more actively, please contact me (same username on Twitter, Facebook, etc.) Thanks!
- If you want to help us coding, join Expo slack https://slack.expo.io/, so we can chat over there. (#react-native-camera)
### FAQ
## Why is `react-native-camera` not listed as a dependency in `package.json`?
`react-native` uses `metro` for dependency resolution. In order to not recursively install this example into the `node_modules` of this example we use `rn-cli.config.js` to resolve `react-native-camera`. This also allows a quicker iteration when developing (without having to `yarn install` after every single change in `react-native-camera`).

View File

@ -0,0 +1,15 @@
/**
* @format
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
renderer.create(<App />);
});

View File

@ -0,0 +1,55 @@
# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#
load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
lib_deps = []
create_aar_targets(glob(["libs/*.aar"]))
create_jar_targets(glob(["libs/*.jar"]))
android_library(
name = "all-libs",
exported_deps = lib_deps,
)
android_library(
name = "app-code",
srcs = glob([
"src/main/java/**/*.java",
]),
deps = [
":all-libs",
":build_config",
":res",
],
)
android_build_config(
name = "build_config",
package = "com.mlkit",
)
android_resource(
name = "res",
package = "com.mlkit",
res = "src/main/res",
)
android_binary(
name = "app",
keystore = "//android/keystores:debug",
manifest = "src/main/AndroidManifest.xml",
package_type = "debug",
deps = [
":app-code",
],
)

View File

@ -0,0 +1,155 @@
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.mlkit"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
missingDimensionStrategy 'react-native-camera', 'mlkit'
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
exclude 'META-INF/androidx.exifinterface_exifinterface.version'
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-camera')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'

View File

@ -0,0 +1,19 @@
"""Helper definitions to glob .aar and .jar targets"""
def create_aar_targets(aarfiles):
for aarfile in aarfiles:
name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")]
lib_deps.append(":" + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
def create_jar_targets(jarfiles):
for jarfile in jarfiles:
name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")]
lib_deps.append(":" + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)

View File

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -0,0 +1,31 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mlkit">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>

View File

@ -0,0 +1,15 @@
package com.mlkit;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "mlkit";
}
}

View File

@ -0,0 +1,48 @@
package com.mlkit;
import android.app.Application;
import org.reactnative.camera.RNCameraPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNCameraPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">mlkit</string>
</resources>

View File

@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -0,0 +1,40 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}

View File

@ -0,0 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

172
examples/mlkit/android/gradlew vendored Executable file
View File

@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

84
examples/mlkit/android/gradlew.bat vendored Normal file
View File

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,8 @@
keystore(
name = "debug",
properties = "debug.keystore.properties",
store = "debug.keystore",
visibility = [
"PUBLIC",
],
)

View File

@ -0,0 +1,4 @@
key.store=debug.keystore
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android

View File

@ -0,0 +1,5 @@
rootProject.name = 'mlkit'
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../../../android')
include ':app'

4
examples/mlkit/app.json Normal file
View File

@ -0,0 +1,4 @@
{
"name": "mlkit",
"displayName": "mlkit"
}

View File

@ -0,0 +1,3 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"]
}

10
examples/mlkit/index.js Normal file
View File

@ -0,0 +1,10 @@
/**
* @format
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);

View File

@ -0,0 +1,34 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'mlkit' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for mlkit
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'react-native-camera', path: '../../../', subspecs: [
'TextDetector',
# 'FaceDetector'
]
pod 'Firebase/Core'
end

View File

@ -0,0 +1,222 @@
PODS:
- boost-for-react-native (1.63.0)
- DoubleConversion (1.1.6)
- Firebase/Core (5.16.0):
- Firebase/CoreOnly
- FirebaseAnalytics (= 5.5.0)
- Firebase/CoreOnly (5.16.0):
- FirebaseCore (= 5.2.0)
- Firebase/MLVision (5.16.0):
- Firebase/CoreOnly
- FirebaseMLVision (= 0.14.0)
- Firebase/MLVisionTextModel (5.16.0):
- Firebase/CoreOnly
- FirebaseMLVisionTextModel (= 0.14.0)
- FirebaseAnalytics (5.5.0):
- FirebaseCore (~> 5.2)
- FirebaseInstanceID (~> 3.4)
- GoogleAppMeasurement (= 5.5.0)
- GoogleUtilities/AppDelegateSwizzler (~> 5.2)
- GoogleUtilities/MethodSwizzler (~> 5.2)
- GoogleUtilities/Network (~> 5.2)
- "GoogleUtilities/NSData+zlib (~> 5.2)"
- nanopb (~> 0.3)
- FirebaseCore (5.2.0):
- GoogleUtilities/Logger (~> 5.2)
- FirebaseInstanceID (3.4.0):
- FirebaseCore (~> 5.2)
- GoogleUtilities/Environment (~> 5.3)
- GoogleUtilities/UserDefaults (~> 5.3)
- FirebaseMLCommon (0.14.0):
- FirebaseCore (~> 5.2)
- FirebaseInstanceID (~> 3.4)
- GoogleUtilities/UserDefaults (~> 5.3)
- GTMSessionFetcher/Core (~> 1.1)
- FirebaseMLVision (0.14.0):
- FirebaseCore (~> 5.2)
- FirebaseMLCommon (~> 0.14)
- GoogleAPIClientForREST/Core (~> 1.3)
- GoogleAPIClientForREST/Vision (~> 1.3)
- GoogleMobileVision/Detector (~> 1.4)
- FirebaseMLVisionTextModel (0.14.0):
- GoogleMobileVision/TextDetector (~> 1.4)
- Folly (2018.10.22.00):
- boost-for-react-native
- DoubleConversion
- glog
- glog (0.3.5)
- GoogleAPIClientForREST/Core (1.3.8):
- GTMSessionFetcher (>= 1.1.7)
- GoogleAPIClientForREST/Vision (1.3.8):
- GoogleAPIClientForREST/Core
- GTMSessionFetcher (>= 1.1.7)
- GoogleAppMeasurement (5.5.0):
- GoogleUtilities/AppDelegateSwizzler (~> 5.2)
- GoogleUtilities/MethodSwizzler (~> 5.2)
- GoogleUtilities/Network (~> 5.2)
- "GoogleUtilities/NSData+zlib (~> 5.2)"
- nanopb (~> 0.3)
- GoogleMobileVision/Detector (1.5.0):
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- GTMSessionFetcher/Core (~> 1.1)
- Protobuf (~> 3.1)
- GoogleMobileVision/TextDetector (1.5.0):
- GoogleMobileVision/Detector (~> 1.5)
- GoogleToolboxForMac/Defines (2.2.0)
- GoogleToolboxForMac/Logger (2.2.0):
- GoogleToolboxForMac/Defines (= 2.2.0)
- "GoogleToolboxForMac/NSData+zlib (2.2.0)":
- GoogleToolboxForMac/Defines (= 2.2.0)
- GoogleUtilities/AppDelegateSwizzler (5.3.7):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (5.3.7)
- GoogleUtilities/Logger (5.3.7):
- GoogleUtilities/Environment
- GoogleUtilities/MethodSwizzler (5.3.7):
- GoogleUtilities/Logger
- GoogleUtilities/Network (5.3.7):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (5.3.7)"
- GoogleUtilities/Reachability (5.3.7):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (5.3.7):
- GoogleUtilities/Logger
- GTMSessionFetcher (1.2.1):
- GTMSessionFetcher/Full (= 1.2.1)
- GTMSessionFetcher/Core (1.2.1)
- GTMSessionFetcher/Full (1.2.1):
- GTMSessionFetcher/Core (= 1.2.1)
- nanopb (0.3.901):
- nanopb/decode (= 0.3.901)
- nanopb/encode (= 0.3.901)
- nanopb/decode (0.3.901)
- nanopb/encode (0.3.901)
- Protobuf (3.6.1)
- React (0.58.5):
- React/Core (= 0.58.5)
- react-native-camera/RCT (1.10.2):
- React
- react-native-camera/RN (1.10.2):
- React
- react-native-camera/TextDetector (1.10.2):
- Firebase/MLVision
- Firebase/MLVisionTextModel
- React
- react-native-camera/RCT
- react-native-camera/RN
- React/Core (0.58.5):
- yoga (= 0.58.5.React)
- React/CxxBridge (0.58.5):
- Folly (= 2018.10.22.00)
- React/Core
- React/cxxreact
- React/jsiexecutor
- React/cxxreact (0.58.5):
- boost-for-react-native (= 1.63.0)
- Folly (= 2018.10.22.00)
- React/jsinspector
- React/DevSupport (0.58.5):
- React/Core
- React/RCTWebSocket
- React/fishhook (0.58.5)
- React/jsi (0.58.5):
- Folly (= 2018.10.22.00)
- React/jsiexecutor (0.58.5):
- Folly (= 2018.10.22.00)
- React/cxxreact
- React/jsi
- React/jsinspector (0.58.5)
- React/RCTAnimation (0.58.5):
- React/Core
- React/RCTBlob (0.58.5):
- React/Core
- React/RCTNetwork (0.58.5):
- React/Core
- React/RCTText (0.58.5):
- React/Core
- React/RCTWebSocket (0.58.5):
- React/Core
- React/fishhook
- React/RCTBlob
- yoga (0.58.5.React)
DEPENDENCIES:
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- Firebase/Core
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- react-native-camera/TextDetector (from `../../../`)
- React/Core (from `../node_modules/react-native`)
- React/CxxBridge (from `../node_modules/react-native`)
- React/DevSupport (from `../node_modules/react-native`)
- React/RCTAnimation (from `../node_modules/react-native`)
- React/RCTNetwork (from `../node_modules/react-native`)
- React/RCTText (from `../node_modules/react-native`)
- React/RCTWebSocket (from `../node_modules/react-native`)
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)
SPEC REPOS:
https://github.com/cocoapods/specs.git:
- boost-for-react-native
- Firebase
- FirebaseAnalytics
- FirebaseCore
- FirebaseInstanceID
- FirebaseMLCommon
- FirebaseMLVision
- FirebaseMLVisionTextModel
- GoogleAPIClientForREST
- GoogleAppMeasurement
- GoogleMobileVision
- GoogleToolboxForMac
- GoogleUtilities
- GTMSessionFetcher
- nanopb
- Protobuf
EXTERNAL SOURCES:
DoubleConversion:
:podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
Folly:
:podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec"
glog:
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
React:
:path: "../node_modules/react-native"
react-native-camera:
:path: "../../../"
yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"
SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
DoubleConversion: bb338842f62ab1d708ceb63ec3d999f0f3d98ecd
Firebase: 749a8ff4962f9d8c79dda1966de20f6f77583d67
FirebaseAnalytics: d35d47c03c50c73c14a7fd31463c5775843e78a9
FirebaseCore: ea2d1816723ef21492b8e9113303e1350db5e08c
FirebaseInstanceID: 97ea7a5dca9afd72c79bfcdddb7a44aa1cbb42a1
FirebaseMLCommon: d8a789e36a7faa175b1a5d1139e7fc7323c8db7b
FirebaseMLVision: 07c0da3ceaa5ecde621528a985748d6098a84388
FirebaseMLVisionTextModel: c6b3bf6129cb97cba51f8f90e80b40a66228dfa1
Folly: de497beb10f102453a1afa9edbf8cf8a251890de
glog: aefd1eb5dda2ab95ba0938556f34b98e2da3a60d
GoogleAPIClientForREST: 5447a194eae517986cafe6421a5330b80b820591
GoogleAppMeasurement: 621f3bc6211d5ba548debe01fafad30cf5ab6859
GoogleMobileVision: a1f93108b3527d67339e2de80e1db76645f9e8b9
GoogleToolboxForMac: ff31605b7d66400dcec09bed5861689aebadda4d
GoogleUtilities: 111a012f4c3a29c9e7c954c082fafd6ee3c999c0
GTMSessionFetcher: 32aeca0aa144acea523e1c8e053089dec2cb98ca
nanopb: 2901f78ea1b7b4015c860c2fdd1ea2fee1a18d48
Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5
React: 16c4fb7ce3fc30c041bce809ceae33bf57e7c142
react-native-camera: 25e0f493dde6e15c814e734685934d55f46e45b2
yoga: 0885622311729a02c2bc02dca97167787a51488b
PODFILE CHECKSUM: 98276cee1420f380535215fe9e3a913b4f50e9a0
COCOAPODS: 1.5.3

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D2A28121D9B038B00D4039D"
BuildableName = "libReact.a"
BlueprintName = "React-tvOS"
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "mlkit-tvOS.app"
BlueprintName = "mlkit-tvOS"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
BuildableName = "mlkit-tvOSTests.xctest"
BlueprintName = "mlkit-tvOSTests"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
BuildableName = "mlkit-tvOSTests.xctest"
BlueprintName = "mlkit-tvOSTests"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "mlkit-tvOS.app"
BlueprintName = "mlkit-tvOS"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "mlkit-tvOS.app"
BlueprintName = "mlkit-tvOS"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "mlkit-tvOS.app"
BlueprintName = "mlkit-tvOS"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "83CBBA2D1A601D0E00E9B192"
BuildableName = "libReact.a"
BlueprintName = "React"
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "mlkit.app"
BlueprintName = "mlkit"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
BuildableName = "mlkitTests.xctest"
BlueprintName = "mlkitTests"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
BuildableName = "mlkitTests.xctest"
BlueprintName = "mlkitTests"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "mlkit.app"
BlueprintName = "mlkit"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "mlkit.app"
BlueprintName = "mlkit"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "mlkit.app"
BlueprintName = "mlkit"
ReferencedContainer = "container:mlkit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:mlkit.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@ -0,0 +1,14 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@end

View File

@ -0,0 +1,38 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import <Firebase.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
[FIRApp configure];
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"mlkit"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [UIColor blackColor];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="mlkit" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="548" y="455"/>
</view>
</objects>
</document>

View File

@ -0,0 +1,38 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>mlkit</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to show off</string>
<!-- Include this only if you are planning to use the camera roll -->
<key>NSPhotoLibraryUsageDescription</key>
<string>This app need library access so you can add pictures</string>
<!-- Include this only if you are planning to use the microphone for video recording -->
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone for video recording</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

Some files were not shown because too many files have changed in this diff Show More