【问题标题】:Retrieving Points of Polygons created by cvApproxPoly()检索由 cvApproxPoly() 创建的多边形的点
【发布时间】:2010-11-30 18:07:32
【问题描述】:

我有一个 CvSeq*,其中包含通过在 CvSeq* 上运行 cvApproxPoly() 创建的多边形,该 CvSeq* 是通过在黑白输入图像上运行 cvFindContors 创建的。我想访问从 CvSeq* 返回的每个多边形的 CvPoints。到目前为止的代码如下(outlines 是一个包含黑白输入图像的 IplImage):

//create pointers to store data we're going to be calculating
CvMemStorage* storage = cvCreateMemStorage();
CvSeq* first_contour = NULL;
CvSeq* first_polygon = NULL;

//find the contours (edges) of the silhouette, in terms of pixels.
cvFindContours( &outlines,
                storage,
                &first_contour,
                sizeof(CvContour),
                CV_RETR_LIST );

//convert the pixel contours to line segments in a polygon.
first_polygon = cvApproxPoly(first_contour, 
                             sizeof(CvContour), 
                             storage,
                             CV_POLY_APPROX_DP, 
                             2,
                             1);

我可以使用 cvDrawContour 将多边形绘制到图像上,但我想遍历定义每个轮廓的每个 2D 点。看起来 CvSeq* first_polygon 的每个元素都包含单个多边形的点集(根据 first_polygon->total 的值得出结论;但我不知道如何访问各个点。请帮忙?

【问题讨论】:

    标签: c++ opencv computer-vision


    【解决方案1】:

    您可以使用 cvGetSeqElem 迭代多边形的顶点。 samples/c 中的 squares.c 实现了这个东西。

    【讨论】:

    • 你能告诉我这个方法在javacv中是否也可用吗?
    【解决方案2】:

    自己解决了这个问题:CvSeq* 是多维的。例如:cvSeq->total;是第一个维度(每个多边形),例如 cvSeq->first->total 是第二个维度(多边形中的每个点)。

    【讨论】:

      猜你喜欢
      • 2013-12-11
      • 2010-12-29
      • 2017-09-26
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 1970-01-01
      • 2011-12-05
      相关资源
      最近更新 更多