我想使用android camera2 API获取从对象到Android设备的距离。在CaptureCallback
中,我按result.get(CaptureResult.LENS_FOCUS_DISTANCE)
获取值,并同时检查LENS_STATE, CONTROL_AF_MODE, CONTROL_AF_STATE
。它们是“STATIONARY”,CONTINUOUS_PICTURE
和PASSIVE_FOCUSED
。我认为焦距应该是有效的,从对象到android设备的距离应该是1/focus_distance
。但事实上,计算值与实际距离完全不同。它出什么问题了? LENS_FOCUS_DISTANCE
是距离估算的正确值吗?有人有想法吗?
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)) ));
}
};
答案 0 :(得分:1)
请检查CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION的值。如果它是UNCALIBRATED或APPROXIMATE,那么LENS_FOCUS_DISTANCE的值可能不会接近现实。
即使使用CALIBRATED,距离越远,对象越远,对于相机,超焦距离(最多几米)的所有内容都无法准确测量距离。