目錄
- 一、算法原理
- 二、讀取las點(diǎn)云
- 三、算法源碼
- 四、結(jié)果展示
- 五、CloudCompare實(shí)現(xiàn)
一、算法原理
布料模擬濾波處理流程:
1)利用點(diǎn)云濾波算法或者點(diǎn)云處理軟件濾除異常點(diǎn);
2)將激光雷達(dá)點(diǎn)云倒置;
3)設(shè)置模擬布料,設(shè)置布料網(wǎng)格分辨率 G R GR GR,確定模擬粒子數(shù)。布料的位置設(shè)置在點(diǎn)云最高點(diǎn)以上;
4)將布料模擬點(diǎn)和雷達(dá)點(diǎn)投影到水平面,為每個(gè)布料模擬點(diǎn)找到最相鄰的激光點(diǎn)的高度值,將高度值設(shè)置為 I H V IHV IHV;
5)布料例子設(shè)置為可移動(dòng),布料粒子首先受到重力作用,當(dāng)粒子高度 C H V CHV CHV小于 I H V IHV IHV時(shí),將粒子高度設(shè)置為 I H V IHV IHV;粒子設(shè)置為不可移動(dòng);
6)計(jì)算布料粒子之間的內(nèi)力作用,根據(jù)設(shè)置的布料剛性參數(shù),調(diào)整布料粒子之間的相對(duì)位置;
7)重復(fù)進(jìn)行5)和6)計(jì)算,迭代次數(shù)達(dá)到設(shè)置的最大迭代次數(shù);
8)計(jì)算激光雷達(dá)點(diǎn)與對(duì)應(yīng)布料模擬點(diǎn)的距離,距離小于閾值標(biāo)記為地面點(diǎn),距離大于閾值標(biāo)記為非地面點(diǎn)。
點(diǎn)云地面點(diǎn)濾波(Cloth Simulation Filter, CSF)“布料”濾波算法介紹
二、讀取las點(diǎn)云
參考鏈接: python讀取las
1、GitHub: laspy
2、基礎(chǔ)教程:Laspy: Documentation
3、安裝:pip install laspy
4、使用example:
import laspy
#============讀取las格式的點(diǎn)云===========
inFile = laspy.file.File(r"40m1.las", mode='r') # 讀取點(diǎn)云
print('X,Y,Z',inFile.x,inFile.y,inFile.z) # 輸出點(diǎn)云坐標(biāo)
print('點(diǎn)云個(gè)數(shù):',len(inFile)) #讀取點(diǎn)云個(gè)數(shù)
#============保存點(diǎn)云為las文件===========
h = inFile.header
outFile = laspy.file.File('666.las', mode = "w", header=h)
points = inFile #對(duì)點(diǎn)云進(jìn)行的相關(guān)操作
outFile.points = points
outFile.close() #關(guān)閉文件完成保存
三、算法源碼
1、算法細(xì)節(jié):CSF
2、源碼獲取:https://github.com/jianboqi/CSF
3、源碼編譯:下載源代碼。在python文件夾下:
python setup.py build
python setup.py install
4、讀取las并可視化算法結(jié)果
import laspy
import CSF
import numpy as np
import open3d as o3d
#============讀取las文件=============
inFile = laspy.file.File(r"40m1.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()
# 參數(shù)設(shè)置
csf.params.bSloopSmooth = False #粒子設(shè)置為不可移動(dòng)
csf.params.cloth_resolution = 0.1 #布料網(wǎng)格分辨率
csf.params.rigidness = 3 #布料剛性參數(shù)
csf.params.time_step = 0.65
csf.params.class_threshold = 0.03 #點(diǎn)云與布料模擬點(diǎn)的距離閾值
csf.params.interations = 500 #最大迭代次數(shù)
# more details about parameter: http://ramm.bnu.edu.cn/projects/CSF/download/
csf.setPointCloud(xyz)
ground = CSF.VecInt() # 地面點(diǎn)索引列表
non_ground = CSF.VecInt() # 非地面點(diǎn)索引列表
csf.do_filtering(ground, non_ground) # 執(zhí)行濾波
#============保存為las文件==========
outFile = laspy.file.File(r"non_ground.las",
mode='w', header=inFile.header)
outFile.points = points[non_ground] # 提取非地面點(diǎn)保存到las
outFile.close() # 關(guān)閉文件夾
a=xyz[ground]
b=xyz[non_ground]
#=============可視化===============
def view_cloud(a, b):
pcd = o3d.geometry.PointCloud()
# =====numpy轉(zhuǎn)point=======
pcd.points = o3d.utility.Vector3dVector(a)
pcd1 = o3d.geometry.PointCloud()
pcd1.points = o3d.utility.Vector3dVector(b)
#=======自定義顏色========
pcd.paint_uniform_color([0, 1, 0])
pcd1.paint_uniform_color([1, 0, 0])
o3d.visualization.draw_geometries([pcd, pcd1],window_name='提取結(jié)果')
o3d.visualization.draw_geometries([pcd1],window_name='非地面點(diǎn)')
o3d.visualization.draw_geometries([pcd],window_name='地面點(diǎn)')
view_cloud(a,b)
5、讀取pcd文件并可視化結(jié)果
import open3d as o3d
import CSF
import numpy as np
pc = o3d.io.read_point_cloud("數(shù)據(jù)//100m1.pcd")
xyz = np.asarray(pc.points)
csf = CSF.CSF()
# prameter settings
csf.params.bSloopSmooth = False
csf.params.cloth_resolution = 0.1
csf.params.rigidness = 3
csf.params.time_step = 0.65
csf.params.class_threshold = 0.03
csf.params.interations = 500
# 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.
# o3d.io.write_point_cloud("trans_of_source.pcd", non_ground)#保存點(diǎn)云
a=xyz[ground]
b=xyz[non_ground]
def view_cloud(a, b):
pcd = o3d.geometry.PointCloud()
# From numpy to Open3D
pcd.points = o3d.utility.Vector3dVector(a)
pcd1 = o3d.geometry.PointCloud()
# From numpy to Open3D
pcd1.points = o3d.utility.Vector3dVector(b)
pcd.paint_uniform_color([0, 1, 0])
pcd1.paint_uniform_color([1, 0, 0])
o3d.visualization.draw_geometries([pcd, pcd1],window_name='提取結(jié)果')
o3d.visualization.draw_geometries([pcd1],window_name='非地面點(diǎn)')
o3d.visualization.draw_geometries([pcd],window_name='地面點(diǎn)')
view_cloud(a,b)
四、結(jié)果展示
五、CloudCompare實(shí)現(xiàn)
1、加載點(diǎn)云數(shù)據(jù),點(diǎn)擊Plugins中的CSF Filter功能
2、彈出如下窗口:
圖中:Cloth resolution:是指用于覆蓋地形的布的網(wǎng)格大小(單位與點(diǎn)云的單位相同)。你設(shè)置的布分辨率越大,你得到的DTM就越粗糙;Max iterations:是指地形仿真的最大迭代次數(shù)。500對(duì)大多數(shù)場(chǎng)景來(lái)說(shuō)都足夠了。Classification threshold:是指根據(jù)點(diǎn)與模擬地形之間的距離,將點(diǎn)云劃分為地面和非地面部分的閾值。0.5適用于大多數(shù)場(chǎng)景
這里的網(wǎng)格分辨率和距離閾值最小只能設(shè)置為10cm,地面10cm的范圍默認(rèn)是地面點(diǎn),精確度不如自己代碼實(shí)現(xiàn)中的高。
3、最后得到的結(jié)果:
可以看出,非地面點(diǎn)中不能提取到路緣石。
到此這篇關(guān)于python實(shí)現(xiàn)CSF地面點(diǎn)濾波的文章就介紹到這了,更多相關(guān)python地面點(diǎn)濾波內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- python點(diǎn)云地面點(diǎn)濾波(Progressive Morphological Filter)算法介紹(PCL庫(kù))
- python 點(diǎn)云地面點(diǎn)濾波-progressive TIN densification(PTD)算法介紹