如何使用谷歌的新酒吧code API播放服务来捕捉吧code值?如何使用、酒吧、API、code

2023-09-04 23:53:15 作者:爆菊专业户

我一直在玩与新的谷歌吧code API样本code。它覆盖一箱以上的一间酒吧code直播相机饲料吧code值。 (还面临着)

我不知道怎么酒吧code值回我的应用程序。 A)如何判断已发生事件的检测时间和B)如何访问ravValue用在我的应用程序的其他部分。任何人都可以帮助呢?

https://developers.google.com/vision/multi-tracker-tutorial

https://github.com/googlesamples/android-vision

更新: 建立在@ pm0733464的回答,我添加了一个回调接口(称为onFound)来,我可以在活动访问跟踪器类。适应谷歌的多跟踪样本:

GraphicTracker

 类GraphicTracker< T>扩展跟踪< T> {
    私人GraphicOverlay mOverlay;
    私人TrackedGraphic< T> mGraphic;
    私人回调mCallback;

    GraphicTracker(GraphicOverlay叠加,TrackedGraphic< T>图形,回调回调){
        mOverlay =叠加;
        mGraphic =图形;
        mCallback =回调;
    }

    公共接口回调{
        无效onFound(串吧codeValue);
    }

    @覆盖
    公共无效的OnUpdate(Detector.Detections< T> detectionResults,T项目){
        mCallback.onFound(((酒吧code)项).rawValue);
        mOverlay.add(mGraphic);
        mGraphic.updateItem(项目);
    }
 

吧codeTrackerFactory

 类吧codeTrackerFactory实现MultiProcessor.Factory<酒吧code取代; {
    私人GraphicOverlay mGraphicOverlay;
    私人GraphicTracker.Callback mCallback;

    酒吧codeTrackerFactory(GraphicOverlay graphicOverlay,GraphicTracker.Callback回调){
        mGraphicOverlay = graphicOverlay;
        mCallback =回调;
    }

    @覆盖
    公共跟踪<酒吧code取代;创建(酒吧code吧code){
        酒吧codeGraphic图形=新的酒吧codeGraphic(mGraphicOverlay);
        返回新GraphicTracker<>(mGraphicOverlay,图形,mCallback);
    }
}
 

主要活动:

 吧codeDetector吧codeDetector =新的酒吧codeDetector.Builder(上下文).build();
酒吧codeTrackerFactory吧codeFactory =新的酒吧codeTrackerFactory(mGraphicOverlay,新GraphicTracker.Callback(){
    @覆盖
    公共无效onFound(串吧codeValue){
        Log.d(TAG,酒吧code。在Multitracker =+吧codeValue);
    }
});
多处理器<酒吧code取代;酒吧codeMultiProcessor ​​=新MultiProcessor.Builder<>(酒吧codeFactory).build();
酒吧codeDetector.setProcessor(酒吧codeMultiProcessor);
 
谷歌地图的API大改版 平台融合 计费统一

解决方案

直接用吧code探测器

一种方法是在一个位图直接使用吧code检测仪,是这样的:

 吧codeDetector吧codeDetector =新的酒吧codeDetector.Builder(上下文).build();
帧帧=新Frame.Builder()setBitmap(位图).build()。
SparseArray<酒吧code取代;酒吧codeS =吧codeDetector.detect(架);
如果(巴codes.size()0){
    //检测到访问栏code值
}
 

接收通知

另一种方法是建立一个流水线结构,用于接收检测到的吧codeS从相机preVIEW视频(请参阅MultiTracker例如的GitHub上)。你会定义自己的跟踪接收检测吧codeS,像这样的:

 类吧codeTrackerFactory实现MultiProcessor.Factory<酒吧code取代; {
    @覆盖
    公共跟踪<酒吧code取代;创建(酒吧code吧code){
        返回新MyBar codeTracker();
    }
}

类MyBar codeTracker延伸追踪<酒吧code取代; {
    @覆盖
    公共无效的OnUpdate(Detector.Detections<酒吧code取代; detectionResults,酒吧code吧code){
        //检测到访问栏code值
    }
 }
 

该跟踪器的新实例为每个栏code产生的,该方法的OnUpdate接受检测的吧code值。

您然后设置摄像机源不断流的图象进入探测器,获得的结果在跟踪:

 吧codeDetector吧codeDetector =新的酒吧codeDetector.Builder(上下文).build();
酒吧codeTrackerFactory吧codeFactory =新的酒吧codeTrackerFactory();
酒吧codeDetector.setProcessor(
    新MultiProcessor.Builder<>(酒吧codeFactory).build());

mCameraSource =新CameraSource.Builder(背景下,巴codeDetector)
    .setFacing(CameraSource.CAMERA_FACING_BACK)
    .setRequested previewSize(1600,1024)
    。建立();
 

之后,你可以直接启动相机源或使用联同一个视图,显示相机preVIEW(请参阅MultiTracker例如了解详情)。

I've been playing with the sample code from the new Google Barcode API. It overlays a box and the barcode value over the live camera feed of a barcode. (Also faces)

I can't tell how to return a barcode value to my app. A) How to tell when a detection event has occurred and B) how to access the ravValue for use in other parts of my app. Can anyone help with this?

https://developers.google.com/vision/multi-tracker-tutorial

https://github.com/googlesamples/android-vision

UPDATE: Building on @pm0733464's answer, I added a callback interface (called onFound) to the Tracker class that I could access in the Activity. Adapting the Google multi-tracker sample:

GraphicTracker:

class GraphicTracker<T> extends Tracker<T> {
    private GraphicOverlay mOverlay;
    private TrackedGraphic<T> mGraphic;
    private Callback mCallback;

    GraphicTracker(GraphicOverlay overlay, TrackedGraphic<T> graphic, Callback callback) {
        mOverlay = overlay;
        mGraphic = graphic;
        mCallback = callback;
    }

    public interface Callback {
        void onFound(String barcodeValue);
    }

    @Override
    public void onUpdate(Detector.Detections<T> detectionResults, T item) {
        mCallback.onFound(((Barcode) item).rawValue);
        mOverlay.add(mGraphic);
        mGraphic.updateItem(item);
    }

BarcodeTrackerFactory :

class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
    private GraphicOverlay mGraphicOverlay;
    private GraphicTracker.Callback mCallback;

    BarcodeTrackerFactory(GraphicOverlay graphicOverlay, GraphicTracker.Callback callback) {
        mGraphicOverlay = graphicOverlay;
        mCallback = callback;
    }

    @Override
    public Tracker<Barcode> create(Barcode barcode) {
        BarcodeGraphic graphic = new BarcodeGraphic(mGraphicOverlay);
        return new GraphicTracker<>(mGraphicOverlay, graphic, mCallback);
    }
}

Main Activity:

BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, new GraphicTracker.Callback() {
    @Override
    public void onFound(String barcodeValue) {
        Log.d(TAG, "Barcode in Multitracker = " + barcodeValue);
    }
});
MultiProcessor<Barcode> barcodeMultiProcessor = new MultiProcessor.Builder<>(barcodeFactory).build();
barcodeDetector.setProcessor(barcodeMultiProcessor);

