I'm trying to use the auto-focus feature of Android phones to detect object distances using the LENS_FOCUS_DISTANCE parameter, but I'm facing accuracy issues.
- My device: Samsung S22
- LENS_FOCUS_DISTANCE_CALIBRATION parameter: APPROXIMATE
- Autofocus Mode: CONTROL_AF_MODE_CONTINOUS_PICTURE
I have a few questions:
I've noticed that the further an object is from the camera, the greater the discrepancy between the LENS_FOCUS_DISTANCE value and the object's actual depth. I suspect this is due to the small focal length of the phone's camera, resulting in a larger Depth of Field (DoF). Could you share insights on the reasonable range of this discrepancy and how the auto-focus algorithm determines the focus distance within this DoF range?
How is the LENS_FOCUS_DISTANCE value calculated? I understand that in auto-focus mode, after focusing is complete and the lens position is fixed, the calculation might involve the imaging formula 1/f = 1/p + 1/q, where LENS_FOCUS_DISTANCE represents 1/p. Is this understanding correct?
According to the Android Developers Documentation:
- The desired distance to the plane of sharpest focus is measured from the lens's frontmost surface.
- This value should be zero for fixed-focus cameras.
- For APPROXIMATE and CALIBRATED devices, the focus metadata is reported in diopters (1/meter), where
0.0frepresents focusing at infinity, and increasing positive numbers indicate focusing closer to the camera device.
Is using the LENS_FOCUS_DISTANCE parameter as a reference for distance measurement physically sound? Despite potential inaccuracies, this parameter essentially defines the distance from the lens's front to the sharpest focus plane, right?
I originally expected that the return value of LENS_FOCUS_DISTANCE would change according to the distance of my object, thereby providing the correct object depth. However, the outcome did not meet my expectations.
For example, when the object was placed at 50 cm, the average return value was 39.1.
| Raw data | ||
|---|---|---|
| Wrist | mean | variance |
| 10 | 10.2 | 0.171429 |
| 15 | 14.9 | 0.209524 |
| 20 | 18.1 | 0.123810 |
| 25 | 22.3 | 0.380952 |
| 30 | 25.7 | 0.380952 |
| 35 | 28.8 | 0.600000 |
| 40 | 32.5 | 1.695238 |
| 45 | 36.3 | 0.952381 |
| 50 | 39.1 | 0.838095 |