【ROS-数据格式理解】PointCloud2格式理解
1、PointCloud2消息格式
具体官方数据http://docs.ros.org/en/jade/api/sensor_msgs/html/msg/PointCloud2.html
在ros中查看如下:
std_msgs/Header header
uint32 seq
time stamp
string frame_id
uint32 height
uint32 width
sensor_msgs/PointField[] fields
uint8 INT8=1
uint8 UINT8=2
uint8 INT16=3
uint8 UINT16=4
uint8 INT32=5
uint8 UINT32=6
uint8 FLOAT32=7
uint8 FLOAT64=8
string name
uint32 offset
uint8 datatype
uint32 count
bool is_bigendian
uint32 point_step
uint32 row_step
uint8[] data
bool is_dense
2、PointCloud2 消息格式例子
header: // 点云的头信息
seq: 963 //
stamp: // 时间戳
secs: 1541143772
nsecs: 912011000
frame_id: "/camera_init"
height: 1 // If the cloud is unordered, height is 1 如果cloud 是无序的 height 是 1
width: 852578 //点云的长度
fields: // sensor_msgs/PointField[] fields
-
name: "x"
offset: 0
datatype: 7 // uint8 INT8 = 1
// uint8 UINT8 = 2
// uint8 INT16 = 3
// uint8 UINT16 = 4
// uint8 INT32 = 5
// uint8 UINT32 = 6
// uint8 FLOAT32 = 7
// uint8 FLOAT64 = 8
count: 1
-
name: "y"
offset: 4
datatype: 7
count: 1
-
name: "z"
offset: 8
datatype: 7
count: 1
-
name: "intensity"
offset: 16
datatype: 7
count: 1
is_bigendian: False
point_step: 32 // Length of a point in bytes 一个点占的比特数
row_step: 27282496 // Length of a row in bytes 一行的长度占用的比特数
data: [ .......................................................... ] // Actual point data, size is (row_step*height)
is_dense: True // 没有非法数据点
data 内部包含的是 包含点云的二进制数据流! 必须要单独解析,直接读取没有任何意义
3、理解其中的fields
为什么其中的fields有如此多的数据?参考文章https://answers.ros.org/question/273182/trying-to-understand-pointcloud2-msg/
PointCloud2消息的数据fields包含编码为字节流的点列表,其中每个点都是一个结构体。单个PointCloud2消息中点的格式由字段定义,字段是sensor_msgs/PointField对象的列表。为了将数据转换回单独的点,必须对其进行反序列化。PointCloud库定义了自动执行此操作的方法(在Python中,您将使用pc2.read_points)。在本质上,这些方法使用内存重解释将字节流转换为一组点(例如Python的struct.unpack()或c++中的重解释类型转换)。
字节流表示的优点是它是一种非常灵活的紧凑的数据传输方式,允许对点使用任意结构。缺点是如果不进行反序列化,消息是不可读的。