![](/img/trans.png)
[英]How can I calculate the distance between two cameras (opencv-python)?
[英]How can I transform coordinate between two cameras using openCV?
我有兩個英特爾實感攝像頭:Camera Left和 Camera Right 。我正在嘗試找到這兩個攝像頭之間的旋轉矩陣和變換矢量,因此我可以在兩個攝像頭之間變換坐標系。
這是我嘗試過的:
1.我使用 cv.calibrateCamera() 得到內在矩陣: M left and M right
2.我使用cv.stereoCalibrate()得到旋轉矩陣R和變換向量T
3.我同時拍了兩張照片,分別是P左和P右。
4.(u left , v left ) 和 (u right , v right ) 在兩張圖片中表示相同的 object。 具有內在矩陣 M left , M right和深度 D left , D right和 (u left , v left ), (u right , v right ),我得到相機坐標 (X left , Y left , Z left ) 和 (X對, Y對, Z對)。
這是問題所在:
在我的假設中, R *(X left , Y left , Z left ) + T = (X right , Y right , Z right )。 但結果並非如此。
這是我的代碼:
import numpy as np
import h5py
import cv2
cameraMatLeft = np.array([
[
1286.540148375528,
0.0,
929.5596785987797
],
[
0.0,
1272.8889372475517,
586.0340979684613
],
[
0.0,
0.0,
1.0
]
])
cameraMatRight = np.array([
[
1294.8590822926074,
0.0,
976.7466553094133
],
[
0.0,
1283.5006893318534,
520.6437123281569
],
[
0.0,
0.0,
1.0
]
])
R = np.array([
[
0.736828762715704,
0.1290536263233139,
0.6636479005976342
],
[
-0.09833992557804119,
0.9916309806151367,
-0.08364961040894248
],
[
-0.6688891040166153,
-0.0036276462155228617,
0.7433533525254223
]
])
T = np.array([
[
-190.9527690494799
],
[
11.868938400892926
],
[
71.571368261639625
]
])
# two pixel point
rightPoint = (1107,568)
leftPoint = (1840,697)
fLeft = h5py.File('C:\\SMIIP\\camera\\depth_pics\\leftDepth0.h5','r')
fRight = h5py.File('C:\\SMIIP\\camera\\depth_pics\\rightDepth0.h5','r')
d_left = fLeft['depth'][leftPoint[1], leftPoint[0]]
d_right = fRight['depth'][rightPoint[1], rightPoint[0]]
#print(d_left)
#print(d_right)
leftInv = np.linalg.inv(cameraMatLeft)
RightInv = np.linalg.inv(cameraMatRight)
leftPixPoint = np.array([d_left*leftPoint[0], d_left*leftPoint[1], d_left])
rightPixPoint = np.array([d_right*rightPoint[0], d_right*rightPoint[1], d_right])
#compute the camera coordinate
leftResult = np.matmul(leftInv, leftPixPoint)
rightResult = np.matmul(RightInv, rightPixPoint)
leftResult = leftResult.reshape(3, 1)
rightResult = rightResult.reshape(3, 1)
leftRotated = np.matmul(R, leftResult) + T
rightRotated = np.matmul(R, rightResult) + T
print(leftResult,rightResult)
#print(leftRotated, rightRotated)
難道我做錯了什么? 請幫幫我。 任何幫助將非常感激。
我認為您所做的並非完全錯誤,但我不確定您用於將 left_cam 坐標轉換為 right_cam 坐標的公式。 從我在這個參考上看到的: 這里。
因此,根據他們所說的 Pr=R(Pl-T)。 不確定這會解決您的情況,但希望我能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.