import open3d as o3d
import numpy as np
import matplotlib.pyplot as plt
pcd = o3d.io.read_point_cloud("A.ply")
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
labels = np.array(pcd.cluster_dbscan(eps=0.02, min_points=4, print_progress=True))
#邻域半径eps和最少点数目minpoints
max_label = labels.max()
print(f"point cloud has {max_label + 1} clusters")
colors = plt.get_cmap("tab20")(labels / (max_label if max_label > 0 else 1))
colors[labels < 0] = 0
pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])
o3d.visualization.draw_geometries([pcd])
其中参数eps和min_point可以通过下图理解
这里min_point=4,所以红色圆圈内有四个点,eps则是领域半径
具体原理可以参考:https://blog.csdn.net/hansome_hong/article/details/107596543