python如何识别点云形状_python – 如何找到2d点云的alpha形状(凹面的船体)?

我正在寻找一个在二维中计算alpha形状的实现。我正在运行ubuntu。我更喜欢这个任务的命令行实用程序,但是也可以使用python库。

在Google中,我发现许多计算alpha形状的实现。但没有一个输出我想要的。作为输入,我具有二维点列表(例如,文本文件中每行一对浮点)。作为输出,我想要另一个具有相同尺度的二维点列表。

我已经尝试安装最新的python绑定的cgal,但这些还没有被支持一段时间,不再编译在Ubuntu 11.04(我也尝试在Ubuntu 10.04,没有运气)。 Clustr,由Aaron Straup Cope开发的flickr项目也不会在Ubuntu 11.04上编译(可能是因为它也绑定到较旧的CGAL库)。

我也试过this implementation从肯·克拉克森在钟表实验室。它输出几乎我想要的,输出似乎是在另一个规模,它将浮点变成ints。

我也尝试了dionysus的python绑定。这些编译,但是当我使用我的列表点输入函数fill_alpha2D_complex(points,f)时,输出不是我预期的。它不是二维点的列表,而是似乎是一个“持久性图”,我不知道这是什么意思。

任何人知道这个问题的简单解决方案?

更新:我想打印出与alpha形状相关联的点,它们处于不连接的边缘。我认为这意味着“给我与最小阿尔法值相关联的点,使形状连接”。

更新我现在发现了如何从Ken Clarkson’s implementation获得我想要的(或多或少的我想要的)从dionysus implementation.克拉克森的实现是做正确的事情,它只是输出点的指标而不是点自己(同一个故事与dionysus),我需要得到一些可选的标志正确。我写的包装如下。该解决方案是理想的,因为它产生了连接并且不包含孔的α形状。 Alpha被自动设置。另一方面,Dionysus不会自动发现这个alpha值。加上Clarkson的实现可以设置为输出形状的ps图像(使用-afps标志)。要获得Clarkson的代码,使用非古老版本的GCC进行编译,您需要遵循here概述。以下代码可用作库或独立包装器:

#!/usr/bin/python -O

import sys, os

import subprocess

import tempfile

hull_path = "./hull.exe"

def get_alpha_shape(points):

# Write points to tempfile

tmpfile = tempfile.NamedTemporaryFile(delete=False)

for point in points:

tmpfile.write("%0.7f %0.7f\n" % point)

tmpfile.close()

# Run hull

command = "%s -A -m1000000 -oN < %s" % (hull_path, tmpfile.name)

print >> sys.stderr, "Running command: %s" % command

retcode = subprocess.call(command, shell=True)

if retcode != 0:

print >> sys.stderr, "Warning: bad retcode returned by hull. Retcode value:" % retcode

os.remove(tmpfile.name)

# Parse results

results_file = open("hout-alf")

results_file.next() # skip header

results_indices = [[int(i) for i in line.rstrip().split()] for line in results_file]

# print "results length = %d" % len(results_indices)

results_file.close()

os.remove(results_file.name)

return [(points[i], points[j]) for i,j in results_indices]

if __name__ == "__main__":

points = [tuple([float(i) for i in line.rstrip().split()]) for line in sys.stdin]

for point_i, point_j in get_alpha_shape(points):

sys.stdout.write("%0.7f,%0.7f\t%0.7f,%0.7f\n" % (point_i[0], point_i[1], point_j[0], point_j[1]))

sys.exit(0)

你可能感兴趣的:(python如何识别点云形状)