加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – OpenCV 2质心

发布时间:2020-12-16 05:50:00 所属栏目:百科 来源:网络整理
导读:我试图找到一个轮廓的质心,但在C(OpenCV 2.3.1)中实现示例代码时遇到麻烦.谁能帮我吗? 解决方法 要找到轮廓的重心,可以使用时刻的方法.并且功能实现OpenCV. 查看这些时刻功能(central and spatial moments). 以下代码取自OpenCV 2.3 docs教程. Full code he
我试图找到一个轮廓的质心,但在C(OpenCV 2.3.1)中实现示例代码时遇到麻烦.谁能帮我吗?

解决方法

要找到轮廓的重心,可以使用时刻的方法.并且功能实现OpenCV.

查看这些时刻功能(central and spatial moments).

以下代码取自OpenCV 2.3 docs教程. Full code here.

/// Find contours
findContours( canny_output,contours,hierarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0) );

/// Get the moments
vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ )
 { mu[i] = moments( contours[i],false ); }

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

也是check out this SOF,虽然它是在Python,它将是有用的.它找到轮廓的所有参数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读