Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Analysis results are not the same as Preview #565

Open
muhrafitriandi opened this issue Dec 1, 2023 · 0 comments
Open

Image Analysis results are not the same as Preview #565

muhrafitriandi opened this issue Dec 1, 2023 · 0 comments

Comments

@muhrafitriandi
Copy link

private fun bindCameraUseCases() = with(binding.viewFinder) {
    val screenAspectRatio = AspectRatio.RATIO_16_9
    val viewPort = ViewPort.Builder(
        Rational(
            width,
            height
        ), display.rotation
    ).build()
    val cameraProvider = cameraProvider ?: throw IllegalStateException(getString(R.string.res_error_camera_start))
    val cameraSelector = CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build()

    preview = Preview.Builder()
        .setTargetAspectRatio(screenAspectRatio)
        .build()

    imageAnalyzer = ImageAnalysis.Builder()
        .setTargetAspectRatio(screenAspectRatio)
        .setTargetRotation(display.rotation)
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
        .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888)
        .build()

    val useCaseGroup = UseCaseGroup.Builder()
        .addUseCase(preview!!)
        .addUseCase(imageAnalyzer)
        .setViewPort(viewPort)
        .build()

    cameraProvider.unbindAll()

    if (camera != null) {
        removeCameraStateObservers(camera!!.cameraInfo)
    }

    try {
        camera = cameraProvider.bindToLifecycle(viewLifecycleOwner, cameraSelector, useCaseGroup)
        preview?.setSurfaceProvider(surfaceProvider)
    } catch (exc: Exception) {
        requireActivity().toast(getString(R.string.res_error_camera_use_case))
    }

    camera?.cameraControl?.enableTorch(viewModel.isFlashOn.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant