Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <opencv2/core.hpp>
  2.  
  3. static bool fixBound(cv::Rect &rect, const cv::Size &roi) {
  4. bool ok = true;
  5. if (rect.width <= 0) {
  6. ok = false;
  7. rect.width = roi.width;
  8. }
  9. if (rect.height <= 0) {
  10. ok = false;
  11. rect.height = roi.height;
  12. }
  13. if (rect.x < 0) rect.x = 0;
  14. if (rect.y < 0) rect.y = 0;
  15. if (rect.x >= roi.width)
  16. rect.x = roi.width - rect.width;
  17. if (rect.y >= roi.height)
  18. rect.y = roi.height - rect.height;
  19. if (rect.x + rect.width > roi.width)
  20. rect.width = roi.width - rect.x;
  21. if (rect.y + rect.height > roi.height)
  22. rect.height = roi.height - rect.y;
  23. if (rect.width > roi.width)
  24. rect.width = roi.width;
  25. if (rect.height > roi.height)
  26. rect.height = roi.height;
  27. if (rect.x < 0) rect.x = 0;
  28. if (rect.y < 0) rect.y = 0;
  29. return ok;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement