最近接了个毫米波雷达点云处理的项目,点云数量惨不忍睹,而且要求很奇葩,必须自己写滤波算法,不能使用PCL、Open3D这些现成的库。没办法,从头搞起吧。
一、算法原理
直通滤波的原理很简单,相当于信号处理里面的带通滤波,给定一个坐标的上下限,大于上限和小于下限的点云被滤掉,只保留落在上下限范围内的点云。
二、代码示例
说明:passthrough函数定义了使用numpy进行直通滤波的过程,实际上就是指定索引条件,再索引数组。若指定的坐标不正确,报错并退出。然后使用numpy的random函数生成0—1区间内的随机点云进行验证。
import numpy as np
import matplotlib.pyplot as plt
def pass_through(points, limit_min, limit_max, filter_value_name):
if (filter_value_name == "x")or(filter_value_name == "X"):
target=0
elif (filter_value_name == "y") or (filter_value_name == "Y"):
target=1
elif (filter_value_name == "z") or (filter_value_name == "Z"):
target=2
else:
print("请输入正确的参数")
exit()
ind = np.where((points[:, target] >= limit_min) & (points[:, target] <= limit_max))[0]
sampled_cloud =points[ind]
return sampled_cloud
point=np.random.random((1000,5))
point=pass_through(point,0,0.2,"z")
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter3D(point[:,0],point[:,1],point[:,2],c='b',marker=".")
plt.show()