我正试图为一个使用激光雷达的学校项目编写一些高效的代码。目标是过滤掉点云中超过10米的任何内容,并将其传递出去。我可以写一个for循环来实现这一点,但它不是很优化。我的目标是通过NumPy有效地实现这一点
def get_distance(input_array):
return np.sqrt(np.sum(np.square(input_array)))
def filter_by_distance(cloud, distance=10):
cloud1 = [item for item in cloud if get_distance(item) <= distance]
return np.asarray(cloud1)
云是一个多维np数组,包含[X,Y,Z,I]
[[23.157 0.032 0.992 0.34 ]
[23.219 0.105 0.994 0.29 ]
[23.282 0.179 0.996 0.26 ]
...
[ 1.548 -1.101 -0.77 0. ]
[ 1.388 -0.978 -0.676 0. ]
[ 1.42 -0.964 -0.684 0. ]]
我正在使用get_distance(cloud[:,0:2])来获取x,y距离,但是我似乎找不到一种方法在没有for循环的情况下使用此修剪原始点云。我将感谢任何帮助
计算内部行的平方和,无需sqrt,直接与平方距离比较
您可以将}布尔的索引(或掩码)作为选择条件传递给ndarray。使用显示的方法获取与原点的距离。只需将其展开,即可在云阵列上按行操作。参见sum documentation并在
True
{axis
下查看。您需要每一行的总和,因为您已经将数据存储为一行X,Y,Z,I。如果在将来对其进行转置,请对列使用axis=0这将为您提供与点云中的点数相同的距离向量。现在使用以下内容制作索引:
如果打印此索引,您将看到一系列}。现在进行过滤
True
{当然,这是最丑陋的一行。如果你这样做…请发表评论,让人们知道你做了什么
奇怪的是,为什么只使用x和y表示距离
你就快到了。你可以添加或删除z,我不确定我代表了什么
加法是一个轴,用于沿每个点的x、y和z值求和,并包含在numpy中进行过滤
points<=distance
返回用作掩码的布尔数组相关问题 更多 >
编程相关推荐