我已经使用cvfindcontour找到了轮廓,现在,我想访问第一个和第二个轮廓,并找到它们之间的欧几里得距离。有人可以帮忙我的代码吗?

CvPoint *contourPoint, *contourPoint2;
contourPoint = (CvPoint *)CV_GET_SEQ_ELEM(CvPoint,contours,1);
contourPoint2 = (CvPoint *)CV_GET_SEQ_ELEM(CvPoint,contours,2);
double dis = sqrt(double((contourPoint->x - contourPoint2->x) * (contourPoint->x - contourPoint2->x) + (contourPoint->y - contourPoint2->y) * (contourPoint->y - contourPoint2->y)) );

这是正确的方法吗?

最佳答案

我将使用cvMoments计算每个轮廓的质心,然后计算两个质心之间的Euclidean distanceHere是有关openframeworks的帖子。 Here是来自opencv邮件列表的帖子。

希望有帮助!

08-18 17:36