focal distance of a captured image in camerax

120 views
Skip to first unread message
Assigned to tonyt...@google.com by wuj...@google.com

Kumar Ranjan Kamila

unread,
Mar 28, 2023, 7:45:11 AM3/28/23
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

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

tonyt...@google.com

unread,
Apr 6, 2023, 12:06:52 PM4/6/23
to Android CameraX Discussion Group, kumar.ran...@gmail.com
Hi,
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
Camera2Interop.Extender(useCaseBuilder).setSessionCaptureCallback(captureCallback)

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

Kumar Ranjan Kamila

unread,
Apr 10, 2023, 1:04:47 AM4/10/23
to Android CameraX Discussion Group, tonyt...@google.com, Kumar Ranjan Kamila
Hii , Tony . Is there any other way specific to cameraX api to get lens focal distance , not using camera2interop ??

tonyt...@google.com

unread,
Apr 10, 2023, 7:19:07 AM4/10/23
to Android CameraX Discussion Group, kumar.ran...@gmail.com, tonyt...@google.com
Unfortunately, there's no such API currently provides that information.

Kumar Ranjan Kamila

unread,
Apr 12, 2023, 12:11:57 AM4/12/23
to Android CameraX Discussion Group, tonyt...@google.com, Kumar Ranjan Kamila
Okay , thanks Tony for the above solution . It helped a lot .
Reply all
Reply to author
Forward
0 new messages