From bf30c84b4fb785486de2607c0121d640647e9dac Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 24 Nov 2025 02:46:18 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=AE=8C=E5=85=A8=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E6=97=B6=E6=8A=A5=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaCore/Vision/VisionHelper.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/MaaCore/Vision/VisionHelper.cpp b/src/MaaCore/Vision/VisionHelper.cpp index 377c54f0e6..0ba8b42c02 100644 --- a/src/MaaCore/Vision/VisionHelper.cpp +++ b/src/MaaCore/Vision/VisionHelper.cpp @@ -83,15 +83,19 @@ Rect VisionHelper::correct_rect(const Rect& rect, const cv::Mat& image) if (rect.empty()) { return { 0, 0, image.cols, image.rows }; } + if (rect.x >= image.cols || rect.y >= image.rows) { + Log.error(__FUNCTION__, "roi is out of range", image.cols, image.rows, rect.to_string()); + return rect; + } Rect res = rect; - res.x = std::clamp(res.x, 0, image.cols); - res.y = std::clamp(res.y, 0, image.rows); - res.width = std::clamp(res.width, 1, std::max(1, image.cols - res.x)); - res.height = std::clamp(res.height, 1, std::max(1, image.rows - res.y)); + res.x = std::clamp(res.x, 0, image.cols - 1); + res.y = std::clamp(res.y, 0, image.rows - 1); + res.width = std::clamp(res.width, 1, image.cols - res.x); + res.height = std::clamp(res.height, 1, image.rows - res.y); if (res != rect) { - Log.warn("roi is out of range", image.cols, image.rows, rect.to_string(), "clamped"); + Log.warn(__FUNCTION__, "roi is out of range", image.cols, image.rows, rect.to_string(), "clamped"); } return res;