雷达点云 sensor_msgs::PointCloud2 pcl::PointCloud
数据格式转换参考代码
官方对点云格式的介绍,主要有四种,sensor_msgs::PointCloud已经弃用。参考
sensor_msgs::PointCloud — ROS message (deprecated)
sensor_msgs::PointCloud2 — ROS message
pcl::PCLPointCloud2 — PCL data structure mostly for compatibility with ROS (I think)
pcl::PointCloud<T> — standard PCL data structure
sensor_msgs::PointCloud2 to pcl::PointCloudpcl::PointXYZ如果报错可以参考解决办法
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_types.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/conversions.h>
#include <pcl_ros/transforms.h>
void cloud_cb(const boost::shared_ptr<const sensor_msgs::PointCloud2>& input){
pcl::PCLPointCloud2 pcl_pc2;
pcl_conversions::toPCL(*input,pcl_pc2);
pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(pcl_pc2,*temp_cloud);
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::fromROSMsg (*input, cloud);
}
sensor_msgs::PointCloud2与pcl::PCLPointCloud2转换并进行降采样。
#include <pcl/filters/voxel_grid.h>
...
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
pcl::PCLPointCloud2 cloud_filtered;
pcl_conversions::toPCL(*cloud_msg, *cloud);
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloudPtr);
sor.setLeafSize (0.1, 0.1, 0.1);
sor.filter (cloud_filtered);
sensor_msgs::PointCloud2 output;
pcl_conversions::fromPCL(cloud_filtered, output);
pub.publish (output);
}
sensor_msgs::PointCloud2与pcl::PointCloud转换并估计场景中找到的最大平面的平面系数
#include <pcl/sample_consensus/model_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/segmentation/sac_segmentation.h>
...
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::fromROSMsg (*input, cloud);
pcl::ModelCoefficients coefficients;
pcl::PointIndices inliers;
pcl::SACSegmentation<pcl::PointXYZ> seg;
seg.setOptimizeCoefficients (true);
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (0.01);
seg.setInputCloud (cloud.makeShared ());
seg.segment (inliers, coefficients);
pcl_msgs::ModelCoefficients ros_coefficients;
pcl_conversions::fromPCL(coefficients, ros_coefficients);
pub.publish (ros_coefficients);
}
更多信息参考
延伸阅读
传感器配置
设备绑定串口名称 Ubuntu
Xsens MTi传感器 ROS下配置
SBG Ellipse系列传感器Ubuntu下进行ROS节点配置
Nooploop UWB LinkTrack ROS下配置
MTI Ellipse VLP16 LinkTrack Topic msg整理
节点程序分析
Xsens ROS 节点 时间戳以及话题
Velodyne ROS 节点 时间戳以及话题
SBG ROS 节点 时间戳 话题
NoopLoop ROS 节点 时间戳以及话题
经典SLAM
GMapping安装与配置
Hector SLAM 安装与配置
Gmapping 原理之目标分布与提议分布
LOAM SLAM安装与配置
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)