当前位置:   article > 正文

open3d 点云聚类dbscan_open3d dbscan 点云聚类

open3d dbscan 点云聚类

关键代码:

labels = np.array(pcd.cluster_dbscan(eps=0.02, min_points=10, print_progress=True))

point_cloud_dbscan_clustering.py 

  1. import open3d as o3d
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. if __name__ == "__main__":
  5. # 1. read pcd
  6. sample_ply_data = o3d.data.PLYPointCloud()
  7. pcd = o3d.io.read_point_cloud(sample_ply_data.path)
  8. # Flip it, otherwise the pointcloud will be upside down.
  9. """
  10. [
  11. [1, 0, 0, 0],
  12. [0, -1, 0, 0],
  13. [0, 0, -1, 0],
  14. [0, 0, 0, 1]
  15. ]
  16. """
  17. pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
  18. # 2. cluster_dbscan. 聚类
  19. """
  20. eps. Density parameter that is used to find neighbouring points.
  21. min_points. Minimum number of points to form a cluster.
  22. print_progress (default False). If 'True' the progress is visualized in the console.
  23. return: label. 每个点都有类别值
  24. """
  25. with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
  26. labels = np.array(pcd.cluster_dbscan(eps=0.02, min_points=10, print_progress=True))
  27. # 3. view:
  28. max_label = labels.max() # 最大的类别值
  29. print(f"point cloud has {max_label + 1} clusters")
  30. colors = plt.get_cmap("tab20")(labels / (max_label if max_label > 0 else 1))
  31. colors[labels < 0] = 0 # 类别为0的,颜色设置为黑色
  32. pcd.colors = o3d.utility.Vector3dVector(colors[:, :3]) # ndarray to vector3d
  33. o3d.visualization.draw([pcd])

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

闽ICP备14008679号