0

So basically I want to get the focus distance of lens when the focus mode is AUTO.

Currently I am working like this:

  • Assuming CONTROL_AF_MODE is set to CONTROL_AF_MODE_AUTO by default.

  • Trying to get CaptureRequest.LENS_FOCUS_DISTANCE which returns 0.0 on NEXUS 5 virtual device and null on Redmi Note 3.

Is it the correct logic?

1 Answers1

1

Generally the logic is correct. Just check a few details:

  1. Make sure your device and specific camera support auto focus by checking LENS_INFO_MINIMUM_FOCUS_DISTANCE.
  2. Make sure CONTROL_AF_STATE is at least not CONTROL_AF_STATE_INACTIVE. Most likely you need to wait until it's actually focused.

Also note the type of this value is different on different devices. Check LENS_INFO_FOCUS_DISTANCE_CALIBRATION to find out if it's a real distance or just some synthetic value.

esentsov
  • 6,372
  • 21
  • 28
  • I am getting `CONTROL_AF_MODE` value as 4. How do I know whether it is the value for `CONTROL_AF_MODE_AUTO` or not? – Rahul Savsani Aug 12 '19 at 15:13
  • Check possible varies [in the documentation](https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html#CONTROL_AF_MODE). 4 is `CONTROL_AF_MODE_CONTINUOUS_PICTURE` – esentsov Aug 12 '19 at 18:35
  • Are the values listed in the documentation lies from 0 to 5 in sequential manner? And as per your answer, How does `LENS_INFO_MINIMUM_FOCUS_DISTANCE` can clarify whether device support auto focus or not? I mean it just gives the minimum focus distance value. I am new to android, so having these type of questions! – Rahul Savsani Aug 13 '19 at 03:18