三维点云文件的读写代码总结

版权声明:本文为博主原创文章,欢迎转载,转载请注明出处。 https://blog.csdn.net/cjh_jinduoxia/article/details/88342473

ply文件

python版本

from plyfile import PlyData, PlyElement
# import data_prep_util

def write_ply(points, filename, text=True): # write the array as a ply file --by_xia
    """ input: Nx3, write points to filename as PLY format. """
    points = [(points[i,0], points[i,1], points[i,2]) for i in range(points.shape[0])]
    vertex = np.array(points, dtype=[('x', 'f4'), ('y', 'f4'),('z', 'f4')])
    el = PlyElement.describe(vertex, 'vertex', comments=['vertices'])
    PlyData([el], text=text).write(filename)

def read_ply(filename):
    """ read XYZ point cloud from filename PLY file """
    plydata = PlyData.read(filename)
    pc = plydata['vertex'].data
    # pc_array = np.array([[x, y, z] for x,y,z in pc])
    point_cloud_x = pc['x'].astype(np.float64)
    point_cloud_y = pc['y'].astype(np.float64)
    point_cloud_z = pc['z'].astype(np.float64)
    pc_array = np.column_stack((point_cloud_x, point_cloud_y, point_cloud_z))
    return pc_array

其中的plyfile文件存储在我的资源中。

c++ 版本

文件

python 版本

c++ 版本

猜你喜欢

转载自blog.csdn.net/cjh_jinduoxia/article/details/88342473