66 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import os
 | 
						||
import cv2
 | 
						||
 | 
						||
 | 
						||
camera_names = ["front", "back", "left", "right"]
 | 
						||
 | 
						||
# --------------------------------------------------------------------
 | 
						||
# (shift_width, shift_height): 鸟瞰图超出标定布的横向和纵向范围
 | 
						||
# 适配桌面环境,确保总范围不超过桌面尺寸
 | 
						||
shift_w = 50  # 左右方向各扩展10cm
 | 
						||
shift_h = 50  # 前后方向各扩展10cm
 | 
						||
 | 
						||
# 标定布与车身之间的间隙(横向和纵向)
 | 
						||
inn_shift_w = 5  # 左右方向间隙
 | 
						||
inn_shift_h = 8  # 前后方向间隙
 | 
						||
 | 
						||
# 标定布主体尺寸(宽×高)
 | 
						||
calib_width = 60   # 标定布宽度60cm
 | 
						||
calib_height = 100 # 标定布高度100cm
 | 
						||
 | 
						||
# 拼接后图像的总尺寸
 | 
						||
total_w = calib_width + 2 * shift_w  # 60 + 2×10 = 80cm(宽)
 | 
						||
total_h = calib_height + 2 * shift_h  # 100 + 2×10 = 120cm(高)
 | 
						||
 | 
						||
# 车身占据的矩形区域四角坐标
 | 
						||
# 确保与小车实际尺寸匹配:宽12cm,长20cm
 | 
						||
xl = shift_w + (calib_width - 12) // 2 + inn_shift_w  # 10 + 24 + 5 = 39
 | 
						||
xr = xl + 12  # 右侧坐标,确保宽度12cm
 | 
						||
yt = shift_h + (calib_height - 20) // 2 + inn_shift_h  # 10 + 40 + 8 = 58
 | 
						||
yb = yt + 20  # 底部坐标,确保长度20cm
 | 
						||
# --------------------------------------------------------------------
 | 
						||
 | 
						||
project_shapes = {
 | 
						||
    "front": (total_w, yt),          # 前相机投影区域:宽80cm × 高58cm
 | 
						||
    "back":  (total_w, total_h - yb), # 后相机投影区域:宽80cm × 高42cm
 | 
						||
    "left":  (total_h, xl),          # 左相机投影区域:高120cm × 宽39cm
 | 
						||
    "right": (total_h, total_w - xr)  # 右相机投影区域:高120cm × 宽29cm
 | 
						||
}
 | 
						||
 | 
						||
# 四个标记点的像素位置,运行get_projection_map.py时需按相同顺序点击
 | 
						||
project_keypoints = {
 | 
						||
    "front": [(shift_w + 12, shift_h),       # 前标定板左上
 | 
						||
              (shift_w + 48, shift_h),       # 前标定板右上
 | 
						||
              (shift_w + 12, shift_h + 16),  # 前标定板左下
 | 
						||
              (shift_w + 48, shift_h + 16)], # 前标定板右下
 | 
						||
 | 
						||
    "back":  [(shift_w + 12, shift_h),       # 后标定板左上
 | 
						||
              (shift_w + 48, shift_h),       # 后标定板右上
 | 
						||
              (shift_w + 12, shift_h + 16),  # 后标定板左下
 | 
						||
              (shift_w + 48, shift_h + 16)], # 后标定板右下
 | 
						||
 | 
						||
    "left":  [(shift_h + 28, shift_w),       # 左标定板左上
 | 
						||
              (shift_h + 64, shift_w),       # 左标定板右上
 | 
						||
              (shift_h + 28, shift_w + 12),  # 左标定板左下
 | 
						||
              (shift_h + 68, shift_w + 12)], # 左标定板右下
 | 
						||
 | 
						||
    "right": [(shift_h + 28, shift_w),       # 右标定板左上
 | 
						||
              (shift_h + 64, shift_w),       # 右标定板右上
 | 
						||
              (shift_h + 28, shift_w + 12),  # 右标定板左下
 | 
						||
              (shift_h + 68, shift_w + 12)]  # 右标定板右下
 | 
						||
}
 | 
						||
 | 
						||
# 加载并调整车身图标大小以匹配车身区域
 | 
						||
car_image = cv2.imread(os.path.join(os.getcwd(), "images", "car.png"))
 | 
						||
car_image = cv2.resize(car_image, (xr - xl, yb - yt))  # 调整为12×20cm的车身大小
 | 
						||
     |