当给定的定位点是三角形的顶点之一时,OpenCV 的 Subdiv2D / Delaunay 是否会损坏?

发布于 2024-11-28 07:03:20 字数 1656 浏览 3 评论 0原文

构建三角剖分的代码:

CvSubdiv2D *subdiv;
CvMemStorage *storage = cvCreateMemStorage(0);
CvRect rectangle = cvRect(0, 0, 100, 100);
subdiv = cvCreateSubdivDelaunay2D(rectangle, storage);
CvPoint2D32f p1 = cvPoint2D32f(10, 10);
CvPoint2D32f p2 = cvPoint2D32f(50, 10);
CvPoint2D32f p3 = cvPoint2D32f(10, 50);
cvSubdivDelaunay2DInsert(subdiv, p1);
cvSubdivDelaunay2DInsert(subdiv, p2);
cvSubdivDelaunay2DInsert(subdiv, p3);

之后,使用其中一个点进行查询:

CvSubdiv2DEdge edge;
CvSubdiv2DPoint *pp;
CvSubdiv2DPointLocation loc = cvSubdiv2DLocate(subdiv, p1, &edge, &pp);

获得结果后,您必须检查该点是否落在:

  • 小面
  • 边缘
  • 顶点
  • 定义的三角剖分/矩形之外的

在这种情况下,它是a vertex:

if(loc == CV_PTLOC_VERTEX) {
//        CvSubdiv2DPoint *tp = cvSubdiv2DEdgeOrg(edge);
//        CvPoint2D32f point = tp->pt;
//        std::cout << point.x << ", " << point.y << std::endl;

//        CvSubdiv2DPoint *tp = cvSubdiv2DEdgeOrg(pp->first);
//        CvPoint2D32f point = tp->pt;
//        std::cout << point.x << ", " << point.y << std::endl;
}

然而,我的两种方法都失败了。在前 3 行中,我尝试查看 locate 是否在参数上放置了正确的边缘。它没有,我遇到了分段错误。在第二个块上,我尝试访问 CvSubdiv2DPoint 结构中的 first 元素,但它也不起作用 - 分段错误。我无法找到 first 上的点,也无法使用它迭代其他边缘。

CvSubdiv2DPoint 无用的原因是,为了迭代结构并实际找到三角形,我需要一个 CvSubdiv2DEdge,但由于我无法从点转换对于边缘,函数的结果是无用的。

我可能忽略了一些东西,但对我来说它似乎被破坏了。 这是文档。 有什么想法吗?

The code for building a triangulation:

CvSubdiv2D *subdiv;
CvMemStorage *storage = cvCreateMemStorage(0);
CvRect rectangle = cvRect(0, 0, 100, 100);
subdiv = cvCreateSubdivDelaunay2D(rectangle, storage);
CvPoint2D32f p1 = cvPoint2D32f(10, 10);
CvPoint2D32f p2 = cvPoint2D32f(50, 10);
CvPoint2D32f p3 = cvPoint2D32f(10, 50);
cvSubdivDelaunay2DInsert(subdiv, p1);
cvSubdivDelaunay2DInsert(subdiv, p2);
cvSubdivDelaunay2DInsert(subdiv, p3);

After that, make a query using one of the points:

CvSubdiv2DEdge edge;
CvSubdiv2DPoint *pp;
CvSubdiv2DPointLocation loc = cvSubdiv2DLocate(subdiv, p1, &edge, &pp);

Once you have the results, you have to check if the point falls on:

  • facet
  • edge
  • vertex
  • outside of the defined triangulation/rectangle

In this case, it's a vertex:

if(loc == CV_PTLOC_VERTEX) {
//        CvSubdiv2DPoint *tp = cvSubdiv2DEdgeOrg(edge);
//        CvPoint2D32f point = tp->pt;
//        std::cout << point.x << ", " << point.y << std::endl;

//        CvSubdiv2DPoint *tp = cvSubdiv2DEdgeOrg(pp->first);
//        CvPoint2D32f point = tp->pt;
//        std::cout << point.x << ", " << point.y << std::endl;
}

However, both my approaches to it have failed. In the first 3 lines, I tried seeing if the locate had put the correct edge on the parameter. It didn't and I got a segmentation fault. On the second block, I tried accessing the first element in the CvSubdiv2DPoint struct but it also doesn't work -- segmentation fault. I can't find the points on first nor can I use it iterate over the other edges.

The reason CvSubdiv2DPoint is useless is because, in order to iterate through the structure and actually find the triangles, I need a CvSubdiv2DEdge, but since I can't convert from a point to an edge, the result of the function is useless.

I may have overlooked something, but to me it seems broken. Here's the documentation. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十级心震 2024-12-05 07:03:20

可以使用序列功能迭代边,这里是代码:

CvMemStorage* storage = cvCreateMemStorage();
CvSubdiv2D* subdivision = cvCreateSubdivDelaunay2D(rect, storage);
for (int i = 0; i < points.size(); ++i)
{
    cvSubdivDelaunay2DInsert(subdivision, points[i]);
}

cvCalcSubdivVoronoi2D(subdivision);
CvSeqReader reader;
CvSeq* seq = (CvSeq*) subdivision->edges;
cvStartReadSeq(seq, &reader);
for (int i = 0; i < seq->total; ++i)
{
    CvQuadEdge2D* edge = (CvQuadEdge2D*)reader.ptr;
    if (CV_IS_SET_ELEM(edge))
    {
               //Do something...
    }
    CV_NEXT_SEQ_ELEM(seq->elem_size, reader);
}

if (storage != 0)
{
    cvReleaseMemStorage(&storage);
}

虽然我没有找到迭代连接到某个顶点的边的方法,但顺便说一下,使用细分本身作为序列以相同的方式迭代顶点。

Edges can be iterated using sequence functionality here is the code:

CvMemStorage* storage = cvCreateMemStorage();
CvSubdiv2D* subdivision = cvCreateSubdivDelaunay2D(rect, storage);
for (int i = 0; i < points.size(); ++i)
{
    cvSubdivDelaunay2DInsert(subdivision, points[i]);
}

cvCalcSubdivVoronoi2D(subdivision);
CvSeqReader reader;
CvSeq* seq = (CvSeq*) subdivision->edges;
cvStartReadSeq(seq, &reader);
for (int i = 0; i < seq->total; ++i)
{
    CvQuadEdge2D* edge = (CvQuadEdge2D*)reader.ptr;
    if (CV_IS_SET_ELEM(edge))
    {
               //Do something...
    }
    CV_NEXT_SEQ_ELEM(seq->elem_size, reader);
}

if (storage != 0)
{
    cvReleaseMemStorage(&storage);
}

Although I didn't find a way to iterate edges connected to some vertex, by the way vertexes are iterated in the same way using the subdivision itself as sequence.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文