1

我想检测我的一组点的边界。我从 scipy spatial 尝试了 Delaunay 三角剖分,但我得到了这个:在此处输入图像描述

当我从这些三角形执行 alpha 形状时,我无法获得点集的边界。所以我认为我应该使用约束德劳内三角剖分。我选择三角形库来执行此操作。但问题是我不知道向函数 triangle.triangulate(tri, opts='') 提供什么。我将我更改的所有点集输入字典,但它返回我的点集。所以任何人都可以帮助我使用此功能或其他替代方法来执行轮廓检测?谢谢

4

2 回答 2

1

我使用另一个库来达到我的目的:shapely。以下是如何使用它对凹面对象进行三角测量:

from shapely.geometry import MultiPoint
from shapely.ops import triangulate
points=MultiPoint(data)
triangles = triangulate(points)
于 2017-10-27T12:29:05.420 回答
0

我不知道三角形库,但您可以使用替代方法来执行此操作。

这是一个普遍存在的问题,您可以获得一个简单的代码来解决这个问题。这个问题在算法中也被称为凸包,scipy 中有一个类可用。

代码如下,带有注释。

#imports
from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt

## Init graphics
axis = plt.gca(); axis.cla();

#Get points sample
points = np.random.rand(20, 2)

#get Convex hull instance for the points set
hull = ConvexHull(points)

#plor the points
plt.plot(points[:,0], points[:,1], 'v')

#Get and plot the boundary
for simplex in hull.simplices:
    axis.plot(points[simplex, 0], points[simplex, 1], 'r-')

不久之后可以看到结果图:

在此处输入图像描述

参考文献:

于 2018-05-12T05:06:48.227 回答