无法使用Google Vision API扫描条形码

时间:2019-05-03 07:41:44

标签: android xamarin google-vision

我具有在两个单独的屏幕中扫描QR和条形码(GS1 128)格式的功能。我能够扫描QR码,但是我的ReceiveDetections(Detections detections)未检测到条形码。奇怪,我尝试设置.SetBarcodeFormats(Barcode.AllFormats)并检测到Code-128,但无法检测到GS1-128 (UCC/EAN-128)ReceiveDetections被调用,但barcodes为空。

下面是我的代码:

_barcodeDetector = new BarcodeDetector.Builder(this)
         .SetBarcodeFormats(Barcode.AllFormats)
         .Build();
_cameraSource = new CameraSource
    .Builder(this, _barcodeDetector)
    .SetRequestedPreviewSize(250, 250)
    .SetAutoFocusEnabled(true)
    .Build();
surfaceView.Holder.AddCallback(this);
_barcodeDetector.SetProcessor(this);

public void ReceiveDetections(Detections detections)
{
    try
    {
        SparseArray barcodes = detections.DetectedItems;
        if (barcodes.Size() != 0)
        {
            string barcode = ((Barcode)barcodes.ValueAt(0)).RawValue;
        }
    }
    catch (Exception ex)
    {

    }
}

0 个答案:

没有答案