如何使用camera2 API获取从对象到Android设备的距离 [英] How to get the distance from an object to android device using camera2 API
问题描述
我想使用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
是距离估计的正确值吗?有人知道吗?
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)) ));
}
};
推荐答案
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.
这篇关于如何使用camera2 API获取从对象到Android设备的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!