From 087c34a67dbc84e674f01514759e9563feef66ee Mon Sep 17 00:00:00 2001 From: DavidWang19 Date: Sun, 14 Dec 2025 20:52:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=AE=A9=E6=88=AA=E5=9B=BE=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=94=AF=E6=8C=81=E4=BB=8Esrc/=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E6=88=AA=E5=9B=BE=E4=B9=9F=E7=BC=A9=E6=94=BE=E5=88=B0?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E5=88=86=E8=BE=A8=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/ImageCropper/main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/ImageCropper/main.py b/tools/ImageCropper/main.py index a73c313fc9..a658c2951c 100644 --- a/tools/ImageCropper/main.py +++ b/tools/ImageCropper/main.py @@ -242,6 +242,19 @@ def screenshot() -> Optional[np.ndarray]: return image +# 缩放图片到目标短边 +def resize_to_target_short_side(image: np.ndarray, target_short_side: int = 720) -> np.ndarray: + height, width = image.shape[:2] + short_side = min(width, height) + if short_side == target_short_side: + return image # 不需要缩放 + scale = target_short_side / short_side + new_width = int(round(width * scale)) + new_height = int(round(height * scale)) + print(f"Resizing image from {width}x{height} to {new_width}x{new_height}") + return cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_AREA) + + # 获取标准化的 Roimage def get_std_roimage() -> Optional[Roimage]: global file_name @@ -250,6 +263,8 @@ def get_std_roimage() -> Optional[Roimage]: file_name = files.pop(0) image = readfile(file_name) file_name = file_name.split(".")[0] + if image is not None: + image = resize_to_target_short_side(image, 720) elif controller: image = screenshot() file_name = datetime.now().strftime("%H%M%S") # '%Y%m%d%H%M%S'