Skip to content

Instantly share code, notes, and snippets.

@deepak140596
Created August 28, 2019 13:57
Show Gist options
  • Save deepak140596/0d57c68ca0b8d7b1bd73cfe06e8bc76e to your computer and use it in GitHub Desktop.
Save deepak140596/0d57c68ca0b8d7b1bd73cfe06e8bc76e to your computer and use it in GitHub Desktop.
private fun startCamera() {
...
// Add this before CameraX.bindToLifecycle
// Setup image analysis pipeline that computes average pixel luminance
val analyzerConfig = ImageAnalysisConfig.Builder().apply {
// Use a worker thread for image analysis to prevent glitches
val analyzerThread = HandlerThread(
"LuminosityAnalysis").apply { start() }
setCallbackHandler(Handler(analyzerThread.looper))
// In our analysis, we care more about the latest image than
// analyzing *every* image
setImageReaderMode(
ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
}.build()
// Build the image analysis use case and instantiate our analyzer
val analyzerUseCase = ImageAnalysis(analyzerConfig).apply {
analyzer = LuminosityAnalyzer()
}
// Bind use cases to lifecycle
// If Android Studio complains about "this" being not a LifecycleOwner
// try rebuilding the project or updating the appcompat dependency to
// version 1.1.0 or higher.
CameraX.bindToLifecycle(this, preview, imageCapture)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment