ROS 订阅图像节点(1)
博客
http://blog.csdn.net/github_30605157/article/details/50990493
参考ROS原网站
http://wiki.ros.org/image_transport/Tutorials
ROS:两个节点同时具有发布和订阅图像信息的功能
http://blog.csdn.net/ding977921830/article/details/70168877
发射结点 my_publisher
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h> int main(int argc, char** argv)
{
ros::init(argc, argv, "image_publisher");
ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Publisher pub = it.advertise("camera/image", 1); cv::Mat image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg(); ros::Rate loop_rate(5);
while (nh.ok()) {
pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
}
接收节点 my_subscriber
接受完要等待一下
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h> //cv::Mat image;
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
try
{
// image = cv_bridge::toCvShare(msg, "bgr8")->image;
// cv::imshow("view", image);
// cvWaitKey(1);
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
cvWaitKey(1); }
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
} int main(int argc, char **argv)
{
ros::init(argc, argv, "image_listener");
ros::NodeHandle nh;
cv::namedWindow("view", 0);
cv::startWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback); ros::spin();
cv::destroyWindow("view");
}
camke.list
cmake_minimum_required(VERSION 2.8.3)
project(my_image_transport) find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
OpenCV
) catkin_package(
# INCLUDE_DIRS include
# LIBRARIES my_image_transport
CATKIN_DEPENDS cv_bridge image_transport
# DEPENDS system_lib
) include_directories(
# include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
) #build my_publisher and my_subscriber
add_executable(my_publisher src/my_publisher.cpp)
target_link_libraries(my_publisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}) add_executable(my_subscriber src/my_subscriber.cpp)
target_link_libraries(my_subscriber ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
package。xml
<?xml version="1.0"?>
<package format="2">
<name>my_image_transport</name>
<version>0.0.0</version>
<description>The my_image_transport package</description> <!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="drone@todo.todo">drone</maintainer> <!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>TODO</license> <!-- Url tags are optional, but multiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/my_image_transport</url> --> <!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> --> <!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
<!-- <depend>roscpp</depend> -->
<!-- Note that this is equivalent to the following: -->
<!-- <build_depend>roscpp</build_depend> -->
<!-- <exec_depend>roscpp</exec_depend> -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use build_export_depend for packages you need in order to build against this package: -->
<!-- <build_export_depend>message_generation</build_export_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use exec_depend for packages you need at runtime: -->
<!-- <exec_depend>message_runtime</exec_depend> -->
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<!-- Use doc_depend for packages you need only for building documentation: -->
<!-- <doc_depend>doxygen</doc_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>image_transport</build_depend>
<build_export_depend>cv_bridge</build_export_depend>
<build_export_depend>image_transport</build_export_depend>
<build_depend>opencv2</build_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>image_transport</exec_depend> <!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here --> </export>
</package>
测试命令
发射
rosrun my_image_ansport my_publisher 2.png
接受
rosrun my_image_transport my_subscriber
http://www.cvlibs.net/datasets/kitti/eval_odometry.php
ROS 订阅图像节点(1)的更多相关文章
- ROS 订阅图像节点
博客 http://blog.csdn.net/github_30605157/article/details/50990493 参考ROS原网站 http://wiki.ros.org/image_ ...
- 【ROS系列】使用QT编写ROS订阅、发布程序
Linux下一直使用QT进行开发,支持cmake使得很容易导入其他工程.学习ROS过程中,很多函数名称难记,使用QT不仅可以提示补全,还为了以后开发GUI方便吧. 1.安装ros_qtc_plugin ...
- 用C++编写发布器和订阅器节点
1.转移到之前教程在catkin工作空间所创建的package路径下: $ roscd package_name/ 例子:$ roscd practice/2.在package路径下创建src目录: ...
- remap——ROS中修改订阅的节点名称
跑数据集或者使用不同传感器时,难免会遇到需要修改topic名称的时候,此时可以有两种做法. 一.直接修改源码.如果有launch文件,则修改launch文件对应的topic 二.直接进行remap操作 ...
- Python写ROS 订阅与发布程序
1. 编写talker代码 vim ..../src/talker.py #!/usr/bin/env python # license removed for brevity import rosp ...
- python ros 订阅imu数据,实时显示欧拉角
#!/usr/bin/env python # -*- coding: utf- -*- import rospy import math from sensor_msgs.msg import Im ...
- ROS分布式控制的节点配置
首先在终端中输入下面的指令查看ROS主节点主机的IP和远程控制端的IP: ifconfig 比如机器人控制器中运行着ROS主节点,其IP地址为192.168.1.111,hostname为xubunt ...
- ros中关于节点、话题、服务以及自定义消息等在终端中的常用命令
以下面的计算力图说明 节点相关常用命令 在终端中查看项目中有哪些节点命令:rosnode list 有了节点信息想要查看节点中到底发布订阅了哪些话题,作为服务端服务类型或者作为客户端需要的服务类型以上 ...
- python ros 订阅robot_pose获取机器人位置
#!/usr/bin/env python import rospy import tf from tf.transformations import * from std_msgs.msg impo ...
随机推荐
- python取余
a=-7,b=3, a % b = 2 #取余 a-((a/b)*b) a / b= -3 #整除 int(math.floor(-7/3.0))
- 安装Eclipse时遇到”java was started but returned exit code = 13“如何解决?
有的时候运行开发工具时会出现java was started but returned exit code = 13......的提示,绝大多数的问题都是版本问题: 我们可以打开命令行工具cmd 输入 ...
- TCP/IP 详解
分层 每一层负责不同的功能: 链路层 有时也称作数据链路层或网络接口层, 通常包括操作系统中的设备驱动程序和计算机 中对应的网络接口卡.它们一起处理与电缆(或其他任何传输媒介)的物理接口细节. ...
- MVC 【Razor 视图引擎】基础操作 --页面跳转,传值,表单提交
ASPX 与 Razor 仅仅是视图不一样. 新建项目----ASP.NET MVC 4 Web 应用程序------选择模板(空).视图引擎(Razor ) 1.视图中 c# 代码 与 HT ...
- mysql百万的数据快速创建索引
测试数据本机一张表users有100百万条记录.在创建此表前没有未相应字段添加索引,所以此时需要为表添加索引.但是因为数据量大的原因,索引添加可能不成功,想了很多办法,终于挖坑成功. 开始准备工作, ...
- 使用git连接本地和远程github
使用git连接本地和远程github 网上很多github的流程比较乱,自己尝试整理了一下,主要是步骤较为清晰,如果有不清楚的可详细进行搜索对比 1. 申请和设置github https://gith ...
- js 将内容复制到剪切板上
clipboard是将内容复制到电脑的剪切板上,要引入clipboard.js //将'data-clipboard-text' 样式添加到指定的元素上 $("#effects") ...
- 商业智能BI-基础理论知识总结 ZT
因为要加入一个BI项目,所以最近在研究BI相关的知识体系,由于这个方面的知识都是比较零散,开始都很多概念,不知道从何入手,网上找的资料也不多,特别是实战案例方面更少,这里还是先把理论知识理解下吧,分享 ...
- SoapUI SoapUI测试WebService协议接口简介
SoapUI测试WebService协议接口简介 by:授客 QQ:1033553122 1. 创建项目,入口:File -> New SOAP Project,或者右键默认项目Project- ...
- android.support不统一的问题
今天supprt28遇到的问题,由于28还是预览版,还存在一些bug 都是因为如果程序内出现不同的,support或者其他外部引用库的多个版本,Gradle在进行合并的时候会使用本地持有的,最高版本的 ...