Open3D DbScanClustering clustering algorithm

The DBSCAN clustering algorithm is a density-based clustering algorithm. The algorithm requires two parameters.

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


Entry:

  • eps: Define the distance to the cluster neighbor
  • min_points: Define the minimum number of points required to form a cluster.

Participants:

  • This function returns a label, where label -1 represents noise.

The algorithm definition starts spreading from the selected point, the distance between neighbor points is <=0.02 meters, and a minimum of 10 points can form a cluster; it is suitable for the point cloud separated by the original point cloud with obvious boundaries.

The original point cloud is divided into 10 clusters, each of which has a different color, and only 3 clusters have a relatively large number of points, which is more obvious. In addition, there is a relatively small fragment in the right corner.

Official example algorithm effect:
Insert picture description hereInsert picture description here
output:

Format = auto
Extension = ply
geometry::PointCloud with 196133 points.
[Open3D DEBUG] Precompute Neighbours
[Open3D DEBUG] Done Precompute Neighbours
[Open3D DEBUG] Compute Clusters
Precompute Neighbours[========================================] 100%
[Open3D DEBUG] Done Compute Clusters: 10
point cloud has 10 clusters

Source code:

# <DBSCAN聚类算法,是基于密度的聚类算法。>
# 该算法需要两个参数。
# -eps: 定义到聚类邻居的距离
# -min_points: 定义形成聚类所需的最小点数。
# 该函数返回一个标签,其中标签-1表示噪音。>

import open3d as o3d
import matplotlib.pyplot as plt
import numpy as np

path =  "../pcds/fragment.ply"
print(path)

pcd = o3d.io.read_point_cloud(path)
print(pcd)

# 定义以选中的点开始蔓延,邻居点距离0.02米的,最小有10个点,可以构成一个簇;适用于点云分隔的比较开的,一块一块的点云。
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
    labels = np.array(pcd.cluster_dbscan(eps=0.02, min_points=10, print_progress=True))

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], "Open3D dbscanclusting")

reference:

http://www.open3d.org/docs/release/tutorial/Basic/pointcloud.html#Access-estimated-vertex-normal

Guess you like

Origin blog.csdn.net/qq_40985985/article/details/108512968