【问题标题】:find distance between contours/objects in opencv在opencv中查找轮廓/对象之间的距离
【发布时间】:2011-11-17 09:08:32
【问题描述】:

我使用 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)) );

这是正确的方法吗?

【问题讨论】:

  • 首先阅读 C++ 手册,然后阅读 OpenCV 文档。你的问题表明你完全没有努力。
  • 是的,我明白,我应该这样做,但由于截止日期太早,我没有足够的时间彻底学习东西。但是,我会在截止日期后详细介绍。你现在能帮帮我吗?
  • 由于contour1和contour2是指针,所以至少要写contour1->x - contour2->x等等...
  • 我已经编辑了代码,告诉我,这是否正确?
  • 我不知道 OpenCV API。您需要自己检查 CvPoint 的定义来回答这个问题。如果它像typedef struct _CvPoint{double x; double y; \* and morestuff *\} CvPoint; 那么是的。检查您的头文件...并阅读有关 OpenCV 结构的更多信息。

标签: c++ c image-processing syntax opencv


【解决方案1】:

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

希望有帮助!

【讨论】:

  • 它们的质心之间的距离可以很大,同时边界之间的距离可以很小。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-09
  • 2015-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
相关资源
最近更新 更多