当给定的定位点是三角形的顶点之一时,OpenCV 的 Subdiv2D / Delaunay 是否会损坏?
构建三角剖分的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用序列功能迭代边,这里是代码:
虽然我没有找到迭代连接到某个顶点的边的方法,但顺便说一下,使用细分本身作为序列以相同的方式迭代顶点。
Edges can be iterated using sequence functionality here is the code:
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.