From a7784a14868dfdb58ca01ff68b654f99d59b61fe Mon Sep 17 00:00:00 2001 From: unknown <695292202@qq.com> Date: Wed, 29 Oct 2025 10:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- surround_view/param_settings.py | 82 +++++++++++++++++++++++---------- surround_view/simple_gui.py | 23 +++++---- yaml/front.yaml | 19 ++++---- 3 files changed, 80 insertions(+), 44 deletions(-) diff --git a/surround_view/param_settings.py b/surround_view/param_settings.py index 9fe9cac..6da3778 100644 --- a/surround_view/param_settings.py +++ b/surround_view/param_settings.py @@ -2,62 +2,94 @@ import os import cv2 +# 摄像头名称列表 camera_names = ["front", "back", "left", "right"] -# -------------------------------------------------------------------- -# (shift_width, shift_height): how far away the birdview looks outside -# of the calibration pattern in horizontal and vertical directions +# 标定布向外扩展的尺寸,单位为像素,默认不修改 shift_w = 300 shift_h = 300 -# size of the gap between the calibration pattern and the car -# in horizontal and vertical directions -inn_shift_w = 20 -inn_shift_h = 50 +# 标定布的长和宽 +cal_w = 3000 +cal_h = 3500 -# total width/height of the stitched image -total_w = 800 + 2 * shift_w -total_h = 960 + 2 * shift_h +# 标定布四角的长和宽 +conner_w = 1000 +conner_h = 1000 -# four corners of the rectangular region occupied by the car -# top-left (x_left, y_top), bottom-right (x_right, y_bottom) -xl = shift_w + 180 + inn_shift_w +# 车辆的长和宽 +car_w = 300 +car_h = 550 + +# 车辆与标定布指定四角之间的间隙 +inn_shift_w = (cal_w - 2 * conner_w - car_w)//2 +inn_shift_h = (cal_h - 2 * conner_h - car_h)//2 + +# 图片的总宽度和总高度 +total_w = cal_w + 2 * shift_w +total_h = cal_h + 2 * shift_h + +# 车辆所占矩形区域的四个角坐标 +# 左上角 (x_left, y_top),右下角 (x_right, y_bottom) +xl = shift_w + conner_w + inn_shift_w xr = total_w - xl -yt = shift_h + 200 + inn_shift_h +yt = shift_h + conner_h + inn_shift_h yb = total_h - yt # -------------------------------------------------------------------- +# 各摄像头投影区域的尺寸 project_shapes = { - "front": (total_w, yt), - "back": (total_w, yt), - "left": (total_h, xl), - "right": (total_h, xl) + "front": (total_w, yt), # 前摄像头:(宽度, 高度) + "back": (total_w, yt), # 后摄像头:(宽度, 高度) + "left": (total_h, xl), # 左摄像头:(宽度, 高度) + "right": (total_h, xl) # 右摄像头:(宽度, 高度) } -# pixel locations of the four points to be chosen. -# you must click these pixels in the same order when running -# the get_projection_map.py script +# 待选择的四个点的像素位置 +# 运行 get_projection_map.py 脚本时,必须按相同顺序点击这些像素 project_keypoints = { - "front": [(shift_w + 200, shift_h), + "front": [(shift_w + 200, shift_h), # 前摄像头的四个关键点坐标 (shift_w + 2800, shift_h), (shift_w + 200, shift_h + 800), (shift_w + 2800, shift_h + 800)], - "back": [(shift_w + 80, shift_h), + "back": [(shift_w + 80, shift_h), # 后摄像头的四个关键点坐标 (shift_w + 320, shift_h), (shift_w + 80, shift_h + 200), (shift_w + 320, shift_h + 200)], - "left": [(shift_w + 80, shift_h), + "left": [(shift_w + 80, shift_h), # 左摄像头的四个关键点坐标 (shift_w + 320, shift_h), (shift_w + 80, shift_h + 200), (shift_w + 320, shift_h + 200)], - "right": [(shift_h + 240, shift_w), + "right": [(shift_h + 240, shift_w), # 右摄像头的四个关键点坐标 (shift_h + 560, shift_w), (shift_h + 240, shift_w + 120), (shift_h + 560, shift_w + 120)], } +# 读取车辆图片并调整尺寸以匹配车辆所在区域 car_image = cv2.imread(os.path.join(os.getcwd(), "images", "car.png")) car_image = cv2.resize(car_image, (xr - xl, yb - yt)) + +# 输出所有参数 +print("--------------------------------------------------------------------") +print(f"总宽度:{total_w}") +print(f"总高度:{total_h}") +print(f"车辆宽度:{car_w}") +print(f"车辆高度:{car_h}") +print(f"标定布宽度:{cal_w}") +print(f"标定布高度:{cal_h}") +print(f"标定布内四角宽度:{conner_w}") +print(f"标定布内四角高度:{conner_h}") +print(f"标定布外扩展宽度:{shift_w}") +print(f"标定布外扩展高度:{shift_h}") +print(f"车辆所在区域内间隙宽度:{inn_shift_w}") +print(f"车辆所在区域内间隙高度:{inn_shift_h}") +print(f"车辆所在区域左上角:({xl}, {yt})") +print(f"车辆所在区域右下角:({xr}, {yb})") +print(f"车辆所在区域四角坐标:{project_keypoints}") +print(f"投影区域尺寸:{project_shapes}") + +print("--------------------------------------------------------------------") diff --git a/surround_view/simple_gui.py b/surround_view/simple_gui.py index e6e6a64..eb6ba61 100644 --- a/surround_view/simple_gui.py +++ b/surround_view/simple_gui.py @@ -45,11 +45,24 @@ class PointSelector(object): self.window_width = image.shape[1] self.window_height = image.shape[0] self.scale = 1.0 # 缩放比例 + self.last_window_size = (self.window_width, self.window_height) def draw_image(self): """ Display the selected keypoints and draw the convex hull. """ + # 检查窗口大小是否改变 + current_width = cv2.getWindowImageRect(self.title)[2] if cv2.getWindowProperty(self.title, cv2.WND_PROP_VISIBLE) >= 1 else self.window_width + current_height = cv2.getWindowImageRect(self.title)[3] if cv2.getWindowProperty(self.title, cv2.WND_PROP_VISIBLE) >= 1 else self.window_height + + if current_width != self.last_window_size[0] or current_height != self.last_window_size[1]: + self.window_width = current_width + self.window_height = current_height + self.last_window_size = (current_width, current_height) + # 计算新的缩放比例 + self.scale = min(current_width / self.original_image.shape[1], + current_height / self.original_image.shape[0]) + # 基于当前缩放比例调整点坐标 scaled_keypoints = [ (int(x * self.scale), int(y * self.scale)) @@ -91,14 +104,6 @@ class PointSelector(object): print(f"click ({orig_x}, {orig_y}) (scaled: ({x}, {y}))") self.keypoints.append((orig_x, orig_y)) self.draw_image() - # 窗口大小改变事件 - elif event == cv2.EVENT_RESIZE: - self.window_width = x - self.window_height = y - # 计算新的缩放比例 - self.scale = min(x / self.original_image.shape[1], - y / self.original_image.shape[0]) - self.draw_image() def loop(self): """ @@ -155,4 +160,4 @@ class PointSelector(object): mask = np.array(mask, dtype=np.uint8) new_mask = cv2.bitwise_and(new_image, new_image, mask=mask) cv2.addWeighted(image, 1.0, new_mask, 0.5, 0.0, image) - return image + return image \ No newline at end of file diff --git a/yaml/front.yaml b/yaml/front.yaml index 5d8b8a4..0591ddd 100644 --- a/yaml/front.yaml +++ b/yaml/front.yaml @@ -4,14 +4,14 @@ camera_matrix: !!opencv-matrix rows: 3 cols: 3 dt: d - data: [ 9.1297883483233306e+02, 0., 1.1530623178818100e+03, 0., - 9.3430332152657456e+02, 7.0322316308984716e+02, 0., 0., 1. ] + data: [ 912.97883483233306, 0., 1153.06231788181, 0., + 934.30332152657456, 703.22316308984716, 0., 0., 1. ] dist_coeffs: !!opencv-matrix rows: 4 cols: 1 dt: d - data: [ -2.2262094222158474e-01, 9.1910107741035543e-02, - -1.1125663233319319e-01, 5.2563645197652560e-02 ] + data: [ -0.22262094222158474, 0.091910107741035543, + -0.11125663233319319, 0.05256364519765256 ] resolution: !!opencv-matrix rows: 2 cols: 1 @@ -21,17 +21,16 @@ project_matrix: !!opencv-matrix rows: 3 cols: 3 dt: d - data: [ -2.8283572994274103e-01, -1.2971399339352716e+00, - 1.0824292174928530e+03, 2.5824309209632131e-02, - -1.3252387496909435e+00, 1.0023621246915676e+03, - 3.7653658154558861e-05, -1.6884376226546168e-03, 1. ] + data: [ -5.4156645669996912, -9.3442896959392545, 7401.7924039391992, + 0.29915864114461999, -10.301469369661787, 5333.8769633702723, + 2.208437292348208e-05, -0.0050239538618510439, 1. ] scale_xy: !!opencv-matrix rows: 2 cols: 1 dt: f - data: [ 6.99999988e-01, 8.00000012e-01 ] + data: [ 0.699999988, 0.800000012 ] shift_xy: !!opencv-matrix rows: 2 cols: 1 dt: f - data: [ -150., -100. ] + data: [ -150., -500. ]