当前位置:   article > 正文

点云 DBSCAN 聚类(附open3d python代码)_pcd.cluster_dbscan

pcd.cluster_dbscan

  1. import open3d as o3d
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. print("->正在加载点云... ")
  5. pcd = o3d.io.read_point_cloud("test.pcd")
  6. print(pcd)
  7. print("->正在DBSCAN聚类...")
  8. eps = 0.5 # 同一聚类中最大点间距
  9. min_points = 50 # 有效聚类的最小点数
  10. labels = np.array(pcd.cluster_dbscan(eps, min_points, print_progress=True))
  11. max_label = labels.max() # 获取聚类标签的最大值 [-1,0,1,2,...,max_label],label = -1 为噪声,因此总聚类个数为 max_label + 1
  12. print(f"point cloud has {max_label + 1} clusters")
  13. colors = plt.get_cmap("tab20")(labels / (max_label if max_label > 0 else 1))
  14. colors[labels < 0] = 0 # labels = -1 的簇为噪声,以黑色显示
  15. pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])
  16. o3d.visualization.draw_geometries([pcd])

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/394217
推荐阅读
相关标签
  

闽ICP备14008679号