使用位姿估计来计算两个相机中心之间的距离误差
两个摄像头固定在杆上。两个摄像机之间的距离是恒定的。这两个摄像头并不相同,因此不应将它们视为立体摄像头。我使用标记(solvePnP)测量两个摄像机中心之间的距离。所有姿势的距离应该是恒定且相等的,但是当我移动杆时,计算出的距离正在变化。什么可能导致错误?
while(camera1.isGrabbing() and camera2.isGrabbing()):
found,rvec_1,tvec_1 = cv2.solvePnP(object_3d_points, camera1_object_2d_points, camera1_matrix, camera1_dist_coefs)
rotM_1 = cv2.Rodrigues(rvec_1)[0]
camera1_Position = -np.matrix(rotM_1).T * np.matrix(tvec_1)
found,rvec_2,tvec_2 = cv2.solvePnP(object_3d_points, camera2_object_2d_points, camera2_matrix, camera2_dist_coefs)
rotM_2 = cv2.Rodrigues(rvec_2)[0]
camera2_Position = -np.matrix(rotM_2).T * np.matrix(tvec_2)
p1 = np.array([camera1_Position[0], camera1_Position[1], camera1_Position[2]])
p2 = np.array([camera2_Position[0], camera2_Position[1], camera2_Position[2]])
squared_distance = np.sum((p1-p2)**2, axis=0)
dis = np.sqrtsquared_distance
print("Distance:>",dis)
Two cameras are fixed to rod. Distance is constant between two cameras. These two cameras are not the identical, so they should not be considered as a stereo. I measure distance between two cameras center by using marker(solvePnP). The distance should be constant and equal for all pose but while I am moving the rod, calculated distance is changing. What could be causing the error?
while(camera1.isGrabbing() and camera2.isGrabbing()):
found,rvec_1,tvec_1 = cv2.solvePnP(object_3d_points, camera1_object_2d_points, camera1_matrix, camera1_dist_coefs)
rotM_1 = cv2.Rodrigues(rvec_1)[0]
camera1_Position = -np.matrix(rotM_1).T * np.matrix(tvec_1)
found,rvec_2,tvec_2 = cv2.solvePnP(object_3d_points, camera2_object_2d_points, camera2_matrix, camera2_dist_coefs)
rotM_2 = cv2.Rodrigues(rvec_2)[0]
camera2_Position = -np.matrix(rotM_2).T * np.matrix(tvec_2)
p1 = np.array([camera1_Position[0], camera1_Position[1], camera1_Position[2]])
p2 = np.array([camera2_Position[0], camera2_Position[1], camera2_Position[2]])
squared_distance = np.sum((p1-p2)**2, axis=0)
dis = np.sqrtsquared_distance
print("Distance:>",dis)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的情况下,这可能是相机校准的问题。正如您所假设的,计算出的相机之间的距离应该是恒定的,但这只会发生在具有完美相机模型的完美世界中。使用 opencv,您使用的是简化的针孔相机模型,该模型有一些限制,因此您必须预料到结果中会出现错误。 SolvePnp 函数很容易出现校准不准确的情况,因此您应该关注这部分以改善结果。您可以在这里找到一些校准过程的提示:
https://dsp.stackexchange.com/questions/第1567章 1567
然而,您永远不会获得零误差(恒定)距离。
您还应该向我们提供您站点的一些数值数据,例如相机分辨率、镜头焦距、几何形状以及估计(物理测量、期望值)和计算距离,以便我们可以判断您是否期望更好的结果。
In your case it might be the matter of camera calibration. As you assumed, calculated distance between cameras should be constant, but it would only happen in a perfect world, with a perfect camera model. With opencv you are using a simplified pinhole camera model, which has some limitations, so that you have to expect errors in your results. SolvePnp function is prone to calibration inaccuracies, so you should probably focus on this part to improve the results. Here you can find some tips for calibration process:
https://dsp.stackexchange.com/questions/1567/how-do-i-get-the-most-accurate-camera-calibration
Nevertheless, you will never get zero-error (constant) distance.
You should also provide us with some numerical data of your station, like camera resolution, lens focal length, geometry and estimated(physicly measured, expected value) and calculated distance, so we could tell if you may expect better results.