OpenCV中计算二值图像的重心

int aoiGravityCenter(IplImage *src, CvPoint &center)
{
 //if(!src)
 // return GRAVITYCENTER__SRC_IS_NULL;
 double m00, m10, m01;
 CvMoments moment;
 cvMoments( src, &moment, 1);
 m00 = cvGetSpatialMoment( &moment, 0, 0 );
 if( m00 == 0)
  return 1;
 m10 = cvGetSpatialMoment( &moment, 1, 0 );
 m01 = cvGetSpatialMoment( &moment, 0, 1 );
 center.x = (int) (m10/m00);
 center.y = (int) (m01/m00);
 return 0;
}

你可能感兴趣的:(OpenCV中计算二值图像的重心)