Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 758
mudin Avatar asked Feb 07 '17 07:02

mudin


2 Answers

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);
like image 172
bremen_matt Avatar answered Sep 24 '22 12:09

bremen_matt


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);
like image 38
Fattie Avatar answered Sep 23 '22 12:09

Fattie