优化参数

This commit is contained in:
2025-10-29 10:34:57 +08:00
parent eb544da71d
commit a7784a1486
3 changed files with 80 additions and 44 deletions

View File

@@ -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