Abh*_*bhi 7 android android-camerax
如何在图像分析中将帧速率降低到 1 fps,这样我就不会多次检测到条形码。在我的用例中,以 1 秒的间隔多次扫描相同的条形码应该会增加一个计数器。所以我希望它能够正常工作。(类似于商店收银台的产品扫描仪)
cameraX版本:1.0.0-beta02
类似问题:
如何使用 Android CameraX ImageAnalysis 提高帧速率?
在此,答案基于cameraX alpha 版本中的预览配置和分析配置构建器。但在测试版中并没有找到它。
如何在使用 SurfaceView 中的 ByteBuffer 时在 android ML-kit 中暂停条形码扫描
在此,图像分析受到限制,但我希望对图像分析器的调用以较低的帧速率进行。即从图像分析用例到图像分析器的调用应该每秒一次。
目前的实施:
https://proandroiddev.com/update-android-camerax-4a44c3e4cdcc
按照此文档,限制图像分析。
override fun analyze(image: ImageProxy) {
val currentTimestamp = System.currentTimeMillis()
if (currentTimestamp - lastAnalyzedTimestamp >= TimeUnit.SECONDS.toMillis(1)) {
// Image analysis code
}
image.close()
}
Run Code Online (Sandbox Code Playgroud)
更好的解决方案会有所帮助。
尝试了 bmdelacruz 的解决方案。关闭图像时遇到问题。
遇到与此类似的错误。
无法让它工作。
使用delay对我来说效果很好。
代码
CoroutineScope(Dispatchers.IO).launch {
delay(1000 - (System.currentTimeMillis() - currentTimestamp))
imageProxy.close()
}
Run Code Online (Sandbox Code Playgroud)
完整的 BarcodeAnalyser 代码
class BarcodeAnalyser(
private val onBarcodesDetected: (barcodes: List<Barcode>) -> Unit,
) : ImageAnalysis.Analyzer {
private val barcodeScannerOptions = BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_ALL_FORMATS)
.build()
private val barcodeScanner = BarcodeScanning.getClient(barcodeScannerOptions)
var currentTimestamp: Long = 0
override fun analyze(
imageProxy: ImageProxy,
) {
currentTimestamp = System.currentTimeMillis()
imageProxy.image?.let { imageToAnalyze ->
val imageToProcess =
InputImage.fromMediaImage(imageToAnalyze, imageProxy.imageInfo.rotationDegrees)
barcodeScanner.process(imageToProcess)
.addOnSuccessListener { barcodes ->
// Success handling
}
.addOnFailureListener { exception ->
// Failure handling
}
.addOnCompleteListener {
CoroutineScope(Dispatchers.IO).launch {
delay(1000 - (System.currentTimeMillis() - currentTimestamp))
imageProxy.close()
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3134 次 |
| 最近记录: |