Guest User

Untitled

a guest
Dec 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. int main() {
  2. std::cout << "Hello, World!" << std::endl;
  3. sorting_contours();
  4. return 0;}
  5. void sorting_contours() {
  6. Mat image = imread("6.jpg");
  7. Mat orig = image.clone();
  8. Mat gray;
  9. cvtColor(image, gray, CV_BGR2GRAY);
  10. threshold(gray, gray, 245, 255, CV_THRESH_BINARY);
  11. Mat edged = imutils::auto_canny(gray);
  12. vector<Vec4i> hierarchy;
  13. vector<vector<Point>> contours;
  14. cv::findContours(edged, contours, hierarchy, CV_RETR_EXTERNAL,
  15. CV_CHAIN_APPROX_SIMPLE);
  16. vector<Rect> boundRect;
  17. contours = imutils::sort_contours(contours, boundRect, imutils::SortContoursMethods::left_to_right);
  18. Mat sortedImage = image.clone();
  19. for (int i = 0; i < contours.size(); i++) {
  20. sortedImage = imutils::label_contour(sortedImage, vector<vector<Point> >(1, contours[i]), i,
  21. cv::Scalar(240, 0, 159));
  22. }
  23. imshow("left_to_right", sortedImage);
  24. waitKey(0);
  25.  
  26. }
Add Comment
Please, Sign In to add comment