如何从Subdiv2D Delaunay三角测量中获取顶点索引
How to get vertex index from Subdiv2D Delaunay triangulation
我正在使用OpenCV 3.1,想知道如何在Subdiv2D Delaunay三角测量中获取边的顶点索引,而不仅仅是顶点坐标?我想使用此索引来保留顶点值以进行进一步插值。
例如:
cv::Subdiv2D subdiv(rect);
// Insert some points to subdiv....
cv::Point2f org, dst;
subdiv.edgeOrg(edge, &org); // starting point of edge
这只给了我org
顶点的坐标.
我已经看到在OpenCV 2.4中,我们可以使用CvSubdiv2DPoint
类型,除了标准Point32f
之外,它还包含id。在 OpenCV 3.1 中,我找不到这个结构,看起来它由于某种原因已被删除。
如果其他人看这个问题。您可以创建一个从 subdiv2D 继承的类,并实现您自己的函数,该函数以这种方式返回索引:
.h
#ifndef __Subdiv2DIndex__
#define __Subdiv2DIndex__
#include <vector>
#include <opencv2opencv.hpp>
using namespace cv;
class Subdiv2DIndex : public Subdiv2D
{
public :
Subdiv2DIndex(Rect rectangle);
//Source code of Subdiv2D: https://github.com/opencv/opencv/blob/master/modules/imgproc/src/subdivision2d.cpp#L762
//The implementation tweaks getTrianglesList() so that only the indice of the triangle inside the image are returned
void getTrianglesIndices(std::vector<int> &ind) const;
};
#endif
。.cpp #include "Subdiv2DIndex.h"
Subdiv2DIndex::Subdiv2DIndex(Rect rectangle) : Subdiv2D{rectangle}
{
}
void Subdiv2DIndex::getTrianglesIndices(std::vector<int> &triangleList) const
{
triangleList.clear();
int i, total = (int)(qedges.size() * 4);
std::vector<bool> edgemask(total, false);
const bool filterPoints = true;
Rect2f rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
for (i = 4; i < total; i += 2)
{
if (edgemask[i])
continue;
Point2f a, b, c;
int edge_a = i;
int indexA = edgeOrg(edge_a, &a) -4;
if (filterPoints && !rect.contains(a))
continue;
int edge_b = getEdge(edge_a, NEXT_AROUND_LEFT);
int indexB = edgeOrg(edge_b, &b) - 4;
if (filterPoints && !rect.contains(b))
continue;
int edge_c = getEdge(edge_b, NEXT_AROUND_LEFT);
int indexC = edgeOrg(edge_c, &c) - 4;
if (filterPoints && !rect.contains(c))
continue;
edgemask[edge_a] = true;
edgemask[edge_b] = true;
edgemask[edge_c] = true;
triangleList.push_back(indexA);
triangleList.push_back(indexB);
triangleList.push_back(indexC);
}
}
事实证明,在 OpenCV 3 中,cv::Subdiv2D
中的一些无效函数现在返回一个整数。就我而言,我发现 subdiv.edgeOrg(...)
和 subdiv.edgeDst(...)
将顶点 id 作为整数返回。
相关文章:
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 如何从 DirectXTK (ToolKit) DirectX::Model 类获取所有顶点坐标以用于冲突检测
- 如何在具有Voro 库的容器中获取所有单元格的顶点
- 如何在C 中获取像素着色器版本和顶点着色版版本
- OpenSG - 获取每个顶点的每个轴
- 使用lib3ds获取一系列顶点
- 如何在DX9中获取顶点声明
- 如何在OpenCV中获取旋转矩形的顶点
- BGL :获取带有数据的顶点描述符
- C++Maya-从帧和子帧获取网格顶点
- 从 boost::adjacency_list 获取边属性(包括相关顶点)
- 在 HLSL 中获取顶点的颜色
- 在图形中移除连接到源顶点的边时获取额外的边
- 如何从Subdiv2D Delaunay三角测量中获取顶点索引
- 如何按名称获取 id 顶点
- Boost:: Dijkstra 最短路径,如何从路径迭代器获取顶点索引
- 如何在约束delaunay三角剖分中获取三角形的顶点
- 在LPDIRECT3DVERTEXBUFFER9上获取顶点内容