Google Vision API - 在Camera Preview上绘制包含QR码的图形布局

时间:2016-02-01 00:01:16

标签: android google-vision

我正在将Google vision API集成到我现有的Android应用程序中。该应用程序确实识别QR码,但我需要实现UI功能,其中用户在条形码上显示图形轮廓。

1 个答案:

答案 0 :(得分:5)

此代码示例包括在条形码上显示图形轮廓:

https://github.com/googlesamples/android-vision/tree/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader

从探测器到图形的关联是这样的:

    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);

    // A barcode detector is created to track barcodes.  An associated multi-processor instance
    // is set to receive the barcode detection results, track the barcodes, and maintain
    // graphics for each barcode on screen.  The factory is used by the multi-processor to
    // create a separate tracker instance for each barcode.
    BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
    BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay);
    barcodeDetector.setProcessor(
            new MultiProcessor.Builder<>(barcodeFactory).build());

GraphicOverlay包含在上面的代码示例中。此实用程序可以轻松添加在相机预览之上呈现的图形对象。请参阅此处的代码:

https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/GraphicOverlay.java

在此示例中,条形码工厂管理图形对象的创建,该图形对象为检测到的条形码绘制矩形和标签。请参阅此处定义的BarcodeGraphic类:

https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeGraphic.java