Android Vision-减少条形码跟踪窗口 [英] Android Vision - Reduce bar code tracking window

查看:98
本文介绍了Android Vision-减少条形码跟踪窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Google Visions扫描仪实施到正在开发的应用中.默认情况下,它是全屏活动,并且会在整个屏幕上跟踪条形码.

I'm trying to implement Google Visions scanner into an app im working on. By default its a full screen activity and barcodes are tracked over the entire screen.

但是,我需要一台全屏相机,但扫描窗口有限.例如,摄像机的表面视图必须是全屏的,它有2个透明的覆盖层,分别设置为屏幕顶部和底部高度的35%,中间留有30%的视口.

However, I need a fullscreen camera but with a limited scanning window. For example, the surface view for the camera needs to be fullscreen, it has 2 transparent overlays set to 35% of the screen height top and bottom leaving a 30% viewport in the center.

我已更改了图形叠加层,因此它只能显示在中间视口中,但无法确定如何将条形码跟踪器限制在同一区域.

I have changed the graphic overlay so it will only display in the middle viewport but havent been able to work out how to limit the barcode tracker to the same area.

有什么想法吗?

推荐答案

当前的API没有提供限制扫描区域的方法.但是,您可以过滤来自检测器的结果,也可以裁剪传递到检测器中的图像.

The current API doesn't provide a way to limit the scan area. However, you could either filter the results coming out of the detector or crop the image that is passed into the detector.

过滤结果方法

使用这种方法,条形码检测器仍将扫描整个图像区域,但是目标区域之外的检测到的条形码将被忽略.一种方法是实现聚焦处理器",该处理器从检测器接收结果,并且最多仅将一个条形码传递给您关联的跟踪器.例如:

With this approach, the barcode detector would still scan the full image area, but detected barcodes outside of the target region would be ignored. One way of doing this is to implement a "focusing processor" that receives the results from the detector and only passes at most one barcode to your associated tracker. For example:

public class CentralBarcodeFocusingProcessor extends FocusingProcessor<Barcode> {

  public CentralBarcodeFocusingProcessor(Detector<Barcode> detector, Tracker<Barcode> tracker) {
    super(detector, tracker);
  }

  @Override
  public int selectFocus(Detections<Barcode> detections) {
    SparseArray<Barcode> barcodes = detections.getDetectedItems();
    for (int i = 0; i < barcodes.size(); ++i) {
      int id = barcodes.keyAt(i);
      if (/* barcode in central region */) {
        return id;
      }
    }
    return -1;
  }
}

然后将这个处理器与检测器相关联,如下所示:

You'd then associate this processor with the detector like this:

   BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
   barcodeDetector.setProcessor(
                new CentralBarcodeFocusingProcessor(myTracker));

裁剪图像方法

在调用检测器之前,您需要先自己裁剪图像.这可以通过实现检测器子类来完成,该子类包装条形码检测器,裁剪接收到的图像,并使用裁剪后的图像调用条形码扫描器.

You'd need to crop the image yourself first, before the detector is called. This could be done by implementing a Detector subclass which wraps the barcode detector, crops the images received, and calls the barcode scanner with the cropped images.

例如,您将创建一个检测器来像这样截取并裁剪图像:

For example, you'd make a detector to intercept and crop the image like this:

class MyDetector extends Detector<Barcode> {
  private Detector<Barcode> mDelegate;

  MyDetector(Detector<Barcode> delegate) {
    mDelegate = delegate;
  }

  public SparseArray<Barcode> detect(Frame frame) {
    // *** crop the frame here
    return mDelegate.detect(croppedFrame);
  }

  public boolean isOperational() {
    return mDelegate.isOperational();
  }

  public boolean setFocus(int id) {
    return mDelegate.setFocus(id);
  }
} 

您将用此包装器包裹条形码检测器,将其置于相机源和条形码检测器之间:

You'd wrap the barcode detector with this one, putting it in between the camera source and the barcode detector:

BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context)
        .build();
MyDetector myDetector = new MyDetector(barcodeDetector);

myDetector.setProcessor(/* include your processor here */);

mCameraSource = new CameraSource.Builder(context, myDetector)
        .build();

这篇关于Android Vision-减少条形码跟踪窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