gpt4 book ai didi

c++ - 检索由 cvApproxPoly() 创建的多边形的点

转载 作者:搜寻专家 更新时间:2023-10-30 23:49:27 25 4
gpt4 key购买 nike

我有一个 CvSeq*,其中包含通过在黑白输入图像上运行 cvFindContors 创建的 CvSeq* 上运行 cvApproxPoly() 创建的多边形。我想访问从 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; 的值得出结论),但我不知道如何访问各个点。请帮忙?

最佳答案

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

关于c++ - 检索由 cvApproxPoly() 创建的多边形的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4316952/

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