Android QRCode扫描仪库 [英] Android QRCode Scanner Library

查看:99
本文介绍了Android QRCode扫描仪库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有什么可供我们使用(如果有的话)的设备,以便我们调用图像上的QR数据发现和提取?

尽管到目前为止有很多帖子引用ZXing库进行QRCode扫描,但我还没有发现这是对我有用的解决方案.其他几个人一直在要求QRCode扫描替代方案,但我还没有看到有用的反馈.我以为我可能会再问社区,对于没有启动活动并在我们自己的应用程序外部调用的QR码库,其他选择可能是什么.它应该以非常简单的方式从Camera2 API扫描图像.它不应该是一个复杂的库.我没有看到这样的例子或个人谈论它.

While there have been plenty of posts thus far referencing the ZXing library for QRCode scanning, I haven't found that to be a solution that works for me. Several others have been asking for QRCode scanning alternatives and I have not seen useful feedback. I thought I might ask the community once more what the other options might be for a QR code library that does not launch an activity and call outside our own applications. It should scan images from the Camera2 API in a very simplistic manner. It shouldn't be a complicated library. I hadn't seen examples or individuals speaking of it in this manner.

这实际上使我感到困惑,为什么没有将QRCode功能的本机实现添加到操作系统内的Camera库或Google SDK内类似位置中的可能.

It actually puzzles me as to why there hasn't been native implementations of the QRCode functionality added into perhaps the Camera library or similar place within the Google SDK natively within the operating system.

调用并要求另一个应用程序(甚至请求下载)不是一个很好的解决方案,任何用户都不应屈服于这样做.作为开发人员,我们应该可以访问能够从图像或帧中提取QRCode的库,然后从中删除编码数据.

Calling and requiring another application (or even requesting a download) is not an elegant solution and no users should be succumbed to doing such thing. As developers we should have access to a library capable of extracting a QRCode from an image or frame that we can then remove encoded data from.

推荐答案

虽然Sean Owen和其他在原始Zxing库上工作的人在过去的几年中提供了一种与条形码库一起工作的方法,但Google终于提出了推出了Google Play服务发布的用于处理二维码和条形码的正式版本.

While Sean Owen and others that have worked on the original Zxing library had provided an approach to work with the barcode libraries for the past several years, Google has finally put out an official release with Google Play Services for handling qr and barcodes.

条形码检测库在这里描述.包含这些库将使平滑的集成成为可能.我将重新发布一些示例代码,以从捕获的图像中获得这些结果.目前,我想更新此官方版本的答案.如果确实确实提供了一种获取此信息的好方法(而不会遇到麻烦和麻烦),那么我将与源进行更新并将其作为可接受的答案进行核对.

The barcode detection library is described here. The inclusion of these libraries will make for a smooth integration. I'll repost with some sample code for achieving these results from a captured image. At the moment, I wanted to update my answer for this official release. If this indeed does provide a nice way to get at this information (without jumping through hoops and complications), then I'll update with the source and check this off as an accepted answer.

Google在过去一年中提供的检测库非常易于使用.它允许与摄像机API进行快速集成,并以简单的方式提取信息.这将是我建议继续认可的组成部分.下面展示了一个用于处理Qr代码的快速代码段.那里也保留了一些伪代码.

The detection library that Google has provided within the past year has been a much easier library to work with. It allows for quick integration with the camera APIs and extracts the information with simplicity. This would be the component that I would suggest going forward with recognition. A quick snippet is demonstrated below for handling a Qr-code. A handful of pseudocode is left in there as well.

public final void analyzeFrameForQrCode(byte[] qrCodePictureF, int imageFormatF, XriteSize previewWindowSizeF)
{
    if(!qrCodeDetectionPossible() || qrCodePictureF == null || mIsAnalyzingQrCodeFrame)
    {
        return;
    }

    ... //Bitmap conversion code

    Frame frame = new Frame.Builder().setBitmap(pictureTaken).build();
    SparseArray<Barcode> barcodes = mBarcodeDetector.detect(frame);
    if(barcodes != null && barcodes.size() != 0)
    {
        Barcode qrCode = barcodes.valueAt(0);//barcodes.get(Barcode.QR_CODE);
        if(qrCode != null)
        {
             if(extractInformationFromQrCode(qrCode.rawValue)) {
                    mIsRequestingBarcodeDetection = false;
                    vibrateForQrCodeDiscovery();
                    ((Activity)mContext).runOnUiThread(new Runnable() {
                        @Override
                        public void run()
                        {
                            hideBarcodeDetection(true);
                        }
                    });
                }
            }
        }

     ... //Cleanup and code beyond Qr related material

   } 
}

当然还有其他可以利用的电话.但是实际上那里只有几行.但是,默认情况下,设备上不提供使用库分析框架的服务.因此,在计算之前,您还应该检查该库是否可用(例如,当Internet不可用时).这是一个小小的麻烦.我以为它将作为支持库的一部分或将来向所有设备推出的Google服务的设备的更新可用.但是它首先需要与外部服务进行通信才能使用这些库调用.一旦它执行了一次,那么从那一刻起该设备就很好了.

There are of course other calls available that can be taken advantage of. But there are really only a couple lines in there. The service for analyzing the frames with the library are not there by default on devices however. So, you should check whether or not the library is available (such as when internet is not available) before calculating as well. This is a slight nuisance of it. I had assumed it would be available as updates for devices going forward as part of the support library or Google Services going out to all devices. But it needs the communication first with an external service to use these library calls. Once it does this one time then that device is good from that moment on.

在我的小示例中,我经过检查后弹出了一个祝酒词,然后退出活动并让用户检查其连接.也可以使用少量示例代码来完成此操作.

In my small example, I pop a toast up after a check and then back out of the activity and let the user check their connection. This can be done with a small amount of sample code as well.

if(!mBarcodeDetector.isOperational())
{
    updateUserInstructions("The barcode library cannot be downloaded");
    return false;
}

编辑(更新):

自从使用最新的可用于条形码检测的Google Play服务视觉库以来,已经花费了相当长的时间.虽然需要通过wifi下载库的限制确实是一个限制,但它是一个一次性的过程.老实说...

A considerable amount of time has passed since working with the latest Google Play Services Vision libraries available for barcode detection. While the limitation for needing to download the library over the wifi is indeed a limitation, it is a one time process. And lets be honest...

...我们的设备将建立连接.库本身是在后台下载的,因此,除非下载时遇到麻烦,否则您甚至不会注意到它的发生,然后您必须报告适当的纠正措施,例如为其启用到Internet的连接.

...our devices will have a connection. The library itself is downloaded in the background so you don't even notice it happening unless there is trouble downloading it and then you would have to report an appropriate corrective measure such as enabling a connection to the internet for it.

另一个小窍门是有时将库集成到应用程序中会有些棘手.将其用作库项目可在某些设备上使用,然后在其他设备上失败.将jar添加到构建路径可在更广泛的设备上使用(可能是全部,但解决了一个问题).因此,现在将其包含在您的项目中时,我将使用辅助方法来完成它.

One additional tidbit is that it is a little tricky sometimes with how you integrate the library into your application. Using it as a library project worked on some devices and then failed on others. Adding the jar to the build path worked across a broader number of devices (it could be all, but it solved a problem). So as such, I would do it using the secondary method when including it in your projects for now.

这篇关于Android QRCode扫描仪库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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