MLKit BarCode Sanner Implementation results in internal error when executing ML Kit tasks

后端 未结 1 1455
[愿得一人]
[愿得一人] 2020-12-12 01:25

Every call to scanner.process(image) is resulting in the onFailure call, with the following error:

Error:com.google.mlkit.common.MlKitException: Internal

相关标签:
1条回答
  • 2020-12-12 01:45

    Inadvertently found the cause of the error by reading this. Adding an OnCompleteListener to the result Task and placing the imageProxy.close() inside, resolved this. i.e.:

    Errors

    Task<List<Barcode>> result = scanner.process(image);
    
    result.addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
        @Override
        public void onSuccess(List<Barcode> barcodes) {
            // Task completed successfully
            Log.i("CameraXApp3", "scanner task successful");
            processBarCodes(barcodes);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            // Task failed with an exception
            Log.i("CameraXApp3", "scanner task failed. Error:" + e);
    
        }
    });
    mediaImage.close();
    imageProxy.close();
    

    No Errors

    Task<List<Barcode>> result = scanner.process(image);
    
    result.addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
        @Override
        public void onSuccess(List<Barcode> barcodes) {
            // Task completed successfully
            Log.i("CameraXApp3", "scanner task successful");
            processBarCodes(barcodes);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            // Task failed with an exception
            Log.i("CameraXApp3", "scanner task failed. Error:" + e);
    
        }
    }).addOnCompleteListener(new OnCompleteListener<List<Barcode>>() {
        @Override
        public void onComplete(@NonNull Task<List<Barcode>> task) {
            mediaImage.close();
            imageProxy.close();
        }
    });
    

    Will wait to mark as answer in case @Hoi wants to grab the points, which he deserves. :)

    0 讨论(0)
提交回复
热议问题