5

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

4

1 回答 1

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

于 2016-02-01T19:32:39.157 回答