【发布时间】: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