rosbag文件中提取图像--分别通过cam/image_raw和cam/image_raw/compressed方话题
来源:互联网 发布:拍摄淘宝静物打灯图解 编辑:程序博客网 时间:2024/06/03 18:19
1、通过cam/image_raw话题
创建launch文件,如下:
export.launch
<launch> <node pkg="rosbag" type="play" name="rosbag" args="-d 2 $(find image_view)/test.bag"/> <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME"> <remap from="image" to="/camera/image_raw"/> </node> </launch>将$(find image_view)/test.bag改为你自己的bag文件路径。
然后,运行launch文件。
roscore打开一个终端,cd到export.launch所在路径下,运行roslaunch export.launch所提取的图片在
~/.ros
路径下,将其移到你的目标文件中,如:cd ~mkdir Examplemv ~/.ros/*.jpg ~/Example
2、通过cam/image_raw/compressed话题
首先写一个test1.cpp节点
#include <ros/ros.h>#include <opencv2/highgui/highgui.hpp>#include <cv_bridge/cv_bridge.h>#include <cv_bridge/cv_bridge.h>#include <cv.h>#include <highgui.h>#include "cxcore.hpp"#include <stdio.h>#include <stdlib.h>#include <string>#include <sstream>using namespace std; long temptime=0; char base_name[256]; string str;void imageCallback(const sensor_msgs::CompressedImageConstPtr& msg){ try { cv::Mat image = cv::imdecode(cv::Mat(msg->data),1);//convert compressed image data to cv::Mat //sprintf(base_name,"%4ld.jpg",temptime); sprintf(base_name,"/home/wf/bagfiles/camera1/%4ld.jpg",temptime); //str //str="/home/wf/bagfiles/camera1/"+base_name; cv::imwrite(base_name,image); cv::imshow("view", image); temptime++; cv::waitKey(10); } catch (cv_bridge::Exception& e) { ROS_ERROR("Could not convert to image!"); }}int main(int argc, char **argv){ ros::init(argc, argv, "image_listener"); ros::NodeHandle nh; cv::namedWindow("view"); cv::startWindowThread(); ros::Subscriber sub = nh.subscribe("/camera1/image_raw/compressed", 1, imageCallback); ros::spin(); cv::destroyWindow("view");}
然后在cmakelists.txt中加入下面的3行:
add_executable(test1 src/test1.cpp)target_link_libraries(test1 ${catkin_LIBRARIES} ${OPENCV_LIBS})add_dependencies(test1 beginner_tutorials_generate_messages_cpp)之后,把上述代码当做一个节点运行就可以了
参考:https://answers.ros.org/question/230476/how-to-subscribe-to-sensor_msgscompressedimage-without-the-raw-image/
阅读全文
1 0
- rosbag文件中提取图像--分别通过cam/image_raw和cam/image_raw/compressed方话题
- CAM
- ROS-从rosbag中提取图像(by launch文件)
- UG和CAM编程
- ROS-从rosbag中提取图像(带时间戳)
- CAM软件
- ASCII Cam
- CAM表
- IP cam 与模拟cam
- PADS中CAM输出的相关设置
- 在roslaunch中通过rosbag运行bag文件
- CAM::DBF and Date::Simple 创建DBF文件
- CAM 与数控编程
- 专业CAD/CAM软件
- CAM存储器概述
- cam 知识点搜索
- usb CAM 调试
- CAM-CRP-1064
- 入门级:GitHub和Git详细使用教程!
- 结构化数据 和 非结构化数据
- Java 8 特性 – 终极手册
- 设计模式-工厂模式
- Set,List集合及其子类/泛型/增强for循环
- rosbag文件中提取图像--分别通过cam/image_raw和cam/image_raw/compressed方话题
- 三角形与星号加强版
- 剑指offer[三]:从尾到头打印链表(java和c++版本)
- IDEA Activiti Designer插件---actiBPM汉字乱码问题
- Matplotlib for Python Developers
- android Cannot resolve symbol'R'
- 斐波那契数列
- Nginx+Tomcat+memcached负载均衡实现session共享
- 基于Unity3D的相机震动效果的实现