focal distance of a captured image in camerax

Skip to first unread message
Assigned to by

Kumar Ranjan Kamila

Mar 28, 2023, 7:45:11 AMMar 28
to Android CameraX Discussion Group
In camera 2 we can focal distance (not focal length which is constant for each camera)

    fun onImageCaptureCompleted(totalCaptureResult: TotalCaptureResult?) {

        var flashState = totalCaptureResult?.get(CaptureResult.FLASH_STATE)
        var flashMode = totalCaptureResult?.get(CaptureResult.FLASH_MODE)
        var lensFocalDistance = totalCaptureResult?.get(CaptureResult.LENS_FOCUS_DISTANCE)
        var lensFocalLength = totalCaptureResult?.get(CaptureResult.LENS_FOCAL_LENGTH)


but can someone tell , how to achieve that in camera X ?? Any help would be greatly appreciated!
Thank you

Kumar Ranjan Kamila

Apr 6, 2023, 12:41:35 AMApr 6
to Android CameraX Discussion Group, Kumar Ranjan Kamila
Any update ? 
It will be helpful

Apr 6, 2023, 12:06:52 PMApr 6
to Android CameraX Discussion Group,
Thanks for the question and sorry for the late reply.

To get the focus distance, there's an experimental feature called Camera2Interop, which allows users to get Camera2 related information while using CameraX. LENS_FOCUS_DISTANCE can be gotten from the capture callback similar to Camera2. The code may look like:

// Create a capture callback that gets the focus distance.
val captureCallback = object : CameraCaptureSession.CaptureCallback() {
    override fun onCaptureCompleted(
        session: CameraCaptureSession,
        request: CaptureRequest,
        result: TotalCaptureResult
    ) {
        val lensFocusDistance = result.get(CaptureResult.LENS_FOCUS_DISTANCE)

// Use Camera2Interop to extend a use case builder with the capture callback

// Build the use case and bind it.
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector,

Kumar Ranjan Kamila

Apr 10, 2023, 1:04:47 AMApr 10
to Android CameraX Discussion Group,, Kumar Ranjan Kamila
Hii , Tony . Is there any other way specific to cameraX api to get lens focal distance , not using camera2interop ??

Apr 10, 2023, 7:19:07 AMApr 10
to Android CameraX Discussion Group,,
Unfortunately, there's no such API currently provides that information.

Kumar Ranjan Kamila

Apr 12, 2023, 12:11:57 AMApr 12
to Android CameraX Discussion Group,, Kumar Ranjan Kamila
Okay , thanks Tony for the above solution . It helped a lot .
Reply all
Reply to author
0 new messages