Advertisement
Guest User

Untitled

a guest
May 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1.     cv::findContours(thresh, cnts, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
  2.     current_result = img->clone();
  3.     for (int i = 0; i < cnts.size(); i++) {
  4.         std::pair<int, int> x = { img->size().width, 0 }, y = { img->size().height, 0 };
  5.         for (int z = 0; z < cnts[i].size(); ++z) {
  6.             x.first = std::min(cnts[i][z].x, x.first);
  7.             x.second = std::max(cnts[i][z].x, x.second);
  8.             y.first = std::min(cnts[i][z].y, y.first);
  9.             y.second = std::max(cnts[i][z].y, y.second);
  10.         }
  11.         cv::Rect bb(x.first, y.first, x.second - x.first, y.second - y.first);
  12.         if (bb.area() < settings_.lower_area) continue;
  13.         if (bb.area() > settings_.upper_area) continue;
  14.         detection_result = true;
  15.         cv::rectangle(current_result, bb, cv::Scalar(0, 0, 255));
  16.     }
  17.     return detection_result;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement