简体   繁体   English

Google ML Kit 条码扫描器无法扫描绿色背景的 QR 码

[英]Google ML Kit barcode scanner does not scan QR code with green background

I noticed a strange issue with Google's ML Kit Barcode scanner .我注意到Google 的 ML Kit Barcode 扫描仪有一个奇怪的问题。 I try to scan a QR code which has a green background, and it does not recognize the QR code at all.我尝试扫描绿色背景的二维码,但它根本无法识别二维码。 However if I crop the same QR code and remove the green background then it scans perfectly well.但是,如果我裁剪相同的二维码并删除绿色背景,那么它扫描得非常好。 I don't put any code examples of my implementation here as the official example has the exact same issue.我没有在此处放置我的实现的任何代码示例,因为官方示例具有完全相同的问题。 Here is my image.这是我的形象。 I don't even know how to research this problem as I totally don't understand what green background can do.我什至不知道如何研究这个问题,因为我完全不明白绿色背景可以做什么。 在此处输入图像描述

Well, after spending some time on trying to solve this problem with various image processing techniques etc. I found out that the solution is rather simple and was always there right in front of me.好吧,在花了一些时间尝试用各种图像处理技术等解决这个问题之后,我发现解决方案相当简单,而且总是摆在我面前。

So while building the image analyzer, there is a configuration function to set Target Resolution setTargetResolution(@NonNull Size resolution) , which if not set explicitly is defaulting to 640x480 , which is probably ok for general use cases related to image analyzer (otherwise I wonder why Google should pick this resolution as a default).因此,在构建图像分析器时,有一个配置函数来设置 Target Resolution setTargetResolution(@NonNull Size resolution) ,如果没有明确设置默认为640x480 ,这对于与图像分析器相关的一般用例可能是可以的(否则我想知道为什么谷歌应该选择这个分辨率作为默认)。 And it's also OK for normal QR codes, but for problematic QRs like this it seems to mess thing up, so ML kit needs a higher resolution images for processing.对于普通的二维码也可以,但对于像这样有问题的二维码,它似乎会搞砸,所以机器学习套件需要更高分辨率的图像来处理。

So just changing this default 640x480 to 1920x1440 immediately solved the issue, and the QR code without borders started to be scanned immediately and with very good performance.所以只要把这个默认的640x480 1920x1440就马上解决了这个问题,而且没有边框的二维码马上就开始扫描了,性能非常好。 I tried other, smaller resolutions as well, tried on different high and low end devices with good and bad cameras, and came to this resolution, which seems to perform the best.我也尝试了其他更小的分辨率,在不同的高端和低端设备上尝试了好坏相机,并得出了这个似乎表现最好的分辨率。

So currently me Image Analyzer builder looks like this, and it works just fine所以目前我的图像分析器生成器看起来像这样,它工作得很好

private val analyzerUseCase = ImageAnalysis.Builder()
        .setTargetResolution(Size(1440, 1920))
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
        .build()

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

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