Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. vector<Rect> detectContours(Mat img)
  2. {
  3. std::vector<cv::Rect> boundRect;
  4. std::vector<std::vector<cv::Point> > contours;
  5. cv::findContours(img, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
  6.  
  7. std::vector<std::vector<cv::Point> > contours_poly(contours.size());
  8. for (int i = 0; i < contours.size(); i++) {
  9. std::vector<cv::Point> contour = contours[i];
  10. if (contour.size() > 1) {
  11. cv::approxPolyDP(cv::Mat(contours[i]), contours_poly[i], 1, true);
  12. cv::Rect appRect(boundingRect(cv::Mat(contours_poly[i])));
  13. if ((appRect.height > 200) && (appRect.width > 200) && (appRect.width * 1.0 / appRect.height) > 1.5 ) {
  14. boundRect.push_back(appRect);
  15. //break;
  16. }
  17. }
  18. }
  19. return boundRect;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement