PCL库学习:在使用pcl::fromROSMsg()出现intensity消息丢失的现象

当使用pcl::fromROSMsg函数转换sensor_msgs::PointCloud2消息时,可能会遇到intensity字段丢失的情况。这通常由于数据类型不匹配导致。解决方法包括注册自定义的pcl数据类型,定义包含intensity、ring和timestamp的结构体,并使用POINT_CLOUD_REGISTER_POINT_STRUCT进行注册。通过这些步骤,可以确保转换后的点云数据保留所有原始信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用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);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值