简体   繁体   English

ML Kit 条码扫描未检测到显示器屏幕照片中的二维码

[英]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
        }
    }

Example of QR code on paper which is found发现的纸上二维码示例

在此处输入图像描述

Example of QR code on the monitor screen which is NOT found未找到监视器屏幕上的 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.根据 QR 检测算法,莫尔效应引入的高频会使检测器偏离轨道。 Frustratingly, it is often the better QRcode detectors that are defeated by Moiré patterns.令人沮丧的是,通常更好的 QRcode 检测器会被莫尔图案打败。

A good workaround is:一个好的解决方法是:

  • take the picture at the highest resolution you can以最高分辨率拍摄照片
  • perform a blurring of the picture对图片进行模糊处理
  • increase contrast to the max, if possible如果可能,将对比度增加到最大值
  • (optionally) run a sigma thresholding, or just rewrite all pixels with a luma component below 32 to 0, all those above 224 to 255. (可选)运行 sigma 阈值,或者只是将亮度分量低于 32 的所有像素重写为 0,所有高于 224 的像素重写为 255。

Another way of doing approximately the same operation is进行大致相同操作的另一种方法是

  • take the picture at the highest resolution you can以最高分辨率拍摄照片
  • increase contrast to the max, if possible如果可能,将对比度增加到最大值
  • downsample the picture to a resolution which is way lower将图片下采样到更低的分辨率

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.

相关问题 条码扫描器使用 ML Kit 仅读取 QR 码 - Barcode scanner is reading only QR codes using ML Kit 性能不佳的 ML Kit 条码扫描 - Bad performance ML Kit barcode scanning ML Kit条形码扫描:无效的图像数据大小 - ML Kit Barcode scanning: Invalid image data size 如何在 Firebase ML KIT 中使用前置摄像头进行条码扫描 - How to use Front Camera for Barcode Scanning in Firebase ML KIT 如何使用Firebase ML Kit创建用于条形码扫描的模块化类 - How to create a modular class for barcode scanning using Firebase ML Kit 无法在 android 上使用 firebase ml 套件检测 QR 码,但在 ios 上工作(颤振) - Not detecting QR codes with firebase ml kit on android but works on ios (flutter) ZXing二维码/条码扫描 - ZXing QR Code/Barcode scanning 用于二维码扫描的 Android ML Kit 库:如何通过降低图像分辨率来提高检测性能 - Android ML Kit library for QR code scanning: How to increase detection performance by reducing image resolution 如何在android JAVA CODE中集成camerax和google ML套件以进行条码扫描? - How to Integrate camerax and google ML kit for barcode scanning in android JAVA CODE? "使用 SurfaceView 中的 ByteBuffer 时如何在 android ML-kit 中暂停条形码扫描" - How to pause barcode scanning in android ML-kit when using ByteBuffer from SurfaceView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM