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文件存储在我的资源中。