【发布时间】:2016-04-24 06:39:02
【问题描述】:
我正在尝试从点云中删除彼此太近的点。我的输入是一个 mx3 矩阵,其中的列代表 xyz 坐标。代码如下:
def remove_duplicates(points, threshold):
# Convert to numpy
points = np.array(points)
# Round to within the threshold
rounded_points = points
if threshold > 0.0:
rounded_points = np.round(points/threshold)*threshold
# Remove duplicate points
point_tuples = [tuple(point) for point in rounded_points]
unique_rounded_points, unique_indices = np.unique(point_tuples, return_index = True)
points = points[unique_indices]
return points
我遇到的问题是 unique_indices 包含的值大于点的长度(我的测试数据为 2265 和 1000)。是我做错了什么,还是这是 NumPy 中的错误?
编辑:我应该注意,对于非常小的输入(尝试 27 分),unique() 似乎可以正常工作。
【问题讨论】:
-
您可能遇到了重叠问题。简单地抓取从 unique 返回的点列表怎么样:points = unique_rounded_points
-
我以前是这样做的,但我更愿意返回原始的未取整点。
-
np.array(point_tuples)[ind]返回什么?同样的错误?points和unique_rounded_points的形状是什么? -
tuple(point)的目的是什么?您是否尝试创建一个结构化数组,以便unique返回唯一的元组,而不是唯一的单个值?
标签: python numpy matrix indexing point-clouds