I want to get the distance from an object to android device using android camera2 API. In CaptureCallback
, I get the value by result.get(CaptureResult.LENS_FOCUS_DISTANCE)
and check LENS_STATE, CONTROL_AF_MODE, CONTROL_AF_STATE
at the same time. They are "STATIONARY", CONTINUOUS_PICTURE
and PASSIVE_FOCUSED
. I think the focus distance should be valid and the distance from an object to android device should be 1/focus_distance
. But in fact the calculated value is totally different from the actual distance. What's wrong with it? Is LENS_FOCUS_DISTANCE
the correct value for distance estimation? Anyone have idea?
final CameraCaptureSession.CaptureCallback captureCallbackListener = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
Log.e(TAG, String.format("captureCallbackListener %s-%f", lensStateToString(result.get(CaptureResult.LENS_STATE)), result.get(CaptureResult.LENS_FOCUS_DISTANCE) ));
Log.e(TAG, String.format("AF mode %s-%s", ctlAfModeToString(result.get(CaptureResult.CONTROL_AF_MODE)), ctlAfStateToString(result.get(CaptureResult.CONTROL_AF_STATE)) ));
}
};