如何使用camera2 API获取从对象到Android设备的距离

时间:2016-11-23 13:01:59

标签: android android-camera2

我想使用android camera2 API获取从对象到Android设备的距离。在CaptureCallback中,我按result.get(CaptureResult.LENS_FOCUS_DISTANCE)获取值,并同时检查LENS_STATE, CONTROL_AF_MODE, CONTROL_AF_STATE。它们是“STATIONARY”,CONTINUOUS_PICTUREPASSIVE_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)) ));
    }
};

1 个答案:

答案 0 :(得分:1)

请检查CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION的值。如果它是UNCALIBRATED或APPROXIMATE,那么LENS_FOCUS_DISTANCE的值可能不会接近现实。

即使使用CALIBRATED,距离越远,对象越远,对于相机,超焦距离(最多几米)的所有内容都无法准确测量距离。