点云 3D 数据 读取、保存 - pypcd 包

1. 点云 3D 数据

点云 3D 数据 离线状况 通常以 “.pcd”、“.bin” 等格式存储,其中 “.pcd” 文件在 Ubuntu 下可以方便的使用 pcl_viewer 命令查看;而 “.bin” 格式 则可 以最少的 库依赖 完成对点云的读取保存。

2. Python 下 pypcd 库安装

当前默认支持的是 python 2.* 环境, python 3.* 下的安装需要适配版本,不然使用过程中会报错

2.1 在 Python 2.* 下安装 pypcd

pip install pypcd

2.2 在 Python 3.* 下安装 pypcd

git clone https://github.com/dimatura/pypcd
cd pypcd

git fetch origin pull/9/head:python3

git checkout python3

python3 setup.py install

3. 点云 3D 数据 的读取、保存

3.1 “.pcd” 格式

import numpy as np
from pypcd import pypcd

file_path = "/home/hjw/point_cloud/test.pcd"

# read data
pcd = pypcd.PointCloud.from_path(file_path)
point_cloud = np.zeros((pcd.points, len(pcd.fields)), dtype=np.float32)

for i, field in enumerate(pcd.fields):
    point_cloud[:, i] = np.transpose(pcd.pc_data[field])

# x, y, z, intensity
point_cloud = point_cloud[:, 0:4]


# store_path = "/home/hjw/point_cloud/test_save.pcd"

# # save as binary compressed
# pcd.save_pcd(store_path , compression='binary_compressed')

3.2 “.bin” 格式

import numpy as np

file_path = "/home/hjw/point_cloud/test.bin"

# read data
point_cloud = np.fromfile(file_path , dtype=np.float32)
point_cloud = point_cloud.reshape((-1, 4))

# x, y, z, intensity
point_cloud = point_cloud[:, 0:4]


# store_path = "/home/hjw/point_cloud/test_save.bin"

# # save data
# point_cloud.tofile(store_path)

猜你喜欢

转载自blog.csdn.net/i6101206007/article/details/128063850