首页 > 代码库 > 轮廓距质心计算
轮廓距质心计算
findContours(shape_threshold, contours_tmp, hierarchy_tmp,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_TC89_KCOS, Point(0, 0) );//输入图像shape_threshold发生了改变
all_edge_num_finfCon=contours_tmp.size();
Mat shape_result=Mat::zeros(threshold_out.size(), CV_8UC3 );
for( int i = 0; i< contours_tmp.size(); i++ )
drawContours( shape_result, contours_tmp, i, Scalar(128,255,128), CV_FILLED);//填充
//计算轮廓矩
vector<Moments> mu(contours_tmp.size() );
for( int i = 0; i < contours_tmp.size(); i++ )
mu[i] = moments( contours_tmp[i], false );
//计算轮廓的质心
vector<Point2f> mc( contours_tmp.size() );
for( int i = 0; i < contours_tmp.size(); i++ )
{
mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 );
circle( shape_result, mc[i], 4, Scalar(255,255,128), -1, 8, 0 );
}