使用pcl::fromROSMsg()函数报错Failed to find match for field ‘intensity‘

6 篇文章 2 订阅
2 篇文章 0 订阅

使用LGSVL创建了激光雷达传感器,其中的原始点云PointCloud2类型的话题中含有intensity数据,并且在Rviz中可以将强度信息显示出来。
使用pcl::fromROSMsg()函数将ROS的PointCloud2类型的消息转成pcl::PointXYZI类型的数据后,出现了Failed to find match for field ‘intensity’ 的问题。
但是,在现实中使用pcl::fromROSMsg()处理激光雷达传感器的原始点云数据不会有问题。
在这里提供解决办法:

自己搭建转换函数,将PointCloud2类型的数据转换成pcl::PointXYZI类型

void callback(const sensor_msgs::PointCloud2ConstPtr &cloudIn)
{
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloudPtr(new pcl::PointCloud<pcl::PointXYZI>);

    // Get the field structure of this point cloud
    int pointBytes = cloudIn->point_step;
    int offset_x;
    int offset_y;
    int offset_z;
    int offset_int;
    for (int f=0; f<cloudIn->fields.size(); ++f)
    {
        if (cloudIn->fields[f].name == "x")
            offset_x = cloudIn->fields[f].offset;
        if (cloudIn->fields[f].name == "y")
            offset_y = cloudIn->fields[f].offset;
        if (cloudIn->fields[f].name == "z")
            offset_z = cloudIn->fields[f].offset;
        if (cloudIn->fields[f].name == "intensity")
            offset_int = cloudIn->fields[f].offset;
    }
    // populate point cloud object
    for (int p=0; p<cloudIn->width; ++p)
    {
            pcl::PointXYZI newPoint;
            newPoint.x = *(float*)(&cloudIn->data[0] + (pointBytes*p) + offset_x);
            newPoint.y = *(float*)(&cloudIn->data[0] + (pointBytes*p) + offset_y) ;
            newPoint.z = *(float*)(&cloudIn->data[0] + (pointBytes*p) + offset_z);
            newPoint.intensity = *(unsigned char*)(&cloudIn->data[0] + (pointBytes*p) + offset_int);
            cloudPtr->points.push_back(newPoint);
    }
    sensor_msgs::PointCloud2 cloud_msg2;
    pcl::toROSMsg(*cloudPtr,cloud_msg2);
}

参考:https://answers.ros.org/question/307881/failed-to-find-match-for-field-intensity-with-ouster-lidar/

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你在运行lego_loam时,出现类似于“Failed to find match for field 'intensity'”这样的错误,通常是因为你的点云数据中缺少了某些字段,例如intensity字段。 解决这个问题的方法,一般有以下几个步骤: 1. 确认你的点云数据中是否包含intensity字段。不同的激光雷达厂商提供的点云数据格式可能不同,需要查看你使用激光雷达的数据格式说明来确认是否包含intensity字段。 2. 如果你的点云数据中确实缺少intensity字段,可以使用ROS工具包中的PointCloud2节点来添加缺失的字段。例如,以下命令可以添加一个名为intensity的字段,并将其值设置为0: ``` rosrun pcl_ros pointcloud_to_pointcloud2 input_cloud:=<input_cloud_topic> output_cloud:=<output_cloud_topic> fields:=x,y,z,intensity:=0 ``` 其中,input_cloud_topic是原始点云数据的话题,output_cloud_topic是添加了intensity字段后输出的点云数据的话题。 3. 如果你的点云数据中包含intensity字段,但仍然出现“Failed to find match for field 'intensity'”这样的错误,可能是因为你没有正确设置ROS参数。lego_loam使用了一些ROS参数来控制点云的处理,例如`/laser_cloud_surround_num`和`/use_cloud_ring`等参数。确保这些参数已正确设置。 如果以上步骤都无法解决问题,可以尝试检查你的代码或配置文件是否存在其他问题,并查看ROS终端的输出,以便更好地理解错误发生的原因。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值