From 45b4b275663f60074a6cae36d8c7a9376587b549 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Tue, 27 Aug 2024 16:42:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87=E6=88=AA?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/image_util.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/image_util.py b/util/image_util.py index 265e208..0b30cc0 100644 --- a/util/image_util.py +++ b/util/image_util.py @@ -38,6 +38,15 @@ def capture(image, rectangle): :return: 截取之后的图片NumPy """ x1, y1, x2, y2 = rectangle + height, width = image.shape[:2] + if x1 < 0: + x1 = 0 + if y1 < 0: + y1 = 0 + if x2 > width: + x2 = width + if y2 > height: + y2 = height return image[int(y1):int(y2), int(x1):int(x2)]