Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android camera2 API get focus distance in AF mode

I'm working with Android camera2 API.

I can get focus distance value using LENS_FOCUS_DISTANCE in manual focus mode. However, the property is always zero in AF mode. Is there any way to get focus distance in AF mode?

like image 408
techneer Avatar asked Jun 09 '15 06:06

techneer


2 Answers

Shortest distance from frontmost surface of the lens that can be brought into sharp focus.

If the lens is fixed-focus, this will be 0.

http://developer.android.com/intl/es/reference/android/hardware/camera2/CameraCharacteristics.html

In other way, if you want to manage focus, remember that LENS_INFO_MINIMUM_FOCUS_DISTANCE give you the minimum focus, but to get the "Max" focus you must use LENS_INFO_HYPERFOCAL_DISTANCE.

float yourMinFocus = mCameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
float yourMaxFocus = mCameraCharacteristics.get(CameraCharacteristics.LENS_INFO_HYPERFOCAL_DISTANCE);

For 2021 when using CameraX, here's how to find camera characteristics such as LENS_INFO_MINIMUM_FOCUS_DISTANCE:

theCamera = cameraProvider.bindToLifecycle(...
CameraCharacteristics camChars = Camera2CameraInfo
   .extractCameraCharacteristics(theCamera.getCameraInfo());
float discoveredMinFocusDistance = camChars
   .get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
Log.i("dev", "min focus is " + discoveredMinFocusDistance);
like image 168
Francisco Durdin Garcia Avatar answered Sep 20 '22 14:09

Francisco Durdin Garcia


If the value of LENS_INFO_MINIMUM_FOCUS_DISTANCE is 0, it means it is fixed focus and not supporting manual focus. Limited capability - Present on all camera devices that report being at least HARDWARE_LEVEL_LIMITED

like image 35
user0770 Avatar answered Sep 19 '22 14:09

user0770