mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 10:32:19 +08:00
chore: 完全越界时报 error
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user