4

**I am trying to extraction point cloud after applying DBSCAN algorithm from open3d. I had problem in visualize in spyder so I am using csv file to save the point cloud and open in cloud compare. Need help to save the file in csv format. ** import numpy as np import open3d as o3d import copy

# threshold should be 
if __name__ == "__main__":

    pcl_map = o3d.io.read_point_cloud("C:/Users/vimal/OneDrive/Desktop/documents-export-2021-06-11/SurfacePolesBuildings.ply")
   
    walls=[]
    cluster=[]


    #http://www.open3d.org/docs/release/tutorial/geometry/pointcloud.html#Plane-segmentation
outlier_cloud=pcl_map
for i in range (15):
        plane_model, inliers = outlier_cloud.segment_plane(distance_threshold=0.29, #0.5 means 50cm
                                             ransac_n=4,
 # if we put the ransac =4 then it can rid of ambiguity from Prof Neumann Lecture
                                             num_iterations=100)
        
        [a, b, c, d] = plane_model
        print(f"Plane equation: {a:.2f}x + {b:.2f}y + {c:.2f}z + {d:.2f} = 0")
        
        inlier=np.asarray(outlier_cloud.select_by_index(inliers).points)
                   
        outlier_cloud = outlier_cloud.select_by_index(inliers, invert=True)
       
        if c<0.1:
            print("FOUND WALL!")
            walls.append(inlier)
                    
idx=0
for wall in walls:
        np.savetxt("C:/Users/vimal/OneDrive/Desktop/documents-export-2021-06-11/wall/wall_"+str(idx)+".csv",wall, delimiter=",")
        idx+=1


# DBSCAN than planesegmentation    
with o3d.utility.VerbosityContextManager(
           o3d.utility.VerbosityLevel.Debug) as cm:
           labels = np.array(
           pcl_map.cluster_dbscan(eps=0.02, min_points=10, print_progress=True))

max_label = labels.max()
print(f"point cloud has {max_label + 1} clusters")
print(cluster)

cluster.append(labels)
idx=0
for wall in cluster:
        np.savetxt("C:/Users/vimal/OneDrive/Desktop/documents-export-2021-06-11/wall/cluster_"+str(idx)+".csv",wall, delimiter=",")
        idx+=1  
Vims Rocz
  • 57
  • 8

0 Answers0