Search in sources :

Example 11 with InputImage

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

the class TextRecognizerAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null) {
        return null;
    }
    TextRecognizer detector = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    detector.process(image).addOnSuccessListener(new OnSuccessListener<Text>() {

        @Override
        public void onSuccess(Text firebaseVisionText) {
            List<Text.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;
}
Also used : WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.mlkit.vision.text.Text) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) TextRecognizer(com.google.mlkit.vision.text.TextRecognizer) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 12 with InputImage

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

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)

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