解决方案

Directly using the barcode detector

One approach is to use the barcode detector directly on a bitmap, like this:

BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<Barcode> barcodes = barcodeDetector.detect(frame);
if (barcodes.size() > 0) {
    // Access detected barcode values
}

Receiving notifications

Another approach is to set up a pipeline structure for receiving detected barcodes from camera preview video (see the MultiTracker example on GitHub). You'd define your own Tracker to receive detected barcodes, like this:

class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
    @Override
    public Tracker<Barcode> create(Barcode barcode) {
        return new MyBarcodeTracker();
    }
} 

class MyBarcodeTracker extends Tracker<Barcode> {
    @Override
    public void onUpdate(Detector.Detections<Barcode> detectionResults, Barcode barcode) {
        // Access detected barcode values
    }
 }

A new instance of this tracker is created for each barcode, with the onUpdate method receiving the detected barcode value.

You then set up the camera source to continuously stream images into the detector, receiving the results in your tracker:

BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory();
barcodeDetector.setProcessor(
    new MultiProcessor.Builder<>(barcodeFactory).build());

mCameraSource = new CameraSource.Builder(context, barcodeDetector)
    .setFacing(CameraSource.CAMERA_FACING_BACK)
    .setRequestedPreviewSize(1600, 1024)
    .build();

Later, you'd either start the camera source directly or use it in conjunction with a view that shows the camera preview (see the MultiTracker example for more details).