当前位置: 首页 > news >正文

ROS第三梯:ROS+C++实现速腾Bag包的解析

解决问题:速腾Bag包利用bag_to_pcd生成的pcd文件字段名称存在问题,多了几个异常的"_",导致强度属性无法在Intensity中显示。

解决方案:利用sensor_msgs库进行数据读取和转换成sensor_msgs::PointCloud格式,再通过遍历该数据结构获得坐标和属性信息,具体代码如下:

/*
依赖库:
roscpp
rosbag
std_msgs
sensor_msgs
*/
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/PointCloud.h>
#include <sensor_msgs/point_cloud_conversion.h>
#include <string>
#include <stdlib.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <boost/foreach.hpp>
#include <boost/filesystem.hpp>
#include <fstream>rosbag::Bag bag;
bag.open(path, rosbag::bagmode::Read); //open *.bag
//set topics which you want to read
std::vector<std::string> topics; //这个是我指定要读取的消息topic
topics.push_back(std::string("/bp1/rslidar_points"));
//read defined topics
rosbag::View view(bag, rosbag::TopicQuery(topics));; 
for (rosbag::MessageInstance const m : view) 
{sensor_msgs::PointCloud2::ConstPtr input = m.instantiate<sensor_msgs::PointCloud2>();if (input == NULL) {continue;}sensor_msgs::PointCloud clouddata;sensor_msgs::convertPointCloud2ToPointCloud(*input, clouddata);for(int i = 0;i<clouddata.points.size();i++){PtType point;point.x = clouddata.points[i].x;if(isnan(point.x)) continue;point.y = clouddata.points[i].y;point.z = clouddata.points[i].z;//设置反射强度point.intensity = clouddata.channels[0].values[i];  //设置ring  point.ring = clouddata.channels[1].values[i];    //设置timestamppoint.timestamp = clouddata.channels[2].values[i];    std::cout<<i<<" "<<point.x<<" "<<point.y<<" "<<point.z<<" "<<point.intensity<<" "<<point.ring<<" "<<std::to_string(clouddata.channels[2].values[i])<<std::endl;
}


http://www.mrgr.cn/news/23742.html

相关文章:

  • 微信支付商户的“商家转账到零钱”产品快速开通指南
  • 变革供应链管理:AI与数据科学的影响
  • LeetCode_sql_day22(1112.每位学生的最高成绩)
  • 鸿蒙开发前景
  • 并发编程:AQS(上)
  • Linux 安装神州通用数据库 ShenTong7.0.8_342.92_linux64
  • uniapp登录页面( 适配:pc、小程序、h5)
  • vue3数据持久化方案:pinia-plugin-persistedstate源码浅析
  • 若依Ruoyi之智能售货机运营管理系统(新增运营运维工单管理)
  • 如何在guitarpro中新建六线谱和简谱并实现简谱在下方?
  • 数据结构应用实例(二)——K均值聚类
  • Vue+SpringBoot+数据库整体开发流程 1
  • Qml 实现水波进度动画条
  • [笔记] 电机工作制以及软硬特性的本质推导
  • LeetCode之高频SQL50题
  • Vue2+JS项目升级为Vue3+TS之jquery的maphilight引入项目(附使用)
  • python如何获取html中的所有链接
  • 儿童护眼灯哪个牌子好?五款眼科医生推荐的台灯分享
  • 诸葛io:消费金融行业智能运营与数智化经营模型构建
  • Kotlin入门实用开发技巧与注意事项