Skip to content

Commit

Permalink
App/Vision: Update the ImageAnalyzer class to support frame-skipping
Browse files Browse the repository at this point in the history
This patch updates the ImageAnalyzer class, which is an abstraction
layer of the concrete image analysis implementation, to support
condition-based frame-skipping.

Signed-off-by: Wook Song <[email protected]>
  • Loading branch information
wooksong committed Nov 14, 2024
1 parent c11c2a2 commit e770a07
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import androidx.camera.core.ImageProxy

class ImageAnalyzer(
private val classifier: MobilenetClassifier,
private val frameSkipRate: Int = 30,
private val shouldAnalyze: (ImageProxy, Int) -> Boolean = { _, frameCount -> frameCount % frameSkipRate == 0 }
) : ImageAnalysis.Analyzer {
private var frameSkipCounter = 0

override fun analyze(imageProxy: ImageProxy) {
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
val bitmap = imageProxy.toBitmap()
if (shouldAnalyze(imageProxy, frameSkipCounter)) {
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
val bitmap = imageProxy.toBitmap()

classifier.classify(bitmap, rotationDegrees)
classifier.classify(bitmap, rotationDegrees)
}

frameSkipCounter = (frameSkipCounter + 1) % frameSkipRate
imageProxy.close()
}
}

0 comments on commit e770a07

Please sign in to comment.