Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Get the mass centers:
- vector<Point2f> mc( contours.size() );
- for( int i = 0; i < contours.size(); i++ )
- { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
- #include "opencv2opencv.hpp"
- #include <vector>
- using namespace std;
- using namespace cv;
- int main()
- {
- Mat1b gray = imread("path_to_image", IMREAD_GRAYSCALE);
- Moments mu = moments(gray, true);
- Point center;
- center.x = mu.m10 / mu.m00;
- center.y = mu.m01 / mu.m00;
- Mat3b res;
- cvtColor(gray, res, CV_GRAY2BGR);
- circle(res, center, 3, Scalar(0,0,255));
- imshow("Result", res);
- waitKey();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement