记录关于我们运行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) : 未处理的原始图像

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

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

介绍几个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<T>的举例应用。这一类型的数据格式是PCL库中定义的一种数据格式
这里面使用了两次数据转换从 sensor_msgs/PointCloud2 到 pcl/PointCloud<T> 和
从 pcl::ModelCoefficients 到 pcl_msgs::ModelCoefficients.
************************************************************************/
#include <iostream>
//ROS
#include <ros/ros.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h> #include <pcl/io/pcd_io.h> //关于平面分割的头文件
#include <pcl/sample_consensus/model_types.h> //分割模型的头文件
#include <pcl/sample_consensus/method_types.h> //采样一致性的方法
#include <pcl/segmentation/sac_segmentation.h> //ransac分割法 ros::Publisher pub; void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
// 将点云格式为sensor_msgs/PointCloud2 格式转为 pcl/PointCloud
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); //cloud.makeShared() 创建一个 boost shared_ptr // pcl_msgs::fromROSMsg(const sensor_msgs::PointCloud2 &, pcl::PointCloud<T>&);
//pcl::io::savePCDFileASCII("test_pcd.pcd",cloud); // 把提取出来的内点形成的平面模型的参数发布出去
pcl_msgs::ModelCoefficients ros_coefficients;
pcl_conversions::fromPCL(coefficients, ros_coefficients);
pub.publish (ros_coefficients);
} int
main (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", , cloud_cb); // Create a ROS publisher for the output model coefficients
pub = nh.advertise<pcl_msgs::ModelCoefficients> ("output", ); // Spin
ros::spin ();
}

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

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

最新文章

  1. React 组件性能优化探索实践
  2. Auty自动化测试框架第三篇——添加异常处理与日志收集
  3. js事件处理机制
  4. Apk去签名校验详解
  5. linux下log4j乱码解决
  6. 常见Android测试工具简介
  7. 28、activity之间传递数据&amp;批量传递数据
  8. C#数据类型转换的几种形式
  9. 在Debian Wheezy 7.3.0上编译安装3.12.14内核
  10. c++中&amp;amp;和&amp;amp;&amp;amp;有什么差别
  11. Xcode 下删除Provisioning Profiles文件
  12. Spring AOP 切点(pointcut)表达式
  13. gunicorn启动flask项目的坑
  14. Vim 安装、配置及复制粘贴操作
  15. Linux上web服务器搭建
  16. 【BZOJ4773】负环 [SPFA][二分]
  17. springboot-day01-引入基础
  18. Error:java: 无效的源发行版: 1.8
  19. objelement = event.target || event.srcElement;
  20. JavaScript 闭包(Closure)

热门文章

  1. django后台使用MySQL情况下的事务控制详解
  2. django -- 对模式进行调式(pay with the api)
  3. 微信小程序 confirm(删除提示)提示框,询问框,小程序操作成功提示后跳转
  4. Java数据结构和算法(五):队列
  5. 开始学习使用 Semantic UI
  6. [LeetCode] Paint House I &amp; II
  7. Cocos2d-x 源代码分析 : Scheduler(定时器) 源代码分析
  8. Eclipse Axis2 插件将代码生成WSDL指南
  9. tensorflow笔记3:CRF函数:tf.contrib.crf.crf_log_likelihood()
  10. node的http请求