ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Save images as 8-bit grayscale in image_view extract from rosbag file

asked 2014-07-30 04:51:40 -0600

mister_kay gravatar image

Hello,

I use a launch-file in order to extract images from a stereo-camera (stereo/left & stereo/right). Thereby I use the package "image_view" with the node "extract" to grab the images from my bagfile.

<launch>
   <arg name="path" default="/home/viki/bagfiles" />
   <arg name="bagfile" default="bagfile_stereo_raw.bag" />
   <arg name="folder_name" default="default_image_folder" />
   <arg name="format" default="png" />

   <param name="/use_sim_time" value="true" />

   <node name="rosbag" pkg="rosbag" type="play" 
      args="--clock -d 4 $(arg path)/$(arg bagfile)" />


   <node name="extract1" pkg="image_view"   type="extract_images" respawn="false" output="screen"                 cwd="ROS_HOME" >
   <remap from="image" to="/stereo/left/image_rect" />
   <param name="filename_format" value="/stereo_images/$(arg folder_name)/left/left_image%04i.$(arg                  format)"/>
   </node>

   <node name="extract2" pkg="image_view" type="extract_images"  respawn="false" output="screen"                  cwd="ROS_HOME" >
   <remap from="image" to="/stereo/left/image_rect" />
   <param name="filename_format" value="/stereo_images/$(arg folder_name)/right/right_image%04i.$(arg                  format)"/>
   </node>

</launch

I now receive all the desired images but they are 24-bit images. Now my question is: How can I setup the launch-file in order to receive 8-bit (grayscale) images? I cannot find any documentation regarding this. Also my question is how to obtain parameters from nodes like "extract" in ROS in general. I found out that there is a parameter called "file_format" for "extract" in the ROS answer sites but how can I see all the different parameters there are for this node. (I am sure my question would resolve by acquiring this info).

Also one other question: I need to create the directories before saving the images (with the launch file) into them. Is there a way that the roslaunch file creates the desired directories by itself?

Thanks in advance! Hector

edit retag flag offensive close merge delete

Comments

I believe your question about creating directories has been asked and answered elsewhere. ( http://answers.ros.org/question/188298/how-to-create-directories-in-a-ros-launch-file/ )

ahendrix gravatar image ahendrix  ( 2014-07-30 12:58:11 -0600 )edit

image_proc should be able to create mono images from color images, but it looks like you're already subscribing to a mono topic. Are the saved images color or monochrome when viewed?

ahendrix gravatar image ahendrix  ( 2014-07-30 13:02:01 -0600 )edit

There isn't any documentation of the extract_images node on the image_view wiki page. Perhaps you can write it once you've figured out all of the details?

ahendrix gravatar image ahendrix  ( 2014-07-30 13:02:57 -0600 )edit

@ahendrix yes i can do that. unfortunately I couldn't find the site where ic an edit the documentaion for extract_images. can you give me a link for a tutorial how to create this docu?

mister_kay gravatar image mister_kay  ( 2014-08-22 10:02:09 -0600 )edit

The wiki page for image_view is http://wiki.ros.org/image_view , and you can sign up for an account here

ahendrix gravatar image ahendrix  ( 2014-08-22 11:06:29 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-08-22 09:42:21 -0600

mister_kay gravatar image

updated 2014-08-22 09:47:20 -0600

The hacky version is to edit the source code in the image_view package named extract_view.cpp [line 105]:

orginal:

image = cv_bridge::toCvShare(msg, "bgr8")->image;

edited:

image = cv_bridge::toCvShare(msg, "mono8")->image;

This way only 8bit grayscale images are extracted. (that was on of the things I wanted.) Of course i had to "catkin_make" my catkin_workspace first before this works!

I think it would be a good idea to add a parameter which makes it possible for every user to extract the images in her/his desired fileformat, e.g.

ros::NodeHandle nh("~");
string the_format;
const string default_format = "bgr8";

nh.param<std::string>("file_format", the_format, default_format);
....
image = cv_bridge::toCvShare(msg, the_format)->image;

I am not that good with GitHub, otherwise I would send a pull request to the creator of image_view.

edit flag offensive delete link more

Comments

Never too early/late to learn! - open an issue in the repository - fork the repo directly in the Github gui - clone your fork, make/test your changes - commit your changes, referencing the issue in the comment - make a pull request through the Github gui to 'pull' your changes to the repo

paulbovbel gravatar image paulbovbel  ( 2014-08-22 09:52:22 -0600 )edit

Question Tools

Stats

Asked: 2014-07-30 04:51:40 -0600

Seen: 2,189 times

Last updated: Aug 22 '14