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

Alt*_*ape 2 c++ opencv computer-vision

我有一个CvSeq*包含通过在b&w输入图像上运行cvFindContors创建的CvSeq*上运行cvApproxPoly()而创建的多边形.我想访问从CvSeq*返回的每个多边形的CvPoints.代码到目前为止(轮廓是包含黑白输入图像的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);
Run Code Online (Sandbox Code Playgroud)

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

Kau*_*rya 5

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