itc= contours.begin();
while (itc!=contours.end()) {
// compute all moments
cv::Moments mom=cv::moments(cv::Mat(*itc++));
// draw mass center
cv::circle(result,
// position of mass center converted tointeger
cv::Point(mom.m10/mom.m00,mom.m01/mom.m00),
2,cv::Scalar(0),2); // draw black dot
}
Calculates all of the moments up to thethird order of a polygon or rasterized shape.
C++: Moments moments(InputArray array,bool binaryImage=false )
Python: cv2.moments(array[, binaryImage]) → retval
C: void cvMoments(constCvArr* arr, CvMoments* moments, int binary=0 )
Parameters: |
|
The function computes moments, up to the3rd order, of a vector shape or a rasterized shape. The results are returned inthe structure Moments defined as: