SHARE
TWEET

Untitled

a guest Sep 19th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top