 Automate point cloud plane and clustering with Python

Hi
I need to share with you how to automate point cloud segmentation by use python 3 in dynamo

I use the pythone code created by Florent Poux, Ph.D. and used in inside dynamo python3 node

To automate point cloud segmentation and 3D shape detection used multi-order RANSAC and unsupervised clustering (DBSCAN).
“Open 3d” python packedge was used in this example and the sample is loaded from the Florent Poux example
Getting started — Open3D 0.14.1 documentation """
Ramiz Mohareb
enramiz@yahoo.com
I use the pythone code created by Florent Poux, Ph.D. and used in inside dynamo python3 node
https://medium.com/towards-data-science/how-to-automate-3d-point-cloud-segmentation-and-clustering-with-python-343c9039e4f5
"""

import random
import numpy as np
import clr
import open3d

from Autodesk.DesignScript.Geometry import *
import matplotlib.pyplot as plt

filepath=IN

import numpy as np
import open3d as o3d

segment_models={}
segments={}
inliers={}
inlier_cloud={}

max_plane_idx=20

Outt=[]

rest=pcd
for i in range(max_plane_idx):
colors = plt.get_cmap("tab20")(i)
segment_models[i], inliers = rest.segment_plane(
distance_threshold=0.01,ransac_n=5,num_iterations=10000)
segments[i]=rest.select_by_index(inliers)
labels = np.array(segments[i].cluster_dbscan(eps=0.1, min_points=100))
candidates=[len(np.where(labels==j)) for j in np.unique(labels)]
best_candidate=int(np.unique(labels)[np.where(candidates== np.max(candidates))])
rest = rest.select_by_index(inliers, invert=True) + segments[i].select_by_index(list(np.where(labels!=best_candidate)))
segments[i]=segments[i].select_by_index(list(np.where(labels== best_candidate)))

for j in range(max_plane_idx):
Outt.append(np.asarray(segments[j].points).tolist())

o3d.visualization.draw_geometries([segments[i] for i in range(max_plane_idx)]+[rest])
#
OUT = Outt
8 Likes