mudin
mudin

Reputation: 2852

How to set infinity focus in camera2 api, android?

I wanna set my custom camera focus distance to infinity while using external fisheye lens, This is what I have done so far:

builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
builder.set(CaptureRequest.LENS_FOCUS_DISTANCE, 0.0f);

But the result is so blurry.

I am using Samsung S6 and Nexus 5. External lens's wide angle is 170 degree.

Can anyone help?

Upvotes: 5

Views: 3558

Answers (2)

Fattie
Fattie

Reputation: 12598

For anyone googling here, to get Android CameraX, camera characteristics such as CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE.

For 2021 the syntax is like ...

So, you've gone through the process of getting the camera ...

theCamera = cameraProvider.bindToLifecycle((LifecycleOwner)this,
              yourCameraSelector, yourImageAnalysis, yourPreview);

the code nowadays is:

CameraCharacteristics camChars = Camera2CameraInfo
   .extractCameraCharacteristics(theCamera.getCameraInfo());
float discoveredMinFocusDistance = camChars
   .get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);

Upvotes: 2

bremen_matt
bremen_matt

Reputation: 7349

If you are just talking about using the built-in camera's lens to achieve fisheye, then the lowest value you should use is:

float minFocalDist = cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);

If you are using an external lens, then I believe that the correct approach is actually to use autofocus on the camera, since that should focus to the focal length of the fish eye lens... I think. So the external lens is taking care of fisheye and the internal is taking care of autofocus. However, if this doesn't work, then see what you get when you set the focal length to the hyperfocal distance. That distance might not be optimal, but it should work in most cases...

float hyperFocalDist = cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_HYPERFOCAL_DISTANCE);

Upvotes: 4

Related Questions