只记录坑点注意点:
1.双目数据获得
原始数据获得----其实是一张图片,从中间一分为二,分别为左右相机画面
cap = cv2.VideoCapture(1)
cap.set(3,1280)
cap.set(4,480)
while True:
ret1, frame = cap.read()
# ret2, frame2 = camera2.read()
# if not ret1 or not ret2:
if ret1 != True:
break
#cv2.resize(frame, (2560, 360), interpolation=cv2.INTER_LINEAR)
dsize = (1280, 480)
imagedst = cv2.resize(frame, dsize, interpolation=cv2.INTER_LINEAR)
frame1 = imagedst[0:480, 0:640]
frame2 = imagedst[0:480, 640:1280]
2.标定数据使用
MATLAB标定双目相机流程就不介绍了,网上一堆,只记录MATLAB标定完的数据如何使用到opencv进行立体匹配,下面图片是各种标定结果
填入opencv前的中间处理
1.相机内参和旋转矩阵转置后填入
2.K1-3,P1-2按照顺序填入
3.平移矩阵直接填入
对应实际填入opencv的数据----转置后的
# 双目相机参数
class stereoCamera(object):
def __init__(self):
# 左相机内参
self.cam_matrix_left = np.array([[496.8881739318051, 29.112084239370530, 342.2427649003997],
[0., 482.43229620875210, 241.1432000960281],
[0., 0., 1.]])
# 右相机内参
self.cam_matrix_right = np.array([[500.0071875044045, 27.945379795056090, 330.7537796063574],
[0., 482.1375852282574, 245.4564457477531],
[0., 0., 1.]])
# 左右相机畸变系数:[k1, k2, p1, p2, k3]
self.distortion_l = np.array([[-0.009251249167910, 0.422804323842635, -0.005152418761053,
0.003651300040505, -0.649768579382033]])
self.distortion_r = np.array([[-0.071705287118270,1.007117302831552, -0.003344136852431,
-0.005290333871640, -2.480977479998242]])
# 旋转矩阵
self.R = np.array([[0.999166147463142, -0.0005777861684523863,0.040824942459317],
[0.0006482001597173343, 0.999998325193149, -0.001711562867902],
[-0.040823885168073, 0.001736598411085, 0.999164848573919]])
# 平移矩阵
self.T = np.array([[-117.0596521731195], [-5.996326944677823], [-2.421637085624411]])