Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Vision API条形码-将检测区域限制在屏幕中央_Android_Barcode Scanner_Vision - Fatal编程技术网

Android Vision API条形码-将检测区域限制在屏幕中央

Android Vision API条形码-将检测区域限制在屏幕中央,android,barcode-scanner,vision,Android,Barcode Scanner,Vision,我正在我的应用程序中实现条形码扫描仪。我想限制我的探测范围。遵循以下逻辑,但在某些设备中无法正常工作 //尝试裁剪帧的中心部分: public class BoxDetector extends Detector { private Detector mDelegate; private int mBoxWidth, mBoxHeight; public BoxDetector(Detector delegate, int boxWidth, int boxHeigh

我正在我的应用程序中实现条形码扫描仪。我想限制我的探测范围。遵循以下逻辑,但在某些设备中无法正常工作

//尝试裁剪帧的中心部分:

 public class BoxDetector extends Detector {
    private Detector mDelegate;
    private int mBoxWidth, mBoxHeight;

    public BoxDetector(Detector delegate, int boxWidth, int boxHeight) {
        mDelegate = delegate;
        mBoxWidth = boxWidth;
        mBoxHeight = boxHeight;
    }

    public SparseArray detect(Frame frame) {
        int width = frame.getMetadata().getWidth();
        int height = frame.getMetadata().getHeight();
        int right = (width / 2) + (mBoxHeight / 2);
        int left = (width / 2) - (mBoxHeight / 2);
        int bottom = (height / 2) + (mBoxWidth / 2);
        int top = (height / 2) - (mBoxWidth / 2);

        YuvImage yuvImage = new YuvImage(frame.getGrayscaleImageData().array(), ImageFormat.NV21, width, height, null);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        yuvImage.compressToJpeg(new Rect(left, top, right, bottom), 100, byteArrayOutputStream);
        byte[] jpegArray = byteArrayOutputStream.toByteArray();
        Bitmap bitmap = BitmapFactory.decodeByteArray(jpegArray, 0, jpegArray.length);

        Frame croppedFrame =
                new Frame.Builder()
                        .setBitmap(bitmap)
                        .setRotation(frame.getMetadata().getRotation())
                        .build();

        return mDelegate.detect(croppedFrame);
    }

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

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

}
//这是我的条形码检测器构建类:

     Detector<Barcode> barcodeDetector = new BoxDetector(new BarcodeDetector.Builder(context).setBarcodeFormats(Barcode.ALL_FORMATS).build(), metrics.widthPixels, metrics.heightPixels);
        //BoxDetector myDetector = new BoxDetector(barcodeDetector, metrics.widthPixels, metrics.heightPixels);

        BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this);
        barcodeDetector.setProcessor(
                new MultiProcessor.Builder<>(barcodeFactory).build());
 @SuppressWarnings("SuspiciousNameCombination")
        CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
                .setFacing(CameraSource.CAMERA_FACING_BACK)
                .setRequestedPreviewSize(metrics.heightPixels, metrics.widthPixels)
                .setRequestedFps(30.0f);
Detector barcodeDetector=新的BoxDetector(新的barcodeDetector.Builder(上下文).setBarcodeFormats(条形码.ALL_格式).build(),metrics.widthPixels,metrics.heightPixels);
//BoxDetector myDetector=新的BoxDetector(条码检测器,metrics.widthPixels,metrics.heightPixels);
BarcodeTrackerFactory barcodeFactory=新的BarcodeTrackerFactory(mgraphCoverLay,this);
条形码检测器.setProcessor(
新的MultiProcessor.Builder(barcodeFactory.build());
@SuppressWarnings(“可疑名称组合”)
CameraSource.Builder=新的CameraSource.Builder(getApplicationContext(),barcodeDetector)
.setFacing(摄像机源.摄像机面向后)
.setRequestedPreviewSize(metrics.heightPixels、metrics.widthPixels)
.setRequestedFps(30.0f);
我在哪里,我错过了什么。已引用与此问题相关的所有github线程。但我找不到解决办法。请为此问题提供一些链接或解决方案。

BarcodeDetector BarcodeDetector=new BarcodeDetector.Builder(上下文)
    BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context)
            .setBarcodeFormats(Barcode.ALL_FORMATS)
            .build();

    //qrBorder 280dp
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int height = dm.heightPixels;
    int wight = dm.widthPixels;
    BoxDetector bx = new BoxDetector(barcodeDetector,pxFromDp(280), height, wight);
    BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this);
    bx.setProcessor(
            new MultiProcessor.Builder<>(barcodeFactory).build());
.setBarcodeFormats(条形码.所有_格式) .build(); //QRDP DisplayMetrics dm=getResources().getDisplayMetrics(); int height=dm.heightPixels; int-wight=dm.width像素; BoxDetector bx=新的BoxDetector(条形码检测器,PXDP(280),高度,重量); BarcodeTrackerFactory barcodeFactory=新的BarcodeTrackerFactory(mgraphCoverLay,this); 设置处理器( 新的MultiProcessor.Builder(barcodeFactory.build());
谢谢您的回答!。由于位图有点贵,我使用了聚焦处理器来限制屏幕中央的扫描仪检测。我正在研究相同的问题,所以你找到解决方案了吗?如果是,那么您能帮助我吗?我已经使用DetectionAreaProcessor来限制检测区域。@Madhu您能告诉我您是如何使用DetectionAreaProcessor实现的吗?