Fork me on GitHub

ros之bag中提取image和pcd

前言

This tutorial requires that you have previously recorded a bag file which contains image data you would like to export as jpeg img or video. Additionally, this tutorial requires that the image_view package has been built and a few video utilities are installed:

roscd image_view
rosmake image_view
sudo apt-get install mjpegtools

This will install the necessary tools to complete the tutorial. The rest of this tutorial will assume that you have a .bag file previously created that is named test.bag and that this bag file is stored in the image_view package directory.

提取image

  • 使用rosbag来播放rosbag
  • 使用image_transport来解压缩图像
  • 使用image_view来提取图像
<launch>
  <!-- play rosbag -->
  <arg name="bag_path" default="/home/liuzhiyang/data" />
  <node pkg="rosbag" type="play" name="rosbag" required="true" output="screen" args="$(arg bag_path)/gyy.bag"/>

  <!-- if image is compressed -->
  <arg name="image_topic" default="/camera_front/image_color" />
  <node pkg="image_transport" type="republish" name="decompress" output="screen" args="compressed in:=$(arg image_topic) raw out:=$(arg image_topic)" />

  <!-- extract img -->
  <node pkg="image_view" type="extract_img" name="extract" respawn="false" required="true" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera_front/image_color"/>
  </node>

</launch>

生成的图像的位置是在~/.ros/下, 因此使用mv移动

cd data/
mkdir img
mv ~/.ros/frame*.jpg img/

生成视频

  • 生成yuv格式
cd ~/test
jpeg2yuv -I p -f 15 -j frame%04d.jpg -b 1 > tmp.yuv
ffmpeg2theora --optimize --videoquality 10 --videobitrate 16778 -o output.ogv tmp.yuv
  • 生成mpeg格式
cd ~/test
mencoder "mf://*.jpg" -mf type=jpg:fps=15 -o output.mpg -speed 1 -ofps 30 -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=2500 -oac copy -of mpeg
  • 生成mp4格式
cd ~/test
ffmpeg -framerate 25 -i frame%04d.jpg -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4

提取pcd

  • usage:
rosrun pcl_ros bag_to_pcd <input_file.bag> <topic> <output_directory>
  • example:
rosrun pcl_ros bag_to_pcd data.bag /laser_tilt_cloud ./pointclouds

参考

posted @ 2021-06-26 15:13  chrislzy  阅读(662)  评论(0编辑  收藏  举报