fix: correct_rect在rect负方向完全越界时依旧输出非0宽度结果

This commit is contained in:
status102
2026-05-03 11:13:21 +08:00
parent 3b909f3959
commit cfa3fedb0c

View File

@@ -106,8 +106,13 @@ Rect VisionHelper::correct_rect(const Rect& rect, const cv::Mat& image)
}
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);
res.width = std::clamp(res.width, 0, image.cols - res.x);
res.height = std::clamp(res.height, 0, image.rows - res.y);
if (res.empty()) {
Log.warn(__FUNCTION__, "roi is empty after correction");
return { 1, 1, 0, 0 }; // 临时修复, 后续需调整默认rect的行为
}
if (res != rect) {
Log.warn(__FUNCTION__, "roi is out of range", image.cols, image.rows, rect.to_string(), "clamped");