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

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++ 版本

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值