Advertisement
Guest User

Untitled

a guest
Feb 9th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include "opencv2/highgui/highgui.hpp"
  3. #include "opencv2/imgproc/imgproc.hpp"
  4.  
  5. using namespace cv;
  6. using namespace std;
  7.  
  8. int main(int argc, char *argv[]) {
  9.  
  10.     Mat input_image = imread(argv[1], 0);
  11.  
  12.     Mat canny_op;
  13.     Canny(input_image, canny_op, 100, 200, 3);
  14.  
  15.     vector<vector<Point> > contours;
  16.     vector<Vec4i> hierarchy;
  17.     findContours( canny_op, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0) );
  18.  
  19.     cout << "Size of contours [vector] is " << contours.size() << endl;
  20.     cout << "Size of hierarchy [vector] is " << hierarchy.size() << endl;
  21.  
  22.     // Draw contours
  23.     Mat drawing = Mat::zeros( input_image.size(), CV_8UC3 );
  24.     for( int i = 0; i< contours.size(); i++ ) {
  25.         cout << i << endl;
  26.         Scalar color(0,0,255);
  27.         drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
  28.     }
  29.  
  30.     namedWindow("output here", 1);
  31.     imshow("output here", drawing);
  32.  
  33.     waitKey(0);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement