Open3D 3차원 점 구름 읽기 시각화, 샘플링, 분리점 제거, 지면 추출

16965 단어 시각화
import open3d as o3d

def display_inlier_outlier(cloud, ind):
    inlier_cloud = cloud.select_by_index(ind)
    outlier_cloud = cloud.select_by_index(ind, invert=True)

    print("Showing outliers (red) and inliers (gray): ")
    outlier_cloud.paint_uniform_color([1, 0, 0])
    inlier_cloud.paint_uniform_color([0.8, 0.8, 0.8])
    o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud], window_name='Open3D Removal Outlier', width=1920,
                                      height=1080, left=50, top=50, point_show_normal=False, mesh_show_wireframe=False,
                                      mesh_show_back_face=False)

#   :  xyz、xyzn、xyzrgb、pts、ply、pcd、txt
pcd = o3d.io.read_point_cloud("D:/pcd/milk_cartoon_all_small_clorox.pcd")
# pcd = o3d.io.read_point_cloud("../../TestData/my_points.txt", format='xyz')
print(pcd)

o3d.visualization.draw_geometries([pcd], window_name='Open3D Origin', width=1920, height=1080, left=50, top=50,
                                  point_show_normal=False, mesh_show_wireframe=False, mesh_show_back_face=False)

#    
# voxel_down_sample(            ,    )
# uniform_down_sample (        n           )
# select_down_sample (         select_down_sample      。              。)
print("Downsample the point cloud with a voxel of 0.003")
downpcd = pcd.voxel_down_sample(voxel_size=0.003)
print(downpcd)
o3d.visualization.draw_geometries([downpcd], window_name='Open3D downSample', width=1920, height=1080, left=50, top=50,
                                  point_show_normal=False, mesh_show_wireframe=False, mesh_show_back_face=False)

#         
#       【Vertex normal estimation】
#                 。 n    。 -  +          。
print("Recompute the normal of the downsampled point cloud")
downpcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
o3d.visualization.draw_geometries([downpcd], window_name='Open3D downSample Normals', width=1920, height=1080, left=50,
                                  top=50, point_show_normal=True, mesh_show_wireframe=False, mesh_show_back_face=False)

#       【outlier removal】
#                   ,                     。      Open3D       。       ,           。
# statistical_outlier_removal 【       】                    。
#                   :nb_neighbors             ,            
#                           std_ratio                         。     ,          
#
# radius_outlier_removal 【       】                    。
#                       :nb_points             
#                                  radius                
print("Statistical oulier removal")
cl, ind = downpcd.remove_statistical_outlier(nb_neighbors=20, std_ratio=2.0)
display_inlier_outlier(downpcd, ind)
downpcd_inlier_cloud = downpcd.select_by_index(ind)
print(downpcd_inlier_cloud)

#      【Plane Segmentation】
# Open3D     RANSAC             。                ,      segement_plane。         。
# distance_threshold                 ,            ; ransac_n                ; num_iterations                 。
#           (a,b,c,d)   ,         (x,y,z),    ax + by + cz + d = 0。                。
plane_model, inliers = downpcd_inlier_cloud.segment_plane(distance_threshold=0.01,
                                             ransac_n=5,
                                             num_iterations=10000)
[a, b, c, d] = plane_model
print(f"Plane equation: {a:.2f}x + {b:.2f}y + {c:.2f}z + {d:.2f} = 0")

inlier_cloud = downpcd_inlier_cloud.select_by_index(inliers)
print('----inlier_cloud: ', inlier_cloud.points)
inlier_cloud.paint_uniform_color([1.0, 0, 0])
outlier_cloud = downpcd_inlier_cloud.select_by_index(inliers, invert=True)
print('----outlier_cloud: ', outlier_cloud.points)
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud], window_name='Open3D Plane Model', width=1920,
                                  height=1080, left=50, top=50, point_show_normal=False, mesh_show_wireframe=False,
                                  mesh_show_back_face=False)
o3d.io.write_point_cloud("D:/pcd/1001140020191217_las2pcd_cx_g.pcd", inlier_cloud)
# help(o3d.visualization.draw_geometries)



좋은 웹페이지 즐겨찾기