zoukankan      html  css  js  c++  java
  • pcl点云与ros之间的数据类型转换

    一、基础数据类型

    pcl::PointCloud<pcl::PointXYZ> pcl的点云

    pcl::PCLPointCloud2 pcl的第二种点云

    sensor_msgs::PointCloud2 ROS中的点云

    sensor_msgs::PointCloud ROS中的点云

     二、转换函数

    1. sensor_msgs::PCLPointCloud2 <=> pcl::PCLPointCloud2

    void pcl_conversions::toPCL(const sensor_msgs::PointCloud2 &, pcl::PCLPointCloud2 &)

    void pcl_conversions::moveFromPCL(const pcl::PCLPointCloud2 &, const sensor_msgs::PointCloud2 &);

    2. pcl::PCLPointCloud2 <=> pcl::PointCloud<pcl::PointXYZ>

    void pcl::fromPCLPointCloud2(const pcl::PCLPointCloud2 &, pcl::PointCloud<pointT> &);

    void pcl::toPCLPointCloud2(const pcl::PointCloud<pointT> &, pcl::PCLPointCloud2 &);

    3. sensor_msgs::PCLPointCloud2 <=> pcl::PointCloud<pcl::PointXYZ>

    void pcl::fromROSMsg(const sensor_msgs::PointCloud2 &, pcl::PointCloud<T> &);

    void pcl::toROSMsg(const pcl::PointCloud<T> &, sensor_msgs::PointCloud2 &);

    4. sensor_msgs::PointCloud2 <=> sensor_msgs::PointCloud

    static bool sensor_msgs::convertPointCloudToPointCloud2(const sensor_msgs::PointCloud & input,sensor_msgs::PointCloud2 & output);

    static bool sensor_msgs::convertPointCloud2ToPointCloud(const sensor_msgs::PointCloud2 & input,sensor_msgs::PointCloud & output);

    三、实例

            pcl::PointCloud<PointT> mls_points;
            sensor_msgs::PointCloud2 cloud_final;
            pcl::toROSMsg(mls_points,cloud_final);
    
    
            std::vector<double> angles_after,ranges_after;
            // Iterate through pointcloud
            for (sensor_msgs::PointCloud2ConstIterator<float> iter_x(cloud_final, "x"),
              iter_y(cloud_final, "y"), iter_z(cloud_final, "z");
              iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z)
            {
    
              double range = hypot(*iter_x, *iter_y);
              double angle = atan2(*iter_y, *iter_x);
              angles_after.push_back(angle);
              ranges_after.push_back(range);
            }
            sensor_msgs::LaserScan msg;
            msg.header = scan_msg->header;
            msg.angle_min       = scan_msg->angle_min;
            msg.angle_max       = scan_msg->angle_max;
            msg.angle_increment = scan_msg->angle_increment;
            msg.time_increment  = scan_msg->time_increment; // 0.00002469;
            msg.range_min       = scan_msg->range_min;
            msg.range_max       = scan_msg->range_max;
            msg.ranges.resize(ranges.size());
            for(int i=0;i<msg.ranges.size();i++)
            {
                msg.ranges[i]=ranges[i];
            }





  • 相关阅读:
    git fetch 和git pull 的差别
    解决npm install安装慢的问题
    Git本地分支和远程分支关联
    phalapi 2.14 使用(一)增加顶级命名空间、调整返回结构字段
    vue-element-template实战(五) 获取后端路由表动态生成权限
    vue-element-template实战(四)使用mock数据,新增用户管理界面
    使用phalapi 2.14版本的问题及解决办法
    关于vue
    git详细操作
    三次握手四次挥手理解
  • 原文地址:https://www.cnblogs.com/zx-hit/p/13819612.html
Copyright © 2011-2022 走看看