在使用pcl::fromROSMsg(sensor_msgs::PointCloud2 in, pcl::PointCloud<PointType> out)时出现了intensity消息丢失的现象。
解决方案如下:(以robosense的lidar为例)
首先播放录制的bag包;播放话题/rslidar_points;
另开终端输入:
rosrun pcl_ros pointcloud_to_pcd input:=/rslidar_points
得到如下的pcd文件(1658123122906719.pcd)
# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z intensity ring timestamp
SIZE 4 4 4 1 2 8
可以发现intensity占一个字节,与自带的pcl数据类型不匹配,因此进行如下处理:
1.注册自定义pcl数据类型
2.定义结构体
//定义两个头文件
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
//定义robosense的结构体
namespace robosense_ros {
struct EIGEN_ALIGN16 Point {
PCL_ADD_POINT4D;
std::uint8_t intensity;
std::uint16_t ring;
double timestamp;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
}
// namespace robosense_ros 注册pcl数据类型
POINT_CLOUD_REGISTER_POINT_STRUCT(robosense_ros::Point,
(float, x, x)
(float, y, y)
(float, z, z)
(std::uint8_t, intensity, intensity)
(std::uint16_t, ring, ring)
(double, timestamp, timestamp)
)
robosense_ros::Point out;
sensor_msgs::PointCloud2 int;
pcl::fromROSMsg(in, out);