为什么MLKIT条形码(QR码)扫描仪如此慢?

发布于 2025-02-07 10:21:07 字数 977 浏览 2 评论 0 原文

我正在尝试使用MLKIT在我的应用中实现QR代码扫描仪,并遵循这两个链接:

https://medium.com/codex/codex/scan-barcodes-in-and-android-using-the-ml-kit-kit-kit-30b2a03ccd50

/Develovers.google.com/ml-kit/vision/barcode-scanning/android“ rel =” nofollow noreferrer“> https://develovelers.google.com/ml-kit/vision/vision/barcode/barcode-scanning/android

mlkit和camerax版本:

camerax_version =“ 1.1.0-beta03” / barcodescanning =“ 17.0.2”

它在任何三星设备上都可以正常工作,但是在用Android 10上使用Android 10,在2到10秒之间可以扫描2到10秒简单的QR码。在带有Android 11的Pixel 2上,有时永远不会工作或最多需要20秒来工作。

当我使用以下LIB时,它在每个设备上都可以正常工作:

/a>

为什么MLKIT需要这么长时间(或不工作)在某些设备上扫描一些简单的QR码?

感谢您的回复

I'm trying to implement a QR code scanner in my app using Mlkit and following these two links :

https://medium.com/codex/scan-barcodes-in-android-using-the-ml-kit-30b2a03ccd50

https://developers.google.com/ml-kit/vision/barcode-scanning/android

Mlkit and CameraX versions :

camerax_version = "1.1.0-beta03" / barcodeScanning = "17.0.2"

It works fine on any Samsung device, but on Xiaomi mi 9T pro with Android 10 it takes between 2 and 10 secondes to scan a simple QR code. On Pixel 2 with Android 11 it sometimes never work or takes up to 20 secondes to work.

When I use the following lib it works fine on every device :

Android zxing Embedded BarcodeView not resuming

Why does Mlkit take so long (or don't work) to scan some simple QR code on some device ?

Thanks for the response

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2025-02-14 10:21:07

如果您使用的是MLKIT条形码扫描并获得过程映像结果慢,则使用下面的代码。它响应很快。

if (image.image != null && image.format == ImageFormat.YUV_420_888) {
                


                scanner.process(InputImage.fromBitmap(image.toBitmap(), image.imageInfo.rotationDegrees))
                    .addOnSuccessListener { barcodes ->
                        if (barcodes.isNotEmpty()) {

                            if (firstCall){


                                for (barcode in barcodes) {
                                    

                                    // Handle received barcodes...


                                    Log.d("ValueXXXX ",barcode.format.toString())

                                    if (barcode.format==Barcode.FORMAT_QR_CODE){
                                        var data = barcode.displayValue.toString().replace("\\", "")
                                        //var json=org.json.JSONObject(data)

                                        Log.d("TAG","DATA1111 "+data)

                                        if(Utils.urlPattern.matcher(data).matches()) {
                                            firstCall=false


                                            showPopupForInvalidQRCode(R.string.DISPLAY_INVALID_QR_CODE,context)



                                            break
                                        }
                                        if (!data.isNullOrEmpty() && Utils.isJSONValid(data)){
                                            firstCall=false
                                            try {
                                                val json = JSONObject(data)
                                                Log.d("TAG","json "+json)
                                                val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
                                                    if (Build.VERSION.SDK_INT >= 26) {
                                                        vibrator.vibrate(VibrationEffect.createOneShot(300, VibrationEffect.DEFAULT_AMPLITUDE))
                                                    } else {
                                                        vibrator.vibrate(300)
                                                    }

                                                 //parse your json here   

                                                break
                                            }catch (e:Exception){
                                                e.printStackTrace()
                                                showPopupForInvalidQRCode(R.string.DISPLAY_INVALID_QR_CODE,context)
                                            }
                                        }

                                        break
                                    }



                                }
                            }

                        } else {
                            // Remove bounding rect
                            barcodeBoxView.setRect(RectF())
                        }
                    }
                    .addOnFailureListener {
                        firstCall=true
                        Log.d("EXCEPTION",it.message.toString())
                        //image.close()

                    }
                    

                    }
            }

if you are using MLkit barcode scanning and getting process image result is slow, then use below code.it responds fast.

if (image.image != null && image.format == ImageFormat.YUV_420_888) {
                


                scanner.process(InputImage.fromBitmap(image.toBitmap(), image.imageInfo.rotationDegrees))
                    .addOnSuccessListener { barcodes ->
                        if (barcodes.isNotEmpty()) {

                            if (firstCall){


                                for (barcode in barcodes) {
                                    

                                    // Handle received barcodes...


                                    Log.d("ValueXXXX ",barcode.format.toString())

                                    if (barcode.format==Barcode.FORMAT_QR_CODE){
                                        var data = barcode.displayValue.toString().replace("\\", "")
                                        //var json=org.json.JSONObject(data)

                                        Log.d("TAG","DATA1111 "+data)

                                        if(Utils.urlPattern.matcher(data).matches()) {
                                            firstCall=false


                                            showPopupForInvalidQRCode(R.string.DISPLAY_INVALID_QR_CODE,context)



                                            break
                                        }
                                        if (!data.isNullOrEmpty() && Utils.isJSONValid(data)){
                                            firstCall=false
                                            try {
                                                val json = JSONObject(data)
                                                Log.d("TAG","json "+json)
                                                val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
                                                    if (Build.VERSION.SDK_INT >= 26) {
                                                        vibrator.vibrate(VibrationEffect.createOneShot(300, VibrationEffect.DEFAULT_AMPLITUDE))
                                                    } else {
                                                        vibrator.vibrate(300)
                                                    }

                                                 //parse your json here   

                                                break
                                            }catch (e:Exception){
                                                e.printStackTrace()
                                                showPopupForInvalidQRCode(R.string.DISPLAY_INVALID_QR_CODE,context)
                                            }
                                        }

                                        break
                                    }



                                }
                            }

                        } else {
                            // Remove bounding rect
                            barcodeBoxView.setRect(RectF())
                        }
                    }
                    .addOnFailureListener {
                        firstCall=true
                        Log.d("EXCEPTION",it.message.toString())
                        //image.close()

                    }
                    

                    }
            }
⒈起吃苦の倖褔 2025-02-14 10:21:07

如果您使用默认的摄像头配置,则预计可以肯定会很慢,因为图像太大,您需要进行类似的操作

.setTargetResolution(Size(1200, 1600))

,您需要检查支持的分辨率列表,因为没有任何解决方案对任何手机都适用,请检查

If you are using the default camera configuration it is expected to be slow for sure because the images are too big, you need to something like

.setTargetResolution(Size(1200, 1600))

By the way, you need to check the list of supported resolutions because not any resolution will work for any phone, please check

https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_PIXEL_ARRAY_SIZE

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文