使用open3d合併ply模型

hxqmw發表於2024-08-29
import open3d as o3d
from scipy.ndimage import binary_fill_holes

def merge_ply(ply1, ply2, output_path):

    # 載入兩個多邊形模型
    mesh1 = o3d.io.read_triangle_mesh(ply1)
    mesh2 = o3d.io.read_triangle_mesh(ply2)

    # 使用 + 運算子合並兩個多邊形模型
    merged_mesh = mesh1 + mesh2

    # 去除合併後的重複頂點和三角形
    merged_mesh.remove_duplicated_vertices()
    merged_mesh.remove_duplicated_triangles()

    # 可選:合併近距離的頂點
    # merged_mesh.merge_close_vertices(distance=0.001)

    # 儲存或視覺化合並後的多邊形模型
    o3d.io.write_triangle_mesh("path_to_output_mesh.ply", merged_mesh)
    o3d.visualization.draw_geometries([merged_mesh])


if __name__ == '__main__':
    ply1 = "Left-Caudate.ply"
    ply2 = "Left-Lenticula.ply"
    merge_ply_path = "merged_mesh.ply"
    merge_ply(ply1, ply2, merge_ply_path)

  

合併後的ply檔案:

相關文章