溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法

發(fā)布時(shí)間:2021-08-06 18:30:44 來(lái)源:億速云 閱讀:798 作者:chen 欄目:開發(fā)技術(shù)

這篇文章主要講解了“python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法”吧!

目錄
  • 一、算法原理

  • 二、讀取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、源碼獲?。篽ttps://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é)果展示

python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法

五、CloudCompare實(shí)現(xiàn)

1、加載點(diǎn)云數(shù)據(jù),點(diǎn)擊Plugins中的CSF Filter功能

python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法

2、彈出如下窗口:

python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法
python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法
?

?圖中: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é)果:

python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法

可以看出,非地面點(diǎn)中不能提取到路緣石。

感謝各位的閱讀,以上就是“python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)python怎么實(shí)現(xiàn)CSF地面點(diǎn)濾波算法這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI