首页 文章

OpenCV - 用于立体视觉的倾斜摄像机和三角测量地标

提问于
浏览
5

我正在使用立体声系统,因此我试图通过三角测量获得某些点的世界坐标 .

我的相机呈现一个角度,Z轴方向(深度方向)与我的表面不正常 . 这就是为什么当我观察平面时,我得不到恒定的深度而是“线性”变化,对吗?我希望从基线方向的深度...我如何重新投射?

enter image description here

我的代码与我的投射数组和三角函数:

#C1 and C2 are the cameras matrix (left and rig)
#R_0 and T_0 are the transformation between cameras
#Coord1 and Coord2 are the correspondant coordinates of left and right respectively
P1 = np.dot(C1,np.hstack((np.identity(3),np.zeros((3,1))))) 

P2 =np.dot(C2,np.hstack(((R_0),T_0)))

for i in range(Coord1.shape[0])
    z = cv2.triangulatePoints(P1, P2, Coord1[i,],Coord2[i,])

--------编辑以后-----------

谢谢scribbleink,所以我试图应用你的提议 . 但我认为我有一个错误,因为它不能很好地工作,你可以在下面看到 . 并且点 Cloud 似乎被弯曲并朝向图像的边缘弯曲 .

enter image description here

U, S, Vt = linalg.svd(F)
V = Vt.T

#Right epipol
U[:,2]/U[2,2]

# The expected X-direction with C1 camera matri and C1[0,0] the focal length
vecteurX = np.array([(U[:,2]/U[2,2])[0],(U[:,2]/U[2,2])[1],C1[0,0]])
vecteurX_unit = vecteurX/np.sqrt(vecteurX[0]**2 + vecteurX[1]**2 + vecteurX[2]**2)


# The expected Y axis :
height = 2048
vecteurY = np.array([0, height -1, 0])
vecteurY_unit = vecteurY/np.sqrt(vecteurY[0]**2 + vecteurY[1]**2 + vecteurY[2]**2)


# The expected Z direction :
vecteurZ = np.cross(vecteurX,vecteurY)
vecteurZ_unit = vecteurZ/np.sqrt(vecteurZ[0]**2 + vecteurZ[1]**2 + vecteurZ[2]**2)

#Normal of the Z optical (the current Z direction)
Zopitcal = np.array([0,0,1])

cos_theta = np.arccos(np.dot(vecteurZ_unit, Zopitcal)/np.sqrt(vecteurZ_unit[0]**2 + vecteurZ_unit[1]**2 + vecteurZ_unit[2]**2)*np.sqrt(Zopitcal[0]**2 + Zopitcal[1]**2 + Zopitcal[2]**2))

sin_theta = (np.cross(vecteurZ_unit, Zopitcal))[1]

#Definition of the Rodrigues vector and use of cv2.Rodrigues to get rotation matrix
v1 = Zopitcal  
v2 = vecteurZ_unit 

v_rodrigues = v1*cos_theta + (np.cross(v2,v1))*sin_theta + v2*(np.cross(v2,v1))*(1. - cos_theta)
R = cv2.Rodrigues(v_rodrigues)[0]

2 回答

  • 5

    您期望的z方向对于重建方法是任意的 . 通常,您有一个旋转矩阵,可以从您想要的方向旋转左摄像机 . 您可以轻松构建该矩阵,然后您需要做的就是将重建点乘以R的转置 .

  • 5

    为了增加fireant的响应,这里有一个候选解决方案,假设预期的X方向与连接两个摄像机的投影中心的线重合 .

    • 计算焦距f_1和f_2(通过针孔模型校准) .

    • 解决相机2 's epipole in camera 1' s帧的位置 . 为此,您可以使用立体相机对的基本矩阵(F)或基本矩阵(E) . 具体来说,左侧和右侧的epipoles位于F的零空间中,因此您可以使用Singular Value Decomposition . 有关可靠的理论参考,请参阅Hartley和Zisserman,第二版,表9.1 "Summary of fundamental matrix properties",第246页(freely available PDF of the chapter) .
      摄像机1的投影中心,即(0,0,0)和右侧极管的位置,即(e_x,e_y,f_1)一起限定了与连接摄像机中心的线对齐的光线 . 这可以用作预期的X方向 . 将此向量称为v_x .

    • 假设预期的Y轴在图像平面中朝下,即从(0,0,f_1)到(0,高度-1,f_1),其中f是焦距 . 将此向量称为v_y .

    • 预期的Z方向现在是向量v_x和v_y的叉积 .

    • 使用预期的Z方向以及摄像机1的光轴(Z轴),然后可以使用this other stackoverflow post中列出的方法从两个3D矢量计算旋转矩阵 .

    Practical note: 在我的实际经验中,如果没有相当大的努力,期望平面物体与立体基线完全对齐是不可能的 . 需要一定量的平面拟合和额外的旋转 .

    One-time effort: 这取决于您是否需要这样做一次,例如对于一次性校准,在这种情况下只需实时进行此估算过程,然后旋转立体相机对,直到深度图方差最小化 . 然后锁定你的相机位置,并祈祷有人不会碰到它 .

    Repeatability: 如果您需要将估计的深度图对齐到真正任意的Z轴,这些Z轴会针对捕获的每个新帧进行更改,那么您应该考虑在平面估算方法中投入时间并使其更加稳健 .

相关问题