繁体   English   中英

扫描时的条形码位置

[英]Barcode location while scanning

我正在为我的应用程序使用RedLaser库进行条形码扫描(我相信它是基于Zxing构建的)。 一切正常,在扫描模式下,将扫描视图中的所有条形码,但我不希望这样做,我只希望考虑在扫描区域中对齐的条形码,而忽略其余区域。

redlaser示例应用程序之后,我在自己的应用程序中实现了该库,在扫描活动的布局上有一个矩形,但是由于示例应用程序扫描并考虑了来自屏幕任何部分的条形码,因此忽略了该矩形。

底线:我希望我的扫描活动比较当前检测到的条形码的位置,看看它是否在“扫描区域”的范围内,如果不是,则不会被读取。

条码扫描

这是用于调整“扫描区域”的代码:

     viewfinderView = findViewById(R.id.view_finder);
        LayoutParams params = new LayoutParams((int)(mDisplay.getWidth() * .75f), 
                (int)(mDisplay.getHeight() * .33f));
        params.gravity = Gravity.CENTER;
        viewfinderView.setLayoutParams(params);

以下代码没有任何作用,我只是写了它来举例说明一切工作原理(因为我没有Redlaser库的源文件),例如条形码位置。

            Set<BarcodeResult> allResults = (Set<BarcodeResult>) scanStatus.get(Status.STATUS_FOUND_BARCODES);
            for( BarcodeResult  s : allResults)
            {
                ArrayList<PointF> barcodelocation = s.barcodeLocation;
                float x = barcodelocation.get(0).x;
                float y = barcodelocation.get(0).y;
//there will be 4 points to each scanned barcode => 8 float's/barcode
            }

抱歉,很长的帖子,但是我在这个问题上已经有一段时间了,我真的很困。

任何帮助表示赞赏!

设法在Redlaser站点上找到解决方案:将视图变成矩形,然后将条形码位置与使用.contain进行比较:

Rect scanningArea = new Rect(viewfinderView.getLeft(), viewfinderView.getTop(), viewfinderView.getRight(), viewfinderView.getBottom());
if(latestResult.iterator().hasNext())
        {

            boolean isInside = true;
            ArrayList<PointF> barcodelocation = latestResult.iterator().next().barcodeLocation;
            for (int i = 0; i < barcodelocation.size(); i++) 
            {
                int x = (int) barcodelocation.get(i).x;
                int y = (int) barcodelocation.get(i).y;
                if (!scanningArea.contains(x, y)) 
                {
                    isInside = false;
                }
            }
            if (isInside) 
            {
            //do stuff here
             }

        }

我仍在处理一些问题,但是现在已经回答了这个问题。 继续前进,拍拍自己的后背。 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM