简体   繁体   English

Zxing在Android设备上检测到但不在PC上检测到

[英]Zxing detects on Android device but not on pc

I am using Zxing core.jar to scan bar codes and qr codes and it's working perfectly, but I want to make tests using Robolectric, to run automated tests without an emulator or device, that will take N number of images through zxing, so my problem is that zxing for some reason is not detecting any type of code format from the .jpg files, I'm not sure if there is a limit size on the image, or something else that I'm missing. 我正在使用Zxing core.jar扫描条形码和二维码,并且运行良好,但是我想使用Robolectric进行测试,以在没有仿真器或设备的情况下运行自动化测试,这将通过zxing采集N张图像,所以我问题是zxing由于某种原因没有从.jpg文件中检测到任何类型的代码格式,我不确定图像上是否存在限制大小,或者我缺少其他内容。 The piece of code that does the detection is this, which works fine with frame previews converted to jpgs 进行检测的代码就是这样,它可以很好地用于将帧预览转换为jpgs

        BinaryBitmap bitmap = getBitmapFromImageData(input);
        Collection<BarcodeFormat> decodeFormats = getDecodeFormats();
        Map<DecodeHintType, Object> hints = getHints(decodeFormats);
        MultiFormatReader multiFormatReader = getMultiFormatReader(hints);

        Result rawResult;
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (NotFoundException e) {
            // not really an error, just QR code not found
            Log.e(LOG_TAG, "Code Detection not found exception.");
            return null;
        }

Where the input contains the byte array in jpg format and is being converted by getBitmapFromImageData to Zxings internal formats. 输入包含jpg格式的字节数组,并由getBitmapFromImageData将其转换为Zxings内部格式。 And like I said the library is working fine in the device, but I can't find any logical reason on why running this code from my pc won't work. 就像我说的那样,该库在设备中运行良好,但是我找不到从我的PC上运行此代码不起作用的任何逻辑原因。

You're not showing any key code, like how you are reading your image. 您没有像显示图像那样显示任何关键代码。 You should check whether it is being read correctly, being binarized correctly by your code, etc. Look at the unit tests in the project to see how to correctly read and process and image on the desktop. 您应该检查它是否被正确读取,是否被您的代码正确地进行了二值化等。查看项目中的单元测试,以了解如何正确读取和处理桌面上的图像。 I don't know what your code may be doing in the "get" methods that is different. 我不知道您的代码在不同的“ get”方法中可能正在做什么。

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

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