[英]ML Kit Barcode Scanning doesn't detect QR codes in the photo of the monitor screen
I am using com.google.mlkit:barcode-scanning:17.0.2
to detect QR codes in the pictures.我正在使用
com.google.mlkit:barcode-scanning:17.0.2
来检测图片中的二维码。
After getting URI from the gallery I create InputImage
and then process this image with BarcodeScanner
to find QR codes.从图库中获取 URI 后,我创建
InputImage
,然后使用BarcodeScanner
处理该图像以查找 QR 码。 When I select a photo of QR codes on paper code is found.当我select时,发现了一张纸质二维码的照片。 But when I take a photo of the QR code on the monitor screen code is never found.
但是当我拍下显示器屏幕上二维码的照片时,却找不到代码。 What I should do to be able to detect a QR code in a photo of a monitor screen?
我应该怎么做才能检测到监视器屏幕照片中的二维码?
(When I use the same scanner with CameraX
to do live QR code detection it finds code on the monitor screen) (当我使用与
CameraX
相同的扫描仪进行实时二维码检测时,它会在监视器屏幕上找到代码)
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
}
}
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.
根据 QR 检测算法,莫尔效应引入的高频会使检测器偏离轨道。 Frustratingly, it is often the better QRcode detectors that are defeated by Moiré patterns.
令人沮丧的是,通常更好的 QRcode 检测器会被莫尔图案打败。
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.
这种影响是由于显示器的刷新率和策略造成的,不容易解决——您可以尝试降低显示器的亮度以增加曝光时间,直到超过 1/50 秒或 1/25 秒,或者从更远的地方拍摄照片远离并使用数码变焦。 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.
然而,使用旧的模拟显示器每次都会发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.