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.

30 import intera_interface
31 import argparse
32 import rospy

This imports the intera interface for accessing the HeadDisplay class.

34 def main():
35     """RSDK Head Display Example:
36     Displays a given image file or multiple files on the robot's face.
37     Pass the relative or absolute file path to an image file on your
38     computer, and the example will read and convert the image using
39     cv_bridge, sending it to the screen as a standard ROS Image Message.
40     """
41     epilog = """
42 Notes:
43     Max screen resolution is 1024x600.
44     Images are always aligned to the top-left corner.
45     Image formats are those supported by OpenCv - LoadImage().
46     """
47     arg_fmt = argparse.RawDescriptionHelpFormatter
48     parser = argparse.ArgumentParser(formatter_class=arg_fmt,
49                                      description=main.__doc__,
50                                      epilog=epilog)
51     required = parser.add_argument_group('required arguments')
52     required.add_argument(
53         '-f', '--file', nargs='+',
54         help='Path to image file to send. Multiple files are separated by a space, eg.: a.png b.png'
55     )
56     parser.add_argument(
57         '-l', '--loop', action="store_true",
58         help='Display images in loop, add argument will display images in loop'
59     )
60     parser.add_argument(
61         '-r', '--rate', type=float, default=1.0,
62         help='Image display frequency for multiple and looped images'
63     )
64     args = parser.parse_args()

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

68     rospy.init_node("head_display_example", anonymous=True)
69 
70     head_display = intera_interface.HeadDisplay()
71     head_display.display_image(args.file, args.loop, args.rate)
72 
73 if __name__ == '__main__':
74     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.