Search in sources :

Example 1 with BarcodeScanner

use of com.google.mlkit.vision.barcode.BarcodeScanner 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)

Aggregations

WritableArray (com.facebook.react.bridge.WritableArray)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 Barcode (com.google.mlkit.vision.barcode.Barcode)1 BarcodeScanner (com.google.mlkit.vision.barcode.BarcodeScanner)1 InputImage (com.google.mlkit.vision.common.InputImage)1 List (java.util.List)1