简体   繁体   English

扫描时的条形码位置

[英]Barcode location while scanning

I'm using for my app the RedLaser library for barcode scanning (which is built off Zxing, I believe). 我正在为我的应用程序使用RedLaser库进行条形码扫描(我相信它是基于Zxing构建的)。 Everything is working fine, while in scanning mode, any barcode that comes within view is scanned, but I don't want that, I want only barcodes that are aligned in a scanning area to be considered and the rest to be ignored. 一切正常,在扫描模式下,将扫描视图中的所有条形码,但我不希望这样做,我只希望考虑在扫描区域中对齐的条形码,而忽略其余区域。

The redlaser sample app, after which I implemented the library in my own app, had a rectangle on the layout of the scanning activiy, however that was ignored, as barcodes from any part of the screen were scanned and taken into account by the sample app. redlaser示例应用程序之后,我在自己的应用程序中实现了该库,在扫描活动的布局上有一个矩形,但是由于示例应用程序扫描并考虑了来自屏幕任何部分的条形码,因此忽略了该矩形。

Bottom line: I want my scanning activity to compare the location of the currently detected barcode and see if it is within the bounds of the "scanning area", if it is not then it won't be read. 底线:我希望我的扫描活动比较当前检测到的条形码的位置,看看它是否在“扫描区域”的范围内,如果不是,则不会被读取。

条码扫描

Here is the code for the adjustment of the "scanning area": 这是用于调整“扫描区域”的代码:

     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);

The following code doesn't do anything, I just wrote it to exemplify the how everything works (since I don't have the source files for the Redlaser library), like the barcodelocation. 以下代码没有任何作用,我只是写了它来举例说明一切工作原理(因为我没有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
            }

Sorry for the long post, but I've been on this issue for a while now and I'm really stuck. 抱歉,很长的帖子,但是我在这个问题上已经有一段时间了,我真的很困。

Any help is appreciated! 任何帮助表示赞赏!

Managed to find a solution on the Redlaser site: turning the view into a rect then comparing the barcode location with that using .contain : 设法在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
             }

        }

I'm still working on a few issues, but this question is answered now. 我仍在处理一些问题,但是现在已经回答了这个问题。 Gonna go ahead and give myself a pat on the back. 继续前进,拍拍自己的后背。 :) :)

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

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