Head Display Image Example

Jump to: navigation , search

Displays a given image file or multiple files on the robot's face.

Introduction

The camera display example demonstrates how to pass image file(s) to robot head for display. The example read and convert image file(s) using cv_bridge, sending the image info to the robot head screen as a standard ROS Image Message. If you would like to follow along with the actual source code for the example on GitHub, it can be found through this link for head display image example.

Usage

Run the example as following command:

$ rosrun intera_examples head_display_image.py -f <the path to image file to send>

Arguments

Important Arguments:

-f or --file : File path for display.

-l or --loop : Display images in loop.

-r or --rate : The frequency for multiple and looped images.

usage: head_display_image.py [-h] [-f FILE [FILE ...]] [-l] [-r RATE]

RSDK Head Display Example:

    Displays a given image file or multiple files on the robot.s face.

    Pass the relative or absolute file path to an image file on your
    computer, and the example will read and convert the image using
    cv_bridge, sending it to the screen as a standard ROS Image Message.
   

optional arguments:
  -h, --help            show this help message and exit
  -l, --loop            Display images in loop, add argument will display
                        images in loop
  -r RATE, --rate RATE  Image display frequency for multiple and looped
                        images.

required arguments:
  -f FILE [FILE ...], --file FILE [FILE ...]
                        Path to image file to send. Multiple files are
                        separated by a space, eg.: a.png b.png

Notes:
    Max screen resolution is 1024x600.
    Images are always aligned to the top-left corner.
    Image formats are those supported by OpenCv - LoadImage().

Code Walkthrough

Now, let's break down the code.

  1. import intera_interface
  2. import argparse
  3. import rospy

This imports the intera interface for accessing the HeadDisplay class.

  1. def main():
  2.     """RSDK Head Display Example:
  3.    Displays a given image file or multiple files on the robot's face.
  4.    Pass the relative or absolute file path to an image file on your
  5.    computer, and the example will read and convert the image using
  6.    cv_bridge, sending it to the screen as a standard ROS Image Message.
  7.    """
  8.     epilog = """
  9. Notes:
  10.    Max screen resolution is 1024x600.
  11.    Images are always aligned to the top-left corner.
  12.    Image formats are those supported by OpenCv - LoadImage().
  13.    """
  14.     arg_fmt = argparse.RawDescriptionHelpFormatter
  15.     parser = argparse.ArgumentParser(formatter_class=arg_fmt,
  16.                                      description=main.__doc__,
  17.                                      epilog=epilog)
  18.     required = parser.add_argument_group('required arguments')
  19.     required.add_argument(
  20.         '-f', '--file', nargs='+',
  21.         help='Path to image file to send. Multiple files are separated by a space, eg.: a.png b.png'
  22.     )
  23.     parser.add_argument(
  24.         '-l', '--loop', action="store_true",
  25.         help='Display images in loop, add argument will display images in loop'
  26.     )
  27.     parser.add_argument(
  28.         '-r', '--rate', type=float, default=1.0,
  29.         help='Image display frequency for multiple and looped images'
  30.     )
  31.     args = parser.parse_args()

Arguments for head image display, the image file(s) is a required argument, loop and rate are optional.

  1.     rospy.init_node("head_display_example", anonymous=True)
  2.  
  3.     head_display = intera_interface.HeadDisplay()
  4.     head_display.display_image(args.file, args.loop, args.rate)
  5.  
  6. if __name__ == '__main__':
  7.     main()

The node is initialized and an instance of the HeadDisplay class is created. Call display_image function by passing in arguments. Press Ctrl-C to quit the example.