ML KIT条形码扫描未检测到监视器屏幕照片中的QR码
我正在使用 com.google.mlkit.mlkit.mlkit:barcode-scanning:barcode-scanning:bar occanning:barcode: 17.0.2
检测图片中的QR码。
从画廊获得URI后,我创建 InputImage
,然后使用 barcodescanner
来查找QR代码。当我在纸质代码上选择QR码的照片时。但是,当我在监视器屏幕代码上拍摄QR码的照片时。我该怎么办才能在监视器屏幕的照片中检测QR码?
(当我使用 camerax
进行实时QR代码检测的同一扫描仪时,它会在监视器屏幕上找到代码)
val image = InputImage.fromFilePath(context, uri)
val scanOptions =
BarcodeScannerOptions.Builder()
.setBarcodeFormats(
Barcode.FORMAT_QR_CODE,
)
.build()
val scanner = BarcodeScanning.getClient(scanOptions)
scanner.process(image)
.addOnSuccessListener {
val code = it.getOrNull(0)?.rawValue
if (code == null) {
// code NOT found
} else {
// code was found
}
}
QR代码的示例在纸上找到
在监视器屏幕上的QR码的示例
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是您正在与moiréformation。根据QR检测算法,Moiré效应引入的高频可以使检测器脱离轨道。令人沮丧的是,通常是更好的 qrcode检测器被莫伊尔模式击败。
一个良好的解决方法是:
进行大约相同操作的另一种方法是以
第二种方法,第二种方法给出了较差的结果,但通常可以用设备原始词实现。
监视器问题的另一个来源(据我所知,在您的照片中都没有)是刷新率。有时,您会发现QR码实际上是图片上半部分中的一个过度曝光的QRCODE,并且在图片的下半部分是一个未充满刺激的QRCODE。两者都没有得到认可。这种效果是由于监视器的刷新率和策略造成的,并且不容易解决 - 您可以尝试降低监视器的光度以增加曝光时间,直到超过1/50或1/25秒的时间,或从更远的地方拍摄图片离开并使用数字缩放。现代监视器的刷新率更高,实际上在其居住时间内刷新的时间更高,因此不应该发生这种情况。但是,使用旧的模拟显示器,但每次都会发生。
第三个疯狂的方式
是偶然发现的,但是即使在QR SDK或图书馆提供一些小的额外装饰的情况下,它也可以很好地奏效。
这在嘈杂,振动富的环境中运行的19美元ESP32 IoT设备(它从移动传输色带上的纸箱盒子的相机图像中获取了QR码)。
Chances are that you're fighting against Moiré effect. Depending on the QR detection algorithm, the high frequencies introduced by the Moiré effect can throw the detector off its track. Frustratingly, it is often the better QRcode detectors that are defeated by Moiré patterns.
A good workaround is:
Another way of doing approximately the same operation is
The second method gives worse results, but usually can be implemented with device primitives.
Another source of problems with monitors (not in your picture as far as I can see) is the refresh rate. Sometimes, you'll find that the QR code is actually an overexposed QRcode in the upper half of the picture and an underexposed QRcode in the bottom half of the picture. Neither are recognized. This effect is due to the monitor's refresh rate and strategy and is not easy to solve - you can try lowering the monitor's luminosity to increase exposure time, until it exceeds 1/50th or 1/25th of a second, or take the picture from farther away and use digital zooming. Modern monitors have higher refresh rates and actually refresh at more than their own dwell time, so this should not happen; with old analog monitors however it will happen every time.
A third, crazy way
This was discovered half by chance, but it works really well even on cheap hardware provided the QR SDK or library supplies some small extra frills.
This worked on a $19 ESP32 IoT device operating in a noisy, vibration-rich environment (it acquires QR codes from a camera image of carton boxes on a moving transport ribbon).