【问题标题】:Can't read barcodes contents with the new ML kit无法使用新的 ML 套件读取条形码内容
【发布时间】:2022-10-24 23:27:26
【问题描述】:

到目前为止,更新我的应用程序以使用新的 ML 套件进行条码扫描是失败的。我正在使用Camera2 API 并以这种方式处理我的图像:

imageToProcess = InputImage.fromMediaImage(image, 0);

Task<List<Barcode>> result = scannerCodeBarre.process(imageToProcess)
                    .addOnSuccessListener(codesBarres -> {
                         // my code to exploit the result given by the ML
                        }
                    })
                    .addOnFailureListener(e -> {
                        // my code to inform finding a barcode content failed
                    });

我可以补充说,只有在获得上一个处理图像的结果后,我才开始处理新图像,但无论预览图像包含 2D 还是 3D 条码,Task 总是触发它的onFailure 功能OnFailureListener

谁能告诉我我可能会错过什么?

【问题讨论】:

    标签: java android barcode google-mlkit


    【解决方案1】:

    测试以下代码。

    Task<List<Barcode>> result = scannerCodeBarre.process(imageToProcess);
    while (!result.isComplete()) {
        anytextView.setText("");
    }
    if (result.isComplete() & result.isSuccessful())  yourResultProcessingMethod(result.getResult());// my code to exploit the result given by the ML
    else yourFailureHandlingMethod();// my code to inform finding a barcode content failed
    
    scannerCodeBarre.close();   
    

    请注意,这两个侦听器没有编码!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2022-10-12
      相关资源
      最近更新 更多