Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/core.hpp>
- static bool fixBound(cv::Rect &rect, const cv::Size &roi) {
- bool ok = true;
- if (rect.width <= 0) {
- ok = false;
- rect.width = roi.width;
- }
- if (rect.height <= 0) {
- ok = false;
- rect.height = roi.height;
- }
- if (rect.x < 0) rect.x = 0;
- if (rect.y < 0) rect.y = 0;
- if (rect.x >= roi.width)
- rect.x = roi.width - rect.width;
- if (rect.y >= roi.height)
- rect.y = roi.height - rect.height;
- if (rect.x + rect.width > roi.width)
- rect.width = roi.width - rect.x;
- if (rect.y + rect.height > roi.height)
- rect.height = roi.height - rect.y;
- if (rect.width > roi.width)
- rect.width = roi.width;
- if (rect.height > roi.height)
- rect.height = roi.height;
- if (rect.x < 0) rect.x = 0;
- if (rect.y < 0) rect.y = 0;
- return ok;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement