文件名称为camera_config.py
import cv2
import numpy as np
# 左相机内参
left_camera_matrix = np.array([[873.61251309 , 0. , 356.87696512],
[ 0. , 873.03610524 ,221.73936972],
[ 0. , 0. , 1. ]])
# 左相机畸变系数:[k1, k2, p1, p2, k3]
left_distortion = np.array([[ 7.51748638e-02 ,-2.04704945e-01, -8.33877116e-03 , 5.29543881e-04,
9.05803473e-01]])
# 右相机内参
right_camera_matrix = np.array([[874.96222872 , 0. , 360.15884393],
[ 0. , 874.95478977, 200.77509962],
[ 0. , 0. , 1. ]])
# 右相机畸变系数:[k1, k2, p1, p2, k3]
right_distortion = np.array([[ 0.06912893 ,-0.02179025 ,-0.00894032 , 0.0001059 , -0.09921054]])
# om = np.array([-0.00009, 0.02300, -0.00372])
# R = cv2.Rodrigues(om)[0]
# 旋转矩阵
R = np.array([[ 9.99995512e-01 , 8.94082589e-04 , 2.85932046e-03],
[-8.94577988e-04 , 9.99999585e-01 , 1.71983365e-04],
[-2.85916551e-03, -1.74540479e-04 , 9.99995897e-01]])
# 平移向量
T = np.array([[-5.71864297e+01], [-3.39736484e-02], [ 1.01933320e+00]])
size = (640, 480)
R1, R2, P1, P2, Q, validPixROI1, validPixROI2 = cv2.stereoRectify(left_camera_matrix, left_distortion,
right_camera_matrix, right_distortion, size, R,
T)
left_map1, left_map2 = cv2.initUndistortRectifyMap(left_camera_matrix, left_distortion, R1, P1, size, cv2.CV_16SC2)
right_map1, right_map2 = cv2.initUndistortRectifyMap(right_camera_matrix, right_distortion, R2, P2, size, cv2.CV_16SC2)