Open3d学习计划—高级篇 3(点云全局配准)
Open3D是一個開源庫,支持快速開發和處理3D數據。Open3D在c++和Python中公開了一組精心選擇的數據結構和算法。后端是高度優化的,并且是為并行化而設置的。
本系列學習計劃有Blue同學作為發起人,主要以Open3D官方網站的教程為主進行翻譯與實踐的學習計劃。點云PCL公眾號作為免費的3D視覺,點云交流社區,期待有使用Open3D或者感興趣的小伙伴能夠加入我們的翻譯計劃,貢獻免費交流社區,為使用Open3D提供中文的使用教程。
ICP配準和彩色點云配準都被稱為局部點云配準方法,因為他們都依賴一個粗糙的對齊作為初始化。本篇教程將會展現另一種被稱為全局配準的配準方法.這種系列的算法不要求一個初始化的對齊,通常會輸出一個沒那么精準的對齊結果,并且使用該結果作為局部配準的初始化.
可視化
該輔助函數可以將配準的源點云和目標點云一起可視化。
def draw_registration_result(source, target, transformation):source_temp = copy.deepcopy(source)target_temp = copy.deepcopy(target)source_temp.paint_uniform_color([1, 0.706, 0])target_temp.paint_uniform_color([0, 0.651, 0.929])source_temp.transform(transformation)o3d.visualization.draw_geometries([source_temp, target_temp])
?注意:這里原來的教程里可視化函數都加了初始視角之類的,但是很多人反映這個會報錯,并且官方函數里也沒給出可接受的參數,所以在這里把初始視角的參數都去掉了
提取幾何特征
我們降采樣點云,估計法線,之后對每個點計算FPFH特征.FPFH特征是一個描述點的局部幾何屬性的33維的向量.在33維空間中進行最近鄰查詢可以返回具有近似幾何結構的點.詳細細節請查看?[Rasu2009].
def preprocess_point_cloud(pcd, voxel_size):print(":: Downsample with a voxel size %.3f." % voxel_size)pcd_down = pcd.voxel_down_sample(voxel_size)radius_normal = voxel_size * 2print(":: Estimate normal with search radius %.3f." % radius_normal)pcd_down.estimate_normals(o3d.geometry.KDTreeSearchParamHybrid(radius=radius_normal, max_nn=30))radius_feature = voxel_size * 5print(":: Compute FPFH feature with search radius %.3f." % radius_feature)pcd_fpfh = o3d.registration.compute_fpfh_feature(pcd_down,o3d.geometry.KDTreeSearchParamHybrid(radius=radius_feature, max_nn=100))return pcd_down, pcd_fpfh
輸入
以下代碼從兩個文件中讀取源點云和目標點云.這一對點云使用單位矩陣作為初始矩陣之后是不對齊的.
def prepare_dataset(voxel_size):print(":: Load two point clouds and disturb initial pose.")source = o3d.io.read_point_cloud("../../TestData/ICP/cloud_bin_0.pcd")target = o3d.io.read_point_cloud("../../TestData/ICP/cloud_bin_1.pcd")trans_init = np.asarray([[0.0, 0.0, 1.0, 0.0], [1.0, 0.0, 0.0, 0.0],[0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]])source.transform(trans_init)draw_registration_result(source, target, np.identity(4))source_down, source_fpfh = preprocess_point_cloud(source, voxel_size)target_down, target_fpfh = preprocess_point_cloud(target, voxel_size)return source, target, source_down, target_down, source_fpfh, target_fpfhvoxel_size = 0.05 # means 5cm for this dataset
source, target, source_down, target_down, source_fpfh, target_fpfh = prepare_dataset(voxel_size)
:: Load two point clouds and disturb initial pose.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
RANSAC
我們使用RANSAC進行全局配準.在RANSAC迭代中,我們每次從源點云中選取 ransac_n 個隨機點.通過在33維FPFH特征空間中查詢最鄰近,可以在目標點云中找到他們的對應點.剪枝步驟需要使用快速修剪算法來提早拒絕錯誤匹配.
Open3d提供以下剪枝算法:
CorrespondenceCheckerBasedOnDistance檢查對應的點云是否接近(也就是距離是否小于指定閾值)
CorrespondenceCheckerBasedOnEdgeLength檢查從源點云和目標點云對應中分別畫上兩條任意邊(兩個頂點連成的線)是否近似.
CorrespondenceCheckerBasedOnNormal考慮的所有的對應的頂點法線的密切關系.他計算了兩個法線向量的點積.使用弧度作為閾值.
只有通過剪枝步驟的匹配才用于轉換,該轉換將在整個點云上進行驗證.核心函數是 :
registration_ransac_based_on_feature_matching.?
RANSACConvergenceCriteria是里面一個十分重要的超參數.他定義了RANSAC迭代的最大次數和驗證的最大次數.這兩個值越大,那么結果越準確,但同時也要花費更多的時間.
我們是基于[Choi2015]提供的的經驗來設置RANSAC的超參數.
def execute_global_registration(source_down, target_down, source_fpfh,target_fpfh, voxel_size):distance_threshold = voxel_size * 1.5print(":: RANSAC registration on downsampled point clouds.")print(" Since the downsampling voxel size is %.3f," % voxel_size)print(" we use a liberal distance threshold %.3f." % distance_threshold)result = o3d.registration.registration_ransac_based_on_feature_matching(source_down, target_down, source_fpfh, target_fpfh, distance_threshold,o3d.registration.TransformationEstimationPointToPoint(False), 4, [o3d.registration.CorrespondenceCheckerBasedOnEdgeLength(0.9),o3d.registration.CorrespondenceCheckerBasedOnDistance(distance_threshold)], o3d.registration.RANSACConvergenceCriteria(4000000, 500))return result
result_ransac = execute_global_registration(source_down, target_down,source_fpfh, target_fpfh,voxel_size)
print(result_ransac)
draw_registration_result(source_down, target_down, result_ransac.transformation)
:: RANSAC registration on downsampled point clouds.
Since the downsampling voxel size is 0.050,
we use a liberal distance threshold 0.075.
registration::RegistrationResult with fitness=6.773109e-01, inlier_rmse=3.332039e-02, and correspondence_set size of 3224
Access transformation to get result.
局部優化
由于性能原因,全局配準只能在大規模降采樣的點云上執行,配準的結果不夠精細,我們使用?Point-to-plane ICP?去進一步優化配準結果.
def refine_registration(source, target, source_fpfh, target_fpfh, voxel_size):distance_threshold = voxel_size * 0.4print(":: Point-to-plane ICP registration is applied on original point")print(" clouds to refine the alignment. This time we use a strict")print(" distance threshold %.3f." % distance_threshold)result = o3d.registration.registration_icp(source, target, distance_threshold, result_ransac.transformation,o3d.registration.TransformationEstimationPointToPlane())return resultresult_icp = refine_registration(source, target, source_fpfh, target_fpfh,voxel_size)
print(result_icp)
draw_registration_result(source, target, result_icp.transformation)
:: Point-to-plane ICP registration is applied on original point
clouds to refine the alignment. This time we use a strict
distance threshold 0.020.
registration::RegistrationResult with fitness=6.210275e-01, inlier_rmse=6.565175e-03, and correspondence_set size of 123482
Access transformation to get result.
快速全局配準
由于無數的模型推薦和評估,導致基于RANSAC的全局配準需要很長的時間.
[Zhou2016]?提出了一種加速的方法,該方法可以快速的優化幾乎沒有對應關系的線處理權重( [Zhou2016] introduced a faster approach that quickly optimizes line process weights of few correspondences).這樣在每次迭代的時候沒有模型建議和評估,該方法就在計算的時候節約的大量的時間.(建議看看原論文,這個感覺翻譯不好,有更好建議的歡迎留言.)
這篇教程比較了基于RANSAC的全局配準和[Zhou2016]方法的運行時間.
輸入
我們使用上面全局配準的輸入例子.
voxel_size = 0.05 # means 5cm for the dataset
source, target, source_down, target_down, source_fpfh, target_fpfh = \prepare_dataset(voxel_size)
:: Load two point clouds and disturb initial pose.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
基準
在下面代碼中,我們將計時全局配準算法.
start = time.time()
result_ransac = execute_global_registration(source_down, target_down,source_fpfh, target_fpfh,voxel_size)
print("Global registration took %.3f sec.\n" % (time.time() - start))
print(result_ransac)
draw_registration_result(source_down, target_down,result_ransac.transformation)
:: RANSAC registration on downsampled point clouds.
Since the downsampling voxel size is 0.050,
we use a liberal distance threshold 0.075.
Global registration took 0.085 sec.
registration::RegistrationResult with fitness=6.760504e-01, inlier_rmse=2.596653e-02, and correspondence_set size of 3218
Access transformation to get result.
快速全局配準
我們采用和基準相同的輸入,下面的代碼調用了了[Zhou2016]的實現.
def execute_fast_global_registration(source_down, target_down, source_fpfh,target_fpfh, voxel_size):distance_threshold = voxel_size * 0.5print(":: Apply fast global registration with distance threshold %.3f" \% distance_threshold)result = o3d.registration.registration_fast_based_on_feature_matching(source_down, target_down, source_fpfh, target_fpfh,o3d.registration.FastGlobalRegistrationOption(maximum_correspondence_distance=distance_threshold))return?result
start = time.time()
result_fast = execute_fast_global_registration(source_down, target_down,source_fpfh, target_fpfh,voxel_size)
print("Fast global registration took %.3f sec.\n" % (time.time() - start))
print(result_fast)
draw_registration_result(source_down, target_down,result_fast.transformation)
:: Apply fast global registration with distance threshold 0.025
Fast global registration took 0.128 sec.
registration::RegistrationResult with fitness=5.054622e-01, inlier_rmse=1.743545e-02, and correspondence_set size of 2406
Access transformation to get result.
經過適當的配置,快速全局配準的精度甚至可以和ICP相媲美.更多實驗結果請參閱[Zhou2016].
資源
三維點云論文及相關應用分享
【點云論文速讀】基于激光雷達的里程計及3D點云地圖中的定位方法
3D目標檢測:MV3D-Net
三維點云分割綜述(上)
3D-MiniNet: 從點云中學習2D表示以實現快速有效的3D LIDAR語義分割(2020)
win下使用QT添加VTK插件實現點云可視化GUI
JSNet:3D點云的聯合實例和語義分割
大場景三維點云的語義分割綜述
PCL中outofcore模塊---基于核外八叉樹的大規模點云的顯示
基于局部凹凸性進行目標分割
基于三維卷積神經網絡的點云標記
點云的超體素(SuperVoxel)
基于超點圖的大規模點云分割
更多文章可查看:點云學習歷史文章大匯總
SLAM及AR相關分享
【開源方案共享】ORB-SLAM3開源啦!
【論文速讀】AVP-SLAM:自動泊車系統中的語義SLAM
【點云論文速讀】StructSLAM:結構化線特征SLAM
SLAM和AR綜述
常用的3D深度相機
AR設備單目視覺慣導SLAM算法綜述與評價
SLAM綜述(4)激光與視覺融合SLAM
Kimera實時重建的語義SLAM系統
SLAM綜述(3)-視覺與慣導,視覺與深度學習SLAM
易擴展的SLAM框架-OpenVSLAM
高翔:非結構化道路激光SLAM中的挑戰
SLAM綜述之Lidar SLAM
基于魚眼相機的SLAM方法介紹
往期線上分享錄播匯總
第一期B站錄播之三維模型檢索技術
第二期B站錄播之深度學習在3D場景中的應用
第三期B站錄播之CMake進階學習
第四期B站錄播之點云物體及六自由度姿態估計
第五期B站錄播之點云深度學習語義分割拓展
第六期B站錄播之Pointnetlk解讀
[線上分享錄播]點云配準概述及其在激光SLAM中的應用
[線上分享錄播]cloudcompare插件開發
[線上分享錄播]基于點云數據的?Mesh重建與處理
[線上分享錄播]機器人力反饋遙操作技術及機器人視覺分享
[線上分享錄播]地面點云配準與機載點云航帶平差
點云PCL更多活動請查看:點云PCL活動之應屆生校招群
掃描下方微信視頻號二維碼可查看最新研究成果及相關開源方案的演示:
如果你對Open3D感興趣,或者正在使用該開源方案,就請加入我們,一起翻譯,一起學習,貢獻自己的力量,目前階段主要以微信群為主,有意者發送“Open3D學習計劃”到公眾號后臺,和更多熱愛分享的小伙伴一起交流吧!如果翻譯的有什么問題或者您有更好的意見,請評論交流!!!!
以上內容如有錯誤請留言評論,歡迎指正交流。如有侵權,請聯系刪除
掃描二維碼
? ? ? ? ? ? ? ? ? ?關注我們
讓我們一起分享一起學習吧!期待有想法,樂于分享的小伙伴加入免費星球注入愛分享的新鮮活力。分享的主題包含但不限于三維視覺,點云,高精地圖,自動駕駛,以及機器人等相關的領域。
分享及合作方式:微信“920177957”(需要按要求備注) 聯系郵箱:dianyunpcl@163.com,歡迎企業來聯系公眾號展開合作。
點一下“在看”你會更好看耶
總結
以上是生活随笔為你收集整理的Open3d学习计划—高级篇 3(点云全局配准)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在结构化场景中基于单目的物体与平面SLA
- 下一篇: nanoflann库