[英]OpenCV - Tilted camera and triangulation landmark for stereo vision
我正在使用立體聲系統,因此我試圖通過三角測量獲得某些點的世界坐標。
我的相機呈現一個角度,Z軸方向(深度方向)與我的表面不正常。 這就是為什么當我觀察平面時,我得不到恆定的深度而是“線性”變化,對嗎? 我希望從基線方向的深度...我如何重新投射?
我的代碼與我的投射數組和三角函數:
#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,所以我試圖應用你的提議。 但我認為我有一個錯誤,因為它不能很好地工作,你可以在下面看到。 並且點雲似乎被彎曲並朝向圖像的邊緣彎曲。
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]
您期望的z方向對於重建方法是任意的。 通常,您有一個旋轉矩陣,可以從您想要的方向旋轉左攝像機。 您可以輕松構建該矩陣,然后您需要做的就是將重建點乘以R的轉置。
為了增加火力反應,這里有一個候選解決方案,假設預期的X方向與連接兩個攝像機投影中心的線重合。
實際注意事項:根據我的實際經驗,在沒有相當大的努力的情況下,期望平面物體與立體基線精確對准是不可能的。 需要一定量的平面擬合和額外的旋轉。
一次性工作:這取決於您是否需要執行此操作,例如,對於一次性校准,在這種情況下,只需實時進行此估算過程,然后旋轉立體相機對,直到深度圖方差最小化。 然后鎖定你的相機位置,並祈禱有人不會碰到它。
可重復性:如果您需要將估計的深度圖對齊到真正任意的Z軸,這些Z軸對於捕獲的每個新幀都會發生變化,那么您應該考慮在平面估算方法中投入時間並使其更加穩健。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.