Search in sources :

Example 6 with InputImage

use of com.google.mlkit.vision.common.InputImage in project react-native-camera by lwansbrough.

the class RNFrameFactory method buildFrame.

public static RNFrame buildFrame(byte[] bitmapData, int width, int height, int rotation) {
    ByteBuffer byteBuffer = ByteBuffer.wrap(bitmapData);
    ImageDimensions dimensions = new ImageDimensions(width, height, rotation);
    InputImage image = InputImage.fromByteBuffer(byteBuffer, width, height, rotation, InputImage.IMAGE_FORMAT_NV21);
    return new RNFrame(image, dimensions);
}
Also used : ImageDimensions(org.reactnative.camera.utils.ImageDimensions) ByteBuffer(java.nio.ByteBuffer) InputImage(com.google.mlkit.vision.common.InputImage)

Example 7 with InputImage

use of com.google.mlkit.vision.common.InputImage in project react-native-camera by lwansbrough.

the class FileFaceDetectionAsyncTask method doInBackground.

@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 {
        InputImage image = InputImage.fromFilePath(mContext, Uri.parse(mUri));
        FaceDetector detector = mRNFaceDetector.getDetector();
        detector.process(image).addOnSuccessListener(new OnSuccessListener<List<Face>>() {

            @Override
            public void onSuccess(List<Face> 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;
}
Also used : RNFaceDetector(org.reactnative.facedetector.RNFaceDetector) FaceDetector(com.google.mlkit.vision.face.FaceDetector) ExifInterface(androidx.exifinterface.media.ExifInterface) List(java.util.List) IOException(java.io.IOException) Face(com.google.mlkit.vision.face.Face) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IOException(java.io.IOException)

Example 8 with InputImage

use of com.google.mlkit.vision.common.InputImage in project react-native-camera by lwansbrough.

the class BarcodeDetectorAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null || mBarcodeDetector == null) {
        return null;
    }
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    BarcodeScanner barcode = mBarcodeDetector.getDetector();
    barcode.process(image).addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {

        @Override
        public void onSuccess(List<Barcode> barcodes) {
            WritableArray serializedBarcodes = serializeEventData(barcodes);
            mDelegate.onBarcodesDetected(serializedBarcodes, mWidth, mHeight, mImageData);
            mDelegate.onBarcodeDetectingTaskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "Text recognition task failed" + e);
            mDelegate.onBarcodeDetectingTaskCompleted();
        }
    });
    return null;
}
Also used : WritableArray(com.facebook.react.bridge.WritableArray) Barcode(com.google.mlkit.vision.barcode.Barcode) BarcodeScanner(com.google.mlkit.vision.barcode.BarcodeScanner) List(java.util.List) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 9 with InputImage

use of com.google.mlkit.vision.common.InputImage in project react-native-camera by lwansbrough.

the class RNFrameFactory method buildFrame.

public static RNFrame buildFrame(Bitmap bitmap) {
    ImageDimensions dimensions = new ImageDimensions(bitmap.getWidth(), bitmap.getHeight());
    InputImage image = InputImage.fromBitmap(bitmap, 0);
    return new RNFrame(image, dimensions);
}
Also used : ImageDimensions(org.reactnative.camera.utils.ImageDimensions) InputImage(com.google.mlkit.vision.common.InputImage)

Example 10 with InputImage

use of com.google.mlkit.vision.common.InputImage in project react-native-camera by react-native-community.

the class BarcodeDetectorAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null || mBarcodeDetector == null) {
        return null;
    }
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    BarcodeScanner barcode = mBarcodeDetector.getDetector();
    barcode.process(image).addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {

        @Override
        public void onSuccess(List<Barcode> barcodes) {
            WritableArray serializedBarcodes = serializeEventData(barcodes);
            mDelegate.onBarcodesDetected(serializedBarcodes, mWidth, mHeight, mImageData);
            mDelegate.onBarcodeDetectingTaskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "Text recognition task failed" + e);
            mDelegate.onBarcodeDetectingTaskCompleted();
        }
    });
    return null;
}
Also used : WritableArray(com.facebook.react.bridge.WritableArray) Barcode(com.google.mlkit.vision.barcode.Barcode) BarcodeScanner(com.google.mlkit.vision.barcode.BarcodeScanner) List(java.util.List) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

InputImage (com.google.mlkit.vision.common.InputImage)12 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)8 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)8 WritableArray (com.facebook.react.bridge.WritableArray)6 List (java.util.List)6 Face (com.google.mlkit.vision.face.Face)4 FaceDetector (com.google.mlkit.vision.face.FaceDetector)4 ImageDimensions (org.reactnative.camera.utils.ImageDimensions)4 RNFaceDetector (org.reactnative.facedetector.RNFaceDetector)4 ExifInterface (androidx.exifinterface.media.ExifInterface)2 Barcode (com.google.mlkit.vision.barcode.Barcode)2 BarcodeScanner (com.google.mlkit.vision.barcode.BarcodeScanner)2 Text (com.google.mlkit.vision.text.Text)2 TextRecognizer (com.google.mlkit.vision.text.TextRecognizer)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2