显示点云
import numpy as np
import open3d as o3d
if __name__ == "__main__":
print("Load a ply point cloud, print it, and render it")
pcd = o3d.io.read_point_cloud("../../TestData/fragment.ply")
print(pcd)
print(np.asarray(pcd.points))
o3d.visualization.draw_geometries([pcd],window_name='Open3D_1')
# pointcloud = o3d.PointCloud()
# pointcloud.points = o3d.Vector3dVector(np.asarray(pcd.points))
# o3d.visualization.draw_geometries([pointcloud])
# downpcd = o3d.geometry.voxel_down_sample(pointcloud, voxel_size=0.05)
# o3d.visualization.draw_geometries([downpcd])
print("Downsample the point cloud with a voxel of 0.05")
# downpcd = pcd.voxel_down_sample(voxel_size=0.05) # 官方文档上的这句话会报错
downpcd = o3d.geometry.voxel_down_sample(pcd, voxel_size=0.05)
o3d.visualization.draw_geometries([downpcd],window_name='Open3D_2')
print("Recompute the normal of the downsampled point cloud")
# downpcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
o3d.geometry.estimate_normals(downpcd,search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
o3d.visualization.draw_geometries([downpcd],window_name='Open3D_3')
print("Print a normal vector of the 0th point")
print(downpcd.normals[0])
print("Print the normal vectors of the first 10 points")
print(np.asarray(downpcd.normals)[:10, :])
print("")
print("Load a polygon volume and use it to crop the original point cloud")
vol = o3d.visualization.read_selection_polygon_volume(
"../../TestData/Crop/cropped.json")
chair = vol.crop_point_cloud(pcd)
o3d.visualization.draw_geometries([chair],window_name='Open3D_4')
print("")
print("Paint chair")
chair.paint_uniform_color([1, 0.706, 0])
o3d.visualization.draw_geometries([chair],window_name='Open3D_5')
print("")
Result:
Load a ply point cloud, print it, and render it
Reading PLY: [========================================] 100%
geometry::PointCloud with 196133 points.
[[0.65234375 0.84686458 2.37890625]
[0.65234375 0.83984375 2.38430572]
[0.66737998 0.83984375 2.37890625]
...
[2.00839925 2.39453125 1.88671875]
[2.00390625 2.39488506 1.88671875]
[2.00390625 2.39453125 1.88793314]]
Downsample the point cloud with a voxel of 0.05
Recompute the normal of the downsampled point cloud
Print a normal vector of the 0th point
[ 0.85641574 0.01693013 -0.51600915]
Print the normal vectors of the first 10 points
[[ 8.56415744e-01 1.69301342e-02 -5.16009150e-01]
[-3.10071169e-01 3.92564590e-02 -9.49902522e-01]
[-2.21066308e-01 2.07235365e-07 -9.75258780e-01]
[-2.65577574e-01 -1.84601949e-01 -9.46250851e-01]
[-7.91944115e-01 -2.92017206e-02 -6.09894891e-01]
[-8.84912237e-02 -9.89400811e-01 1.15131831e-01]
[ 6.28492508e-01 -6.12988948e-01 -4.78791935e-01]
[ 7.28260110e-01 -4.73518839e-01 -4.95395924e-01]
[-5.07368635e-03 -9.99572767e-01 -2.87844085e-02]
[ 3.49295119e-01 1.16948013e-02 -9.36939780e-01]]
Load a polygon volume and use it to crop the original point cloud
Cropping geometry: [========================================] 100%
Paint chair