This commit is contained in:
2025-10-31 09:55:58 +08:00
parent a7784a1486
commit 1f841c373f
8 changed files with 64 additions and 68 deletions

View File

@@ -1,7 +1,6 @@
import os
import cv2
# 摄像头名称列表
camera_names = ["front", "back", "left", "right"]
@@ -22,8 +21,8 @@ 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
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
@@ -39,34 +38,34 @@ 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) # 右摄像头:(宽度, 高度)
}
# 待选择的四个点的像素位置
# 运行 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), # 后摄像头的四个关键点坐标
(shift_w + 320, shift_h),
(shift_w + 80, shift_h + 200),
(shift_w + 320, shift_h + 200)],
"back": [(shift_w + 200, shift_h),
(shift_w + 2800, shift_h),
(shift_w + 200, shift_h + 500),
(shift_w + 2800, shift_h + 500)],
"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), # 右摄像头的四个关键点坐标
(shift_h + 560, shift_w),
(shift_h + 240, shift_w + 120),
(shift_h + 560, shift_w + 120)],
"left": [(shift_w + 300, shift_h),
(shift_w + 3200, shift_h),
(shift_w + 300, shift_h + 700),
(shift_w + 3200, shift_h + 700)],
"right": [(shift_h + 500, shift_w),
(shift_h + 3300, shift_w),
(shift_h + 500, shift_w + 600),
(shift_h + 3300, shift_w + 600)],
}
# 读取车辆图片并调整尺寸以匹配车辆所在区域

View File

@@ -45,24 +45,11 @@ 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))
@@ -104,6 +91,14 @@ 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):
"""
@@ -160,4 +155,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