How to get the distance from an object to android device using camera2 API

冷暖自知 提交于 2019-12-13 16:25:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!