Open
Description
I have a question. Why not pass scanThrottleDelay to the native layer for processing? Perform throttling inside the analyze function of QRCodeAnalyzer. This can reduce the number of calls for identifying QR codes.
The problem I'm encountering now:
Scanning codes for a long time can cause the phone to get hot and overheated
import android.annotation.SuppressLint
import androidx.camera.core.ExperimentalGetImage
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy
import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.barcode.common.Barcode
import com.google.mlkit.vision.common.InputImage
class QRCodeAnalyzer (
private val scanThrottleDelay: Long, // --> Newly added code
private val onQRCodesDetected: (qrCodes: List<Barcode>) -> Unit
) : ImageAnalysis.Analyzer {
private var lastScanTime: Long = 0 // --> Newly added code
@SuppressLint("UnsafeExperimentalUsageError")
@ExperimentalGetImage
override fun analyze(image: ImageProxy) {
val currentTime = System.currentTimeMillis() // --> Newly added code
if (currentTime - lastScanTime < scanThrottleDelay) { // --> Newly added code
image.close() // --> Newly added code
return // --> Newly added code
}
lastScanTime = currentTime
val inputImage = InputImage.fromMediaImage(image.image!!, image.imageInfo.rotationDegrees)
val scanner = BarcodeScanning.getClient()
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
val strBarcodes = mutableListOf<Barcode>()
barcodes.forEach { barcode ->
strBarcodes.add(barcode ?: return@forEach)
}
onQRCodesDetected(strBarcodes)
}
.addOnCompleteListener{
image.close()
}
}
}```
Metadata
Metadata
Assignees
Labels
No labels