我正在开发一个 Android 应用程序,需要一次扫描多个 QR 码(例如,单帧中最多同时检测和解码 10 个 QR 码)。我正在考虑使用 Google ML Kit 的条形码扫描 API,但我不确定它是否支持在单个相机帧中检测和解码多个二维码。
这就是我想要实现的目标:
- Detect and decode up to 10 QR codes simultaneously.
- Process the results efficiently for real-time feedback.
我尝试过的:
- I’ve reviewed the ML Kit Barcode Scanning API documentation, but it’s not clear whether this functionality is supported out of the box.
- I tested the API with single QR codes, and it works perfectly for one barcode or QR code at a time.
- I attempted scanning multiple QR codes by feeding a frame containing multiple codes, but it seems to detect only one at a time.
我的问题:
- Does Google ML Kit Barcode Scanning API natively support multiple QR code detection?
- If not, is there any open-source implementation or workaround to achieve this functionality using ML Kit or another library (e.g., Zxing or ZBar)?
- Are there specific configurations or techniques to enhance the detection of multiple barcodes/QR codes in one frame?
其他详细信息:
- Development environment: Android (Java/Kotlin)
- Library version: Google ML Kit Barcode Scanning (latest version as of writing)
- Use case: Real-time scanning of bulk QR codes (up to 10) in a single camera frame.
如果 ML Kit 不是此用例的正确选择,我将不胜感激任何有助于实现这一目标的其他库或方法的建议。
谢谢!
是的,Google ML Kit 的条形码扫描 API 支持在单个框架中扫描多个二维码。
要检测多个 QR 码,请将扫描仪配置为定位 QR 码:
val options = BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
.build()
创建扫描仪实例:
val scanner = BarcodeScanning.getClient(options)
处理图像帧:
val image = InputImage.fromBitmap(bitmap, 0)
scanner.process(image)
.addOnSuccessListener { barcodes ->
for (barcode in barcodes) {
val rawValue = barcode.rawValue
// Use or display the detected QR code data
}
}
.addOnFailureListener { e ->
Log.e("QRScanner", "Error: ", e)
}
此方法在单帧中最多检测 10 个 QR 码。如果您需要扫描十多个代码,想要即用型扫描 UI 组件,您可以考虑使用商业替代品,例如 Scanbot SDK。该 SDK 支持无条形码限制的扫描,并提供预构建的 UI 元素以加快实施速度(为了提高透明度,我在 Scanbot 工作)。