Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. /// Get the mass centers:
  2. vector<Point2f> mc( contours.size() );
  3. for( int i = 0; i < contours.size(); i++ )
  4. { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
  5.  
  6. #include "opencv2opencv.hpp"
  7. #include <vector>
  8.  
  9. using namespace std;
  10. using namespace cv;
  11.  
  12. int main()
  13. {
  14.  
  15. Mat1b gray = imread("path_to_image", IMREAD_GRAYSCALE);
  16.  
  17. Moments mu = moments(gray, true);
  18. Point center;
  19. center.x = mu.m10 / mu.m00;
  20. center.y = mu.m01 / mu.m00;
  21.  
  22. Mat3b res;
  23. cvtColor(gray, res, CV_GRAY2BGR);
  24.  
  25. circle(res, center, 3, Scalar(0,0,255));
  26.  
  27. imshow("Result", res);
  28. waitKey();
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement