您的位置:首页 > 其它

ROS-从rosbag中提取图像(by launch文件)

2017-07-07 13:56 841 查看
从rosbag文件中,提取图像并保存。

新建export.launch :

<launch>
<node pkg="rosbag" type="play" name="rosbag" args="-d 2 /home/lcl/bagfiles/camera.bag"/>
<node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
<remap from="image" to="camera/rgb/image_color"/>
</node>
</launch>


注:

换 args=”-d 2 $(find image_view)/test.bag 为 输入其绝对路径 解决 find 不到的问题;

运行export.launch文件:

roslaunch   export.launch


将生成的图像 移动到 test 文件夹下

1  cd ~
2 mkdir test
3 mv ~/.ros/frame*.jpg test/


这样在文件夹中便可看到提取的图像。

其中,测试中遇到的问题

该launch 提取了149张图像,而rosbag info camera.bag 显示 [ 235/235chunks]

如图:



搜索原因在于提取的时间间隔,目前默认的是0.1,

You can try to change the “sec_per_frame” parameter of image_extract. It is set to 0.1 by default, and if you are capturing images with 30 fps, you would get 1/3 of the frames, which is close to what you are getting. Try setting it to 0.03.具体参考

Example launch file:

<launch>
<node pkg="rosbag" type="play" name="rosbag" args="-d 2 $(find image_export)/input/file.bag"/>
<node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
<remap from="image" to="[YOUR_TOPIC_NAME]"/>
<param name="sec_per_frame" value="0.03"/>
</node></launch>


主要是添加
<param name="sec_per_frame" value="0.03"/>


重新运行,得到233张,接近bag文件的255.



如果想要改变图像名称,在launch添加下列语句即可。

<param name="file_format" value="frame%05d.jpg"/>


参考:1.ros.wiki:http://wiki.ros.org/rosbag/Tutorials/Exporting%20image%20and%20video%20data
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ROS