参考文章:
点云地面点滤波(Cloth Simulation Filter, CSF)“布料”滤波算法介绍
安装
项目地址: https://github.com/jianboqi/CSF
项目有详细安装说明,对于python版本,先下载整个仓库,然后cd到里面的python目录。
python setup.py build
python setup.py install
实验
def csf_ground_segmentation(data):
"""
cloth simulation segmentation for point clouds
:param:data format: np.vstack((x, y,z)..).transpose() # extract x, y, z and put into a list
"""
points = data
# create csf class
csf = CSF.CSF()
# prameter settings
csf.params.bSloopSmooth = False
csf.params.cloth_resolution = 0.5
# more details about parameter: http://ramm.bnu.edu.cn/projects/CSF/download/
csf.setPointCloud(points)
ground = CSF.VecInt() # a list to indicate the index of ground points after calculation
non_ground = CSF.VecInt() # a list to indicate the index of non-ground points after calculation
csf.do_filtering(ground, non_ground) # do actual filtering.
outpoints = points[ground] # extract ground points
return outpoints
if __name__="__main__":
file = 'xxx.pcd'
cloud = pcl.load(file) # 取每一帧 file 为指定的pcd点云文件
filtered_stat = cloud.make_statistical_outlier_filter()
filtered_stat.set_mean_k(50)
filtered_stat.set_std_dev_mul_thresh(1.0)
filtered_point = filtered_stat.filter() # inliers
filtered_point_np = np.array(filtered_point).astype(np.double)
ground_p = csf_ground_segmentation(filtered_point_np) # 粗糙地面点
ground_p_tovisual = pcl.PointCloud(ground_p.astype('float32'))
# 可视化结果
visualcolor1 = pcl.pcl_visualization.PointCloudColorHandleringCustom(filtered_point, 0, 255, 0)
visualcolor2 = pcl.pcl_visualization.PointCloudColorHandleringCustom(ground_p_tovisual, 255, 0, 0)
vs = pcl.pcl_visualization.PCLVisualizering
vss1 = pcl.pcl_visualization.PCLVisualizering()
vs.AddPointCloud_ColorHandler(vss1, filtered_point, visualcolor1, id=b'cloud', viewport=0)
vs.AddPointCloud_ColorHandler(vss1, ground_p_tovisual, visualcolor2, id=b'cloud1', viewport=0)
while not vs.WasStopped(vss1):
vs.SpinOnce(vss1)
结果
可见该算法对于粗糙地面分割还不错。但是对于路沿等边界并没有分割好。