点云—>Mesh模型
- 1.介绍
- 1.1 背景
- 1.2 效果示意
- 2 算法实现
- 2.1 依赖库
- 2.2 实验数据
- 2.3 代码实现
- 2.4 实验效果
- 3.总结
1.介绍
1.1 背景
(1)本文主要内容是将三维点云(离散的三维点)进行表面重建生成Mesh网格,之前有篇关于开源软件-Cars-Mesh使用,它是对开源软件-Cars使用生成的点云进行处理得到Mesh网格结构,由于使用cars-mesh需要的配置文件较多,深入其内部涉及到点云mesh构建部分,得出如下结论:
cars-mesh主要有三种mesh构建方法:
- 泊松表面重建(poisson_reconstruction)
- Delaunay 三角剖分(delaunay_2d_reconstruction)
- ball_pivoting_reconstruction
此外还有移动立方体(Marching Cubes Algorithm)、贪婪投影三角化(Greedy Triangulation)等方法。
(2)由于基于卫星影像生成的建筑物点云往往只有建筑物屋顶点云,建筑物立面几乎没有点云,因此充分考虑这种特点,选取了Delaunay三角剖分的方法进行重建,能够保持建筑物立面垂直以及屋顶有棱有角。
1.2 效果示意
如下效果是在meshlab中呈现的:
2 算法实现
2.1 依赖库
本算法依赖三维点云处理库open3d以及在二维上进行三角剖分的Delaunay实现函数,这里在scipy和matplotlib均有实现,本文选择了scipy中的。
2.2 实验数据
vertices.ply,其只包含点的xyz信息,点云对应的颜色无。实验数据见资源绑定,包含原始点云和mesh构建后的数据,效果在cloudcompare中按照高程渲染效果如下:
2.3 代码实现
import open3d as o3d
import numpy as np
from scipy.spatial import Delaunay
import matplotlib.tri as mtriclass Mesh:def __init__(self, vertices, triangles, vertex_colors=None):self.vertices = vertices self.triangles = trianglesself.vertex_colors = vertex_colorsdef delaunay_2d_reconstruction(pcd_file: str, method: str = "scipy") -> Mesh:"""2.5D Delaunay triangulation: Delaunay triangulation on the planimetricpoints and add afterwards the z coordinates.Parameters----------pcd_file: strPath to the PLY file containing point cloud data.method: str, default='scipy'Method to use for Delaunay 2.5D triangulation. Available methods are'scipy' and 'matplotlib'.Returns-------mesh: MeshMesh object containing vertices, triangles, and vertex colors."""# Load point cloud from PLY filepcd = o3d.io.read_point_cloud(pcd_file)# Get points, colors, and z coordinates from point cloudpoints = np.asarray(pcd.points)[:, :2] # Project points to XY planecolors = np.asarray(pcd.colors)# Perform 2D Delaunay triangulationif method == "scipy":mesh_data = Delaunay(points)elif method == "matplotlib":mesh_data = mtri.Triangulation(points[:, 0], points[:, 1])# Construct meshmesh_vertices = np.hstack([points, np.zeros((len(points), 1))])mesh_triangles = mesh_data.simplices# Set z coordinates based on the original point cloudz_coordinates = np.asarray(pcd.points)[:, 2]mesh_vertices[:, 2] = z_coordinates# Create Mesh object with vertex colorsmesh = Mesh(mesh_vertices, mesh_triangles, vertex_colors=colors)return meshdef save_mesh_as_ply(mesh: Mesh, filename: str):"""Save mesh as a PLY file.Parameters----------mesh: MeshMesh object containing vertices, triangles, and vertex colors.filename: strPath to save the PLY file."""# Create Open3D TriangleMesh objectmesh_o3d = o3d.geometry.TriangleMesh()mesh_o3d.vertices = o3d.utility.Vector3dVector(mesh.vertices)mesh_o3d.triangles = o3d.utility.Vector3iVector(mesh.triangles)# Set vertex colorsif mesh.vertex_colors is not None:mesh_o3d.vertex_colors = o3d.utility.Vector3dVector(mesh.vertex_colors)# Save TriangleMesh object to PLY fileo3d.io.write_triangle_mesh(filename, mesh_o3d)# Example usage:
pcd_file = "vertices.ply"
method = "scipy" # or "matplotlib"
mesh = delaunay_2d_reconstruction(pcd_file, method)
save_mesh_as_ply(mesh, "vertices_result_mesh.ply")
2.4 实验效果
整体效果在前面已经有呈现了,以下呈现几栋比较高的建筑效果:首先是mesh网格结构:
3.总结
整体而言,针对基于卫星影像生成的点云,Delaunay 三角剖分mesh构建效果良好:
(1)mesh重构本质上还是依赖于点云生成效果好坏,Delaunay 三角剖分在高建筑效果比较突出,但在低矮建筑效果差一些;
(2)在建筑物楼顶棱角细节层面以及与地面接触的部分有待进一步优化;
(3)TODO:尝试更多的mesh重构方法以及优化(2)