gpt4 book ai didi

c++ - OpenCV 2质心

转载 作者:可可西里 更新时间:2023-11-01 16:27:47 25 4
gpt4 key购买 nike

我试图找到轮廓的质心,但在用 C++ (OpenCV 2.3.1) 实现示例代码时遇到了问题。谁能帮帮我?

最佳答案

要找到轮廓的质心,可以使用矩量法。并且函数是用 OpenCV 实现的。

查看这些矩函数 (central and spatial moments)。

以下代码摘自 OpenCV 2.3 文档教程。 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 编写的,但它会很有用。它找到轮廓的所有参数。

关于c++ - OpenCV 2质心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9074202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com