# filename: camera_configs.py import cv2 import numpy as np import pandas as pd from configparser import ConfigParser config = ConfigParser() config.read(r'./config.ini',encoding='utf-8') path = config['camera_name']['Serial_number'] + '__camera_parameter.xlsx' df = pd.read_excel(path) odd_even = 0 x1_l, y1_l = 0, 0 x2_l, y2_l = 0, 0 x1_r, y1_r = 0, 0 x2_r, y2_r = 0, 0 threeD = [0, 0] disparity_show = [0, 0] left_camera_matrix = np.array(df.iloc[0:3, 1:4]) left_distortion = np.array([df.iloc[3, 1:6]]).astype(np.float64) right_camera_matrix = np.array(df.iloc[4:7, 1:4]) right_distortion = np.array([df.iloc[7, 1:6]]).astype(np.float64) R = np.array(df.iloc[8:11, 1:4]) T = np.array(df.iloc[11, 1:4]).astype(np.float64) size = (1600, 1200) # 图像尺寸 # 进行立体更正 R1, R2, P1, P2, Q, validPixROI1, validPixROI2 = cv2.stereoRectify(left_camera_matrix, left_distortion, right_camera_matrix, right_distortion, size, R, T, alpha=-1) # 计算更正map 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)