博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在ROS中使用PCL(2)
阅读量:7137 次
发布时间:2019-06-28

本文共 3417 字,大约阅读时间需要 11 分钟。

记录关于我们运行roslaunch openni_launch openni.launch  命令时生成的话题以及这些话题的数据类型便于后期的处理,只有知道它们的数据结构,才能很好的对数据进行处理,我们观察到使用rostopic list的所有话题的列表,当然其中也有一些不经常使用的话题类型,比如下面这些话题是我们经常使用的

/camera/depth/image
/camera/depth/image_raw
/camera/depth/points
/camera/ir/image_raw
/camera/rgb/image_color
/camera/rgb/image_raw

发布的话题:

image_raw () : 未处理的原始图像

使用命令查看sensor_msgs/Image的数据

camera_info ():包含了相机标定配置以及相关数据

 

介绍几个ROS节点运行的几种工具。他们的作用是ROS格式点云或包与点云数据(PCD)文件格式之间的相互转换。

(1)bag_to_pcd

用法:rosrun pcl_ros bag_to_pcd <input_file.bag> <topic> <output_directory>

读取一个包文件,保存所有ROS点云消息在指定的PCD文件中。

(2)convert_pcd_to_image

用法:rosrun pcl_ros convert_pcd_to_image <cloud.pcd>

加载一个PCD文件,将其作为ROS图像消息每秒中发布五次。

(3) convert_pointcloud_to_image

用法:rosrun pcl_ros convert_pointcloud_to_image input:=/my_cloud output:=/my_image

 查看图像:rosrun image_view image_view image:=/my_image

订阅一个ROS的点云的话题并以图像的信息发布出去。

(4)pcd_to_pointcloud

用法:rosrun pcl_ros pcd_to_pointcloud <file.pcd> [ <interval> ]

  • <file.pcd> is the (required) file name to read.

  • <interval> is the (optional) number of seconds to sleep between messages. If <interval> is zero or not specified the message is published once.

加载一个PCD文件,发布一次或多次作为ROS点云消息

(5)pointcloud_to_pcd

例如: rosrun pcl_ros pointcloud_to_pcd input:=/velodyne/pointcloud2

订阅一个ROS的话题和保存为点云PCD文件。每个消息被保存到一个单独的文件,名称是由一个可自定义的前缀参数,ROS时间的消息,和以PCD扩展的文件。

那么我们使用一个简单的例子来实现在ROS中进行平面的分割,同时注意到使用的数据转换的使用

/**************************************************************************关于使用pcl/PointCloud
的举例应用。这一类型的数据格式是PCL库中定义的一种数据格式这里面使用了两次数据转换从 sensor_msgs/PointCloud2 到 pcl/PointCloud
和 从 pcl::ModelCoefficients 到 pcl_msgs::ModelCoefficients.************************************************************************/#include
//ROS#include
// PCL specific includes#include
#include
#include
#include
#include
#include
//关于平面分割的头文件#include
//分割模型的头文件#include
//采样一致性的方法#include
//ransac分割法ros::Publisher pub;void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input){ // 将点云格式为sensor_msgs/PointCloud2 格式转为 pcl/PointCloud pcl::PointCloud
cloud; pcl::fromROSMsg (*input, cloud); //关键的一句数据的转换 pcl::ModelCoefficients coefficients; //申明模型的参数 pcl::PointIndices inliers; //申明存储模型的内点的索引 // 创建一个分割方法 pcl::SACSegmentation
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); //cloud.makeShared() 创建一个 boost shared_ptr // pcl_msgs::fromROSMsg(const sensor_msgs::PointCloud2 &, pcl::PointCloud
&); //pcl::io::savePCDFileASCII("test_pcd.pcd",cloud); // 把提取出来的内点形成的平面模型的参数发布出去 pcl_msgs::ModelCoefficients ros_coefficients; pcl_conversions::fromPCL(coefficients, ros_coefficients); pub.publish (ros_coefficients);}intmain (int argc, char** argv){ // Initialize ROS ros::init (argc, argv, "my_pcl_tutorial"); ros::NodeHandle nh; // Create a ROS subscriber for the input point cloud ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb); // Create a ROS publisher for the output model coefficients pub = nh.advertise
("output", 1); // Spin ros::spin ();}

在这里我们的input就是要订阅的话题/camera/depth/points

我们在rosrun 的时候注明input:=/camera/depth/points的这样就可以使用kienct发布的点云数据,同时你也可以指定点云的数据

 

转载地址:http://intrl.baihongyu.com/

你可能感兴趣的文章
ASP.NET中页面传值
查看>>
Flex4中动态生成RadioButton,绑定数据源
查看>>
开源CMS大PK:WordPress vs Drupal vs Joomla ,谁更强大更好用
查看>>
HDU-1004 Let the Balloon Rise STL map
查看>>
单片机低功耗设计杂谈
查看>>
Ubuntu上怎么安装Eclipse Android 开发环境
查看>>
转载:解答Google的一道面试题
查看>>
在 ASP.NET 页面中使用 TreeView 控件
查看>>
走进单元测试二:测试需要从哪些方面着手
查看>>
著名编程语录
查看>>
后台修改,订单锁定
查看>>
CentOS 5.4 安裝 boost 1.4.1 筆記 - 杨毅的电子笔记
查看>>
工欲善其事,必先利其器:分享一套Code Smith 搭建N层架构模板
查看>>
几何变换详解
查看>>
Cocoa设计模式之KVC
查看>>
POJ 2063 Investment(完全背包)
查看>>
netmon工作原理
查看>>
通过python的import hooks实现像引用代码一样使用配置文件
查看>>
Google Code在Windows下面设置.netrc
查看>>
Oracle笔记(4):一个存储过程编写及C#调用
查看>>