python读写自定义格式的pcd文件的示例代码
作者:heroacool
这篇文章主要介绍了python读写自定义格式的pcd文件,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
lio-sam中pose是按照x y z i roll pitch yaw time 存储的,需要用python读取或者保存。
读pcd
from lidar_mapping.tools import py3pcd
import numpy as np
from scipy.spatial.transform import Rotation as R
def read_transformations(filename: str):
pc = py3pcd.PointCloud.from_path(filename)
data = pc.pc_data.view(
np.dtype([
("x", np.float32),
("y", np.float32),
("z", np.float32),
("intensity", np.float32),
("roll", np.float32),
("pitch", np.float32),
("yaw", np.float32),
("time", np.float64)
])
).reshape(-1, 1)
return data写pcd
import numpy as np
from lidar_mapping.tools import py3pcd
# 创建一个包含点云数据的numpy array
point_cloud = np.array([
[1.0, 2.0, 3.0, 0.5, 0.1, 0.2, 0.3, 1234567890.1],
[4.0, 5.0, 6.0, 0.6, 0.4, 0.5, 0.6, 1234567900.24]],
dtype=np.dtype([
("x", np.float32),
("y", np.float32),
("z", np.float32),
("intensity", np.float32),
("roll", np.float32),
("pitch", np.float32),
("yaw", np.float32),
("time", np.float64)
])
)
pcl_data = py3pcd.PointCloud.from_array(point_cloud)
pcl_data.save_pcd('point_cloud.pcd', compression='binary')到此这篇关于python读写自定义格式的pcd文件的文章就介绍到这了,更多相关python读写pcd文件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
