优化来自点云的3d表面重构

问题描述

我对o3d还是很陌生,我希望有人根据我的代码向我展示:) 我正在尝试从(少量)实验数据重建表面。我想拥有尽可能多的灵活性/可调性。

我的代码是这样的:

import open3d as o3d
sys.path.append('..')

output_path=(r"C:\Users\Giammarco\Desktop\PYTHON_graphs\OUTPUTS\\")

poisson_mesh=[]
densities=[]

pcd = o3d.geometry.PointCloud()
pcd.normals = o3d.utility.Vector3dVector(np.zeros((1,3)))  # invalidate existing normals

#load the point cloud
point_cloud=np.array([x,y,z]).T
cloud = PyntCloud.from_instance("open3d",pcd)
pcd.points = o3d.utility.Vector3dVector(point_cloud)
#resise the scale of the sample
vox_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd,1.)

#presetn in all approaches of plc
kdtree = cloud.add_structure("kdtree")
testc = cloud.get_neighbors(k=5)
distances = pcd.compute_nearest_neighbor_distance()
avg_dist = np.mean(distances)

#compute the normals
pcd.estimate_normals(); #mandatory
#orient the normals
#Number of nearest neighbours: 5 is the minimum to have a closed surface with scale >= 2
pcd.orient_normals_consistent_tangent_plane(7)

#Poisson algorithm
poisson_mesh,densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd,depth=9,width=0,scale=3.5,linear_fit=False)
bbox = pcd.get_axis_aligned_bounding_box()
p_mesh_crop = poisson_mesh.crop(bbox)

# cleaning
# p_mesh_crop =poisson_mesh.simplify_quadric_decimation(6000)
# p_mesh_crop.remove_unreferenced_vertices
# p_mesh_crop.remove_degenerate_triangles()
# p_mesh_crop.remove_duplicated_triangles()
# p_mesh_crop.remove_duplicated_vertices()
# p_mesh_crop.remove_non_manifold_edges()

#designing the surface colour
#densities are the real density of features
densities = np.asarray(densities)
density_colors = plt.get_cmap('viridis')((dgo - dgo.min()) / (dgo.max() - dgo.min()))
density_colors = density_colors[:,:3]

#works for the plotting in o3d
poisson_mesh.vertex_colors = o3d.utility.Vector3dVector(density_colors)


o3d.io.write_triangle_mesh(output_path+"bpa_mesh.ply",dec_mesh);
o3d.io.write_triangle_mesh(output_path+"p_mesh_c.ply",poisson_mesh);
# o3d.io.write_triangle_mesh(output_path+"p_mesh_c.ply",p_mesh_crop);

# my_lods = lod_mesh_export(p_mesh_crop,[100000,50000,10000,1000,100],".ply",output_path)
my_lods = lod_mesh_export(poisson_mesh,output_path)

# o3d.visualization.draw_geometries([pcd,p_mesh_crop],mesh_show_back_face=True)
# o3d.visualization.draw_geometries([pcd,poisson_mesh],poisson_mesh[100000]],point_show_normal=True)

# tri_mesh_pois.show()#designing the surface colour
#densities are the real density of features
densities = np.asarray(densities)
density_colors = plt.get_cmap('viridis')((dgo - dgo.min()) / (dgo.max() - dgo.min()))
density_colors = density_colors[:,:3]

#works for the plotting in o3d
poisson_mesh.vertex_colors = o3d.utility.Vector3dVector(density_colors)
o3d.io.write_triangle_mesh(output_path+"p_mesh_c.ply",poisson_mesh);
my_lods = lod_mesh_export(poisson_mesh,output_path)

#SHORTCUTS from keyboard: n = show normals,q = quit,w = mesh
o3d.visualization.draw_geometries([pcd,mesh_show_back_face=True)

一些输出:

poisson knn=7 size=1.5

with normals

  1. 我担心create_from_point_cloud_poisson拟合模型选项:除了depthsize以外,还有什么方法可以调整其参数?我是否应该设置一个迭代过程以实现更好的转换(例如阈值)?如您所见,计算表面与实验点之间的距离很大。

  2. 是否正确设置了法线估计?在第二个输出中,某些方向仍然非常随机。 我也尝试过以下语法:pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.05,max_nn=20));,但是它不会收敛到封闭的表面,而不会收敛到一个平面(见下文)

estimation of normals

请给我有关我的代码的反馈以及有关如何改进它的建议。

谢谢您的支持!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)