Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Camerax lens focus distance not working

77 views
Skip to first unread message
Assigned to scot...@google.com by me

Talal Shah

unread,
Nov 16, 2024, 6:10:16 AM11/16/24
to Android CameraX Discussion Group

I am using CameraX to develop a QR code scanner. I've attached an image as well. My requirement is that when the user opens the app, the camera should already be focused at a certain distance. I've disabled the autofocus functionality because I need to take a picture of the QR code.

I've implemented ImageAnalysis, but I'm getting a blurry image. The current implementation only works when I place the QR code very close to the camera. I want to capture the QR code from a bit farther away, but when I try adding a floating distance point, it doesn't work as expected.

camerax version 1.4.0

Camera2Interop.Extender<Preview> camera2Extender = new Camera2Interop.Extender<>(builder1);

// Disable auto-focus mode
camera2Extender.setCaptureRequestOption(
        CaptureRequest.CONTROL_AF_MODE,
        CameraMetadata.CONTROL_AF_MODE_OFF
);

// Set focus distance to a balanced value for mid-range focus
camera2Extender.setCaptureRequestOption(
        CaptureRequest.LENS_FOCUS_DISTANCE,
        0.3f // Adjust this value as needed for your use case
);

preview.setSurfaceProvider(previewView.getSurfaceProvider());
1000070123 (1).png

Scott Nien

unread,
Nov 17, 2024, 9:39:26 PM11/17/24
to Talal Shah, Android CameraX Discussion Group
Not sure If I fully understand your requirement, but will it work for you if you force focusing on the center right in the beginning?

camera = bindToLifecycle(..) MeteringPoint pt= (new SurfaceOrientedMeteringPointFactory(1.0f, 1.0f))

            .createPoint(0.5f, 0.5f);

camera.getCameraControl().startFocusAndMetering(

        new FocusMeteringAction.Builder(pt) .disableAutoCancel() // keep the current focus forever

                .build()

)


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/f21f5dd1-06b4-4af7-8302-4bb40e43b2c1n%40android.com.

Talal Shah

unread,
Nov 18, 2024, 11:35:28 AM11/18/24
to Scott Nien, Android CameraX Discussion Group
Hello Scott,

My requirement is to open the camera to scan QR code and after scanning I want to get QR code image for this I'm using ImageAnalysis but as I use autofocus I sometimes get blurry image to avoid this I want my camera to focus at the center of the screen at some distance from the camera where I will bring my QR code to scan and these camera focus setting is saved throughout the process without autofocus.
Reply all
Reply to author
Forward
0 new messages