Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<Rect> detectContours(Mat img)
- {
- std::vector<cv::Rect> boundRect;
- std::vector<std::vector<cv::Point> > contours;
- cv::findContours(img, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
- std::vector<std::vector<cv::Point> > contours_poly(contours.size());
- for (int i = 0; i < contours.size(); i++) {
- std::vector<cv::Point> contour = contours[i];
- if (contour.size() > 1) {
- cv::approxPolyDP(cv::Mat(contours[i]), contours_poly[i], 1, true);
- cv::Rect appRect(boundingRect(cv::Mat(contours_poly[i])));
- if ((appRect.height > 200) && (appRect.width > 200) && (appRect.width * 1.0 / appRect.height) > 1.5 ) {
- boundRect.push_back(appRect);
- //break;
- }
- }
- }
- return boundRect;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement