(三)ros 点云格式转PCL点云格式

(1)sensor_msgs::PointCloud2 是ROS 点云数据

rosmsg show sensor_msgs/PointCloud2 显示

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

特别注意sensor_msgs/PointField[] fields,表示每个点的属性信息

一下为fields 属性信息

string name       # 点的字段名

uint32 offset      # 相对于结构体起始地址的字节数

uint8  datatype  # 该字段所占用的字节数

uint32 count      # 该字段的数量,通常为1

datatype 不同值与类型的对应如下:

uint8 INT8    = 1             // 1字节

uint8 UINT8   = 2           // 1字节

uint8 INT16   = 3            // 2字节

uint8 UINT16  = 4          // 2字节

uint8 INT32   = 5            // 4字节

uint8 UINT32  = 6          // 4字节

uint8 FLOAT32 = 7        // 4字节

uint8 FLOAT64 = 8        // 8字节

比如想要得到激光点云的反射强度。Fields中的name为"intensity"。但是具体数值不能够通过这些属性得到,需要转换成PCL点云格式

(2)PCL中的点云数据结构

PCL中的功能函数多以模板的形式实现,可以使用多种点云类型。比如:

PointXYZ - float x, y, z)

PointXYZI - float x, y, z, intensity

PointXYZRGB - float x, y, z, rgb

PointXYZRGBA - float x, y, z, uint32_t rgba

Normal - float normal[3], curvature 法线方向,对应的曲率的测量值

PointNormal - float x, y, z, normal[3], curvature 采样点,法线和曲率

(3)如果需要获取反射强度信息:

需要把ros 点云格式转为PCL点云格式

pcl::PointCloud::Ptr cloud(new pcl::PointCloud);

pcl::fromROSMsg(*msg, *cloud);

for (size_t i = 0;i < cloud->points.size();i++)

{

    float intensity = cloud->points[i].intensity;

}

你可能感兴趣的:(机器人,ros,pcl,机器人)