基于布料模拟的机载LiDAR滤波方法。 这是文章的代码:
https://github.com/jianboqi/CSF
CSF是cloth simulation filter算法的简称,其基本原理就是在倒置的点云上放置一块布料,然后模拟布料与点云的作用,最终布料的形状可以近似地形的走势,可以利用点与布料直接的距离对原始点云进行分类(地面点和非地面点)。
W. Zhang, J. Qi*, P. Wan, H. Wang, D. Xie, X. Wang, and G. Yan, “An Easy-to-Use Airborne LiDAR Data Filtering Method Based on Cloth Simulation
,” Remote Sens., vol. 8, no. 6, p. 501, 2016. (http://www.mdpi.com/2072-4292/8/6/501/htm)
CSF本身是用C++开发的,可以保证执行效率。只是在此基础上利用了swig对其添加了一层Python的接口。因此可以通过Python执行CSF滤波。
现在,我们用swig包装了CSF的Python接口。 现在使用起来更简单。 这项新功能可以使CSF更易于嵌入到大型项目中。 例如,它可以与Laspy
(https://github.com/laspy/laspy)一起使用。 您要做的只是将点云读取到python 2D列表中,并将其传递给CSF。 以下示例显示了如何将其与laspy一起使用。
使用las格式需要先安装laspy这个库(pip install laspy)。
# coding: utf-8
import laspy
import CSF
import numpy as np
inFile = laspy.file.File(r"in.las", mode='r') # read a las file
points = inFile.points
xyz = np.vstack((inFile.x, inFile.y, inFile.z)).transpose() # extract x, y, z and put into a list
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(xyz)
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.
outFile = laspy.file.File(r"ground.las",
mode='w', header=inFile.header)
outFile.points = points[ground] # extract ground points, and save it to a las file.
outFile.close() # do not forget this
如果激光雷达数据存储在txt文件中(每行x y z),则也可以直接将其导入。
import CSF
csf = CSF.CSF()
csf.readPointsFromFile('samp52.txt')
csf.params.bSloopSmooth = False
csf.params.cloth_resolution = 0.5
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.
csf.savePoints(ground,"ground.txt")
参数说明
虽然CSF有几个参数需要设置,但是大部分情况只用修改一两个即可。
以上就是python点云滤波库CSF的主要使用步骤。
下载源代码。 在python文件夹下:
python setup.py build
python setup.py install
在matlab文件夹下的demo_mex.m文件中查看更多详细信息。
现在,CSF由CMake构建,它生成了一个静态库,该库可被其他c ++程序使用。
linux
要构建库,请运行:
mkdir build #or other name
cd build
cmake ..
make
sudo make install
或者如果您想构建库和演示可执行文件csfdemo
mkdir build #or other name
cd build
cmake -DBUILD_DEMO=ON ..
make
sudo make install