[Documentation] [TitleIndex] [WordIndex

(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Annotating image through action interface

Description: The tutorial walks through the process of launching ROS action to annotate images and creating a simple client that sends images for annotation.

Keywords: action, mturk, image

Tutorial Level: INTERMEDIATE

Prerequisites

Linking remote topics

The system has two loosely coupled parts: web server and the client host: annotate_image_action_client.png

Each host has its own ROS core and the cores don't communicate directly. The web server publishes all annotations on /django_crowd_server/annotation topic. As there will be one publisher for each web server process, we relay all annotation messages on the server side to the single topic /external/annotation .

The client doesn't have any knowledge about the remote topic publishers. To be able to listen to these, we need to link the remote topic into the local core. To do so, we launch a link_topic node:

 <node pkg="mech_turk_ros" type="link_topic.py" name="link_topic">
        <param name="server" value="default"/>
        <param name="remote_topic_name" value="/external/annotation"/>
 </node>

Running action server

The action server needs to know only server name, server session and the annotation topic that the server will use:

  <node pkg="mech_turk_ros" type="annotate_image_action_server.py" name="annota\
te_image_action" output="screen">
        <param name="annotation_topic" value="/external/annotation"/>
        <param name="server" value="default"/>
        <param name="session" value="my-first-session"/>
  </node>

Once we launch the action server, we can send goals to it and check on the goal status. When the annotation arrives from the server, the goal will succeed.

Note: The images are identified via the header time stamp. The time stamps must be filled non-zero.

Sending and receiving goals

The action interface is very easy to use. All we need is to create an action_client (don't use simple_action_client !) and send some images:

   1 client = ActionClient("annotate_image_action",AnnotateImageAction);
   2 image  = cv.LoadImage(image_name)
   3 image_message = CvBridge().cv_to_imgmsg(image)
   4 image_message.header.stamp=rospy.get_rostime()
   5 goal   = AnnotateImageGoal(image_message)
   6 gh     = client.send_goal(goal);

To run the complete code, go to mech_turk_ros and run "make test" to download the test data:

roscd mech_turk_ros
make test
cd test_data
tar xvzf five_images_with_people.tgz

Then launch the action node and the link topic. This code will use my-first-session session on default server. Edit the launch file to change those:

roscd mech_turk_ros/test/tutorial/
roslaunch annotate_image_action.launch 

Now we are ready to submit images:

./annotate_jpeg_images_via_action.py ../../test_data/five_images_with_people/*.jpg

You will see a stream of status messages:

[INFO] 1266865578.995343: Total goals: 5 (active: 2, succeeded: 0, aborted: 0)
[INFO] 1266865579.497386: Total goals: 5 (active: 3, succeeded: 0, aborted: 0)
[INFO] 1266865579.998994: Total goals: 5 (active: 4, succeeded: 0, aborted: 0)
[INFO] 1266865580.500433: Total goals: 5 (active: 4, succeeded: 0, aborted: 0)
[INFO] 1266865581.002143: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
[INFO] 1266865581.503550: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
[INFO] 1266865582.005283: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
[INFO] 1266865582.506859: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
[INFO] 1266865583.008502: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
[INFO] 1266865583.510212: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)

Now go to Mechanical Turk Sandbox and submit something to your HITs. As you do this, you will see the goals succeed:

[INFO] 1266865593.543404: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
......
[INFO] 1266865594.045152: Total goals: 5 (active: 5, succeeded: 0, aborted: 0)
[INFO] 1266865594.546576: Total goals: 5 (active: 4, succeeded: 1, aborted: 0)
......
[INFO] 1266865605.583602: Total goals: 5 (active: 4, succeeded: 1, aborted: 0)
[INFO] 1266865606.085143: Total goals: 5 (active: 3, succeeded: 2, aborted: 0)
........
[INFO] 1266865612.606854: Total goals: 5 (active: 3, succeeded: 2, aborted: 0)
[INFO] 1266865613.108561: Total goals: 5 (active: 2, succeeded: 3, aborted: 0)
........
[INFO] 1266865619.128123: Total goals: 5 (active: 2, succeeded: 3, aborted: 0)
[INFO] 1266865619.629856: Total goals: 5 (active: 1, succeeded: 4, aborted: 0)
........
[INFO] 1266865625.651012: Total goals: 5 (active: 1, succeeded: 4, aborted: 0)
[INFO] 1266865626.152690: Total goals: 5 (active: 0, succeeded: 5, aborted: 0)


2019-08-17 12:56