python实现将点云的.bin格式文件转化为.txt格式

示例

备注:示例代码的.bin文件的后缀‘.bin’在转换前已经去掉了

import numpy as np

def load_pc_kitti(pc_path, index):
    print(index)
    scan = np.fromfile(pc_path, dtype=np.float32)
    scan = scan.reshape((-1, 4))
    points = scan[:, :]  # get xyz

    f = open('/home/yangguide/Documents/lidar_3dssd/data/velodynetxt/%d' % index, 'w')
    for i in range(points.shape[0]):
        for j in range(4):
            strNum = str(points[i][j])
            f.write(strNum)
            f.write(' ')
        f.write('\n')
    f.close()

    print(points)
    return points

for index in range(0, 2244):
    pc_path = "/home/yangguide/Documents/lidar_3dssd/data/velodyne_new/%d" % index
    load_pc_kitti(pc_path, index)

你可能感兴趣的:(#,Python编程,自动驾驶,深度学习,tensorflow,pytorch,机器学习)