目录
1. create_from_point_cloud_ball_pivoting
2. create_from_point_cloud_alpha_shape
3. create_from_point_cloud_poisson
从以下效果来看,第三个方法最好。
1. create_from_point_cloud_ball_pivoting
关键代码:
rec_mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting( pcd, o3d.utility.DoubleVector(radii))
triangle_mesh_from_point_cloud_ball_pivoting.py
import open3d as o3d
import numpy as np
if __name__ == "__main__":
# 1. read pcd
bunny = o3d.data.BunnyMesh()
gt_mesh = o3d.io.read_triangle_mesh(bunny.path)
gt_mesh.compute_vertex_normals()
pcd = gt_mesh.sample_points_poisson_disk(3000)
print("Displaying input pointcloud ...")
o3d.visualization.draw([pcd], point_size=5)
# 2. creat mesh by ball.
pcd.estimate_normals()
distances = pcd.compute_nearest_neighbor_distance()
avg_dist = np.mean(distances)
radius = 2 * avg_dist
# radii = [0.005, 0.01, 0.02, 0.04]
radii = [radius, radius*2, radius*4, radius*8]
# radii = [radius, radius*2]
print('Running ball pivoting surface reconstruction ...')
rec_mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(
pcd, o3d.utility.DoubleVector(radii))
print("Displaying reconstructed mesh ...")
o3d.visualization.draw([rec_mesh])
2. create_from_point_cloud_alpha_shape
关键代码:
mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape( pcd, alpha)
import open3d as o3d
if __name__ == "__main__":
# 1. read pcd
bunny = o3d.data.BunnyMesh()
mesh = o3d.io.read_triangle_mesh(bunny.path)
mesh.compute_vertex_normals()
pcd = mesh.sample_points_poisson_disk(3000)
print("Displaying input pointcloud ...")
o3d.visualization.draw_geometries([pcd])
# 2. create mesh by alpha
alpha = 0.03 # 越大形状偏离越大
print(f"alpha={alpha:.3f}")
print('Running alpha shapes surface reconstruction ...')
mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape(
pcd, alpha)
mesh.compute_triangle_normals(normalized=True)
print("Displaying reconstructed mesh ...")
o3d.visualization.draw_geometries([mesh], mesh_show_back_face=True)
3. create_from_point_cloud_poisson
关键代码:
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson( pcd, depth=9)
import open3d as o3d
import numpy as np
if __name__ == "__main__":
# eagle = o3d.data.EaglePointCloud()
# pcd = o3d.io.read_point_cloud(eagle.path)
# R = pcd.get_rotation_matrix_from_xyz((np.pi, -np.pi / 4, 0))
# pcd.rotate(R, center=(0, 0, 0))
# print('Displaying input pointcloud ...')
# o3d.visualization.draw([pcd])
bunny = o3d.data.BunnyMesh()
mesh = o3d.io.read_triangle_mesh(bunny.path)
mesh.compute_vertex_normals()
pcd = mesh.sample_points_poisson_disk(3000)
print("Displaying input pointcloud ...")
o3d.visualization.draw_geometries([pcd])
print('Running Poisson surface reconstruction ...')
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
pcd, depth=9) # depth值越大,效果越好
print('Displaying reconstructed mesh ...')
mesh.paint_uniform_color((0, 1, 1))
o3d.visualization.draw([mesh])