点云PCD转成bin

三维点云PCD转换成bin格式

在网上看了一些用PCL直接读取PCD点云,然后直接写入文件,但再通过代码打开显示不了,因为其中很多Nan数据,找到一个大佬写的PCD转成bin格式的代码,是python版本的,要求是提供的PCD文件要包含intensity、(ring,time)等,以下例子仅供参考。

1. 安装依赖

pip install numpy
pip install argparse
pip install pypcd
pip install tqdm

注意 pypcd是python2.7的库

2. 运行代码

git clone https://github.com/Yuseung-Na/pcd2bin.git
cd pcd2bin
python pcd2bin.py --pcd_path=../123/pcd --bin_path=../123/bin --file_name=test

Notes:

这个仓库也有转换方法 https://github.com/Qjizhi/kitti-velodyne-viewer

3. 简易版

def save_lidar_files(src_pth,out_pth,file_count):   # save as bin format
    '''
      Use this function fist to convert the timestamp-name pcd into counter-sorted bin file
    :param src_pth: .pcd files
    :param out_pth: .bin files
    :param file_count : The initial file number you want to save
    :return: None
    '''
    files=[]
    for idx,filename in enumerate(os.listdir(src_pth)):
        name,ext = os.path.splitext(filename)
        if ext == '.pcd':
            files.append(name)
    files.sort()
    for pcd_file in tqdm(files):
        src_lidar_file = src_pth + '/' + str(pcd_file) + '.pcd'
        out_lidar_file = out_pth + '/' + str(file_count).zfill(6) + '.bin'
        # Load pcd from pypcd
        pc = pypcd.PointCloud.from_path(src_lidar_file)
        np_x = (np.array(pc.pc_data['x'], dtype=np.float32)).astype(np.float32)
        np_y = (np.array(pc.pc_data['y'], dtype=np.float32)).astype(np.float32)
        np_z = (np.array(pc.pc_data['z'], dtype=np.float32)).astype(np.float32)
        np_i = (np.array(pc.pc_data['intensity'], dtype=np.float32)).astype(np.float32) / 256
        points_32 = np.transpose(np.vstack((np_x, np_y, np_z, np_i)))
        with open(out_lidar_file, 'w') as f:  # Save as bin format
            points_32.tofile(f)
        file_count += 1
  • 5
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 20
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值