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 );
}

相关文章:

  • 2021-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-11-23
  • 2021-08-18
  • 2022-12-23
  • 2021-09-02
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2021-06-01
  • 2021-09-23
  • 2021-06-27
  • 2021-06-08
相关资源
相似解决方案