Revert "fix: 超出范围的Rect使用{0, 0, 0, 0}代替原样返回, x, y为负值时width和height改正错误 (#15695)"

This reverts commit 667a82ede4.
This commit is contained in:
status102
2026-02-26 12:32:54 +08:00
parent 23c65b6e54
commit 489d94df7c

View File

@@ -83,20 +83,14 @@ 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 || rect.x + rect.width < 0 || rect.y + rect.height < 0) {
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 { 0, 0, 0, 0 };
return rect;
}
Rect res = rect;
res.x = std::clamp(res.x, 0, image.cols - 1);
res.y = std::clamp(res.y, 0, image.rows - 1);
if (res.x > rect.x) {
res.width = rect.width - (res.x - rect.x);
}
if (res.y > rect.y) {
res.height = rect.height - (res.y - rect.y);
}
res.width = std::clamp(res.width, 1, image.cols - res.x);
res.height = std::clamp(res.height, 1, image.rows - res.y);