其他分享
首页 > 其他分享> > android – Google Vision API – 在Camera Preview上绘制包含QR码的图形布局

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

作者:互联网

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

解决方法:

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

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

标签:android,google-vision
来源: https://codeday.me/bug/20190519/1135784.html