本文主要是介绍雷达点云数据.pcd格式转.bin格式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
雷达点云数据.pcd格式转.bin格式
注意,方法1原则上可行,但是本人没整好pypcd的环境
方法2是绝对可以的。
方法1
1 源码如下:
def pcb2bin1(): # save as bin format''''''import os# import pypcdfrom pypcd import pypcdimport numpy as npfrom tqdm import tqdmpcd_pth = r'./data/002140.pcd'bin_pth = r'./data/002140.bin'files = os.listdir(pcd_pth)files = [f for f in files if f[-4:]=='.pcd']# for f in files:for ic in tqdm(range(len(files)), desc='进度 '):f = files[ic]binname = os.path.join(pcd_pth, f)binname = os.path.join(bin_pth, f[:-4]+'.bin')# Load pcd from pypcdpc = pypcd.PointCloud.from_path(binname)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) / 256points_32 = np.transpose(np.vstack((np_x, np_y, np_z, np_i)))with open(bin_pth, 'w') as f: # Save as bin formatpoints_32.tofile(f)
2 调用pypcd库,但是安装好之后,报错如下
pc = pypcd.PointCloud.from_path(binname)
AttributeError: module 'pypcd' has no attribute 'PointCloud'
此问题是版本不匹配的问题
3 其它人的解决方法
3.1 下载官方源码
git clone https://github.com/dimatura/pypcd
3.2 如下流程
(1)
cd pypcd
git fetch origin pull/9/head:python3
上述 git 命令尝试了很多遍才成功,打印如下
remote: Enumerating objects: 36, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 36 (delta 19), reused 17 (delta 17), pack-reused 14
Unpacking objects: 100% (36/36), 12.82 KiB | 3.00 KiB/s, done.
From https://github.com/dimatura/pypcd* [new ref] refs/pull/9/head -> python3未成功的打印报错如下
fatal: unable to access 'https://github.com/dimatura/pypcd/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
(2)
git checkout python3
(3)
python3 setup.py install --user
方法2
1 源码如下:
def pcd2bin2():import numpy as npimport open3d as o3dpcd_path = './data/002140.pcd'bin_path = './data/002140.bin'# 读取PCD文件 pcd = o3d.io.read_point_cloud(pcd_path)# print(pcd)points = np.asarray(pcd.points)# 查看点云图像# o3d.visualization.draw_geometries([pcd])# 将PCD格式保存为BIN格式points.tofile(bin_path)# o3d.io.write_point_cloud(bin_path, pcd) # 正常执行,但是不保存数据
2 环境
需要包含open3d的环境(注意,这里的python的环境必须是3.7的版本,亲测3.8的python环境一直无法import open3d)
conda create -n pcd2bin python=3.7
conda activate pcd2bin
pip install open3d
参考:
1 python3中pypcd读取点云数据
2 [python pcd2bin_51CTO博客](https://blog.51cto.com/u_16175471/7581334#:~:text=journey title Python PCD转BIN 实现步骤 section 准备工作 清理环境,将读取到的点云数据转换为numpy数组 section 保存为BIN文件 定义保存路径 使用numpy库将点云数据保存为BIN文件 section 完成转换 打印转换成功消息)
这篇关于雷达点云数据.pcd格式转.bin格式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!