How to improve qrcode recognition with android mlkit (or zxing)?

146 Views Asked by At

I have implemented a qr scanner as same as described in tutorials and that works in general. But there is a qr code (attached) that my scanner can't recognise. The Qr is correct because embedded camera app is recognising it. I have tried a bundled variant and with gms. Also zxing can't parse that qr. Can you give a tip how to tune my implementation?

My code

    private fun startCamera() {
        val cameraController = LifecycleCameraController(context)

        cameraController.setImageAnalysisAnalyzer(
            ContextCompat.getMainExecutor(context),
            QrCodeAnalyzer { value ->
                onDecode?.invoke(value)
                onDecode = null
            }
        )

        cameraController.bindToLifecycle(this)
        preview.controller = cameraController
    }

class QrCodeAnalyzer(
    private val onQrCodesDetected: (qrCode: String) -> Unit,
) : ImageAnalysis.Analyzer {

    private val options = BarcodeScannerOptions.Builder()
        .setBarcodeFormats(Barcode.FORMAT_QR_CODE)
        .build()

    private val scanner = BarcodeScanning.getClient(options)

    @ExperimentalGetImage
    override fun analyze(image: ImageProxy) {
        image.image?.let { img ->
            val inputImage = InputImage.fromMediaImage(img, image.imageInfo.rotationDegrees)

            scanner.process(inputImage)
                .addOnSuccessListener { barcodes ->
                    barcodes.firstNotNullOfOrNull { it.rawValue }?.let { onQrCodesDetected(it) }
                }
                .addOnCompleteListener {
                    image.close()
                }
        }
    }

    override fun getDefaultTargetResolution(): Size? {
        return Size(1080, 1920)
    }
}

problem qr code

0

There are 0 best solutions below