Publish static image topic

Introduction

You may need image topics to try recognition nodes/nodelets in jsk_perception, and this tutorial shows how to create image topic easily.

Step by step

For this purpose, you can use image_publisher.py.

terminal 1:

$ roscore

terminal 2:

$ rosrun jsk_perception image_publisher.py \
  _file_name:=$(rospack find jsk_perception)/sample/kiva_pod_image_color.jpg _rate:=30

_file_name:=... and _rate:=... is remapping of rosparam and you can get the value with:

$ rosparam get /image_publisher/file_name
/home/wkentaro/Projects/jsk/src/jsk-ros-pkg/jsk_recognition/jsk_perception/sample/kiva_pod_image_color.jpg

$ rosparam get /image_publisher/rate
30

The image is published to topic /image_publisher/output, so you can see it by:

$ rosrun image_view image_view image:=/image_publisher/output

image:=... is remaping of topic, and the image_view will subscribe /image_publisher/output in this case.

The result is as shown below:

../_images/sample_image_publisher.jpg

A single command

You can run upper programs in a single command with writing roslaunch file:

$ # emacs tutorial_image_publisher.launch
$ vim tutorial_image_publisher.launch

Or you can download the file from:

<launch>
  <node name="image_publisher"
        pkg="jsk_perception" type="image_publisher.py">
    <!--
    <param name="file_name" value="$(find jsk_perception)/sample/kiva_pod_image_color.jpg" type="str" />
    <param name="rate" value="30" type="int" />
    Below also works.
    See http://wiki.ros.org/roslaunch/XML/param and http://wiki.ros.org/roslaunch/XML/rosparam for detail.
    -->
    <rosparam subst_value="true">
      file_name: $(find jsk_perception)/sample/kiva_pod_image_color.jpg
      rate: 30
    </rosparam>
  </node>
  <node name="image_view"
        pkg="image_view" type="image_view">
    <!--
    <remap from="image" to="/image_publisher/output" />
    Below works because image_publisher and image_view is in the same namespace.
    See http://wiki.ros.org/roslaunch/Tutorials/Roslaunch%20tips%20for%20larger%20projects for detail.
    -->
    <remap from="image" to="image_publisher/output" />
  </node>
</launch>

You can launch the roslaunch file by:

$ roslaunch ./tutorial_image_publisher.launch