问题
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)) ));
}
};
回答1:
Please check the value of CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION. If it's UNCALIBRATED or APPROXIMATE, then the value of LENS_FOCUS_DISTANCE will likely not be close to reality.
And even with CALIBRATED, the farther objects are, the more error there will be - to the camera, everything past the hyperfocal distance (a few meters at best) starts being impossible to accurately measure distance to.
来源:https://stackoverflow.com/questions/40765286/how-to-get-the-distance-from-an-object-to-android-device-using-camera2-api