-
-
Save deepak140596/0d57c68ca0b8d7b1bd73cfe06e8bc76e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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