1+ ## Image Tools Demo in Python
2+
13This is a demonstration of the Quality of Service (QoS) features of ROS 2 using Python.
2- There are two programs implemented here: cam2image_py, and showimage_py. Note that in
3- order for these programs to work, an OpenCV binding for Python3 must be available. As
4- of this writing (January 11, 2017), only OpenCV 3 or later supports Python3. Instructions
5- for compiling OpenCV3 for Python3 are available here:
6-
7- http://stackoverflow.com/questions/20953273/install-opencv-for-python-3-3
8-
9- The condensed rundown that works on Ubuntu16.04 and will install to /usr/local is:
10- $ sudo apt install python3 build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python3.5-dev libpython3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
11- $ git clone https://github.com/opencv/opencv
12- $ cd opencv
13- $ git checkout 3.2.0
14- $ mkdir release
15- $ cd release
16- $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
17- $ make -j8
18- $ sudo make install
19-
20- CAM2IMAGE_PY
21- ------------
4+ There are two programs implemented here: cam2image_py, and showimage_py.
5+
6+ ### CAM2IMAGE_PY
227This is a Python program that will take data from an attached camera, and publish the
23- data to a topic called "image", with the type sensor_msgs:: msg:: Image. If a camera
8+ data to a topic called "image", with the type sensor_msgs/ msg/ Image. If a camera
249isn't available, this program can also generate a default image and smoothly "move"
2510it across the screen, simulating motion. The usage output from the program looks like
2611this:
2712
28- usage: cam2image_py.py [-h] [-b] [-d QUEUE_DEPTH] [-f FREQUENCY] [-k {0,1}]
29- [-r {0,1}] [-s {0,1}] [-x WIDTH] [-y HEIGHT]
13+ ```
14+ usage: cam2image_py [-h] [-b] [-d DEPTH] [-f FREQUENCY] [-k {0,1}] [-r {0,1}]
15+ [-s {0,1}] [-t TOPIC] [-x WIDTH] [-y HEIGHT]
3016
3117optional arguments:
3218 -h, --help show this help message and exit
3319 -b, --burger Produce images of burgers rather than connecting to a
3420 camera (default: False)
35- -d QUEUE_DEPTH , --depth QUEUE_DEPTH
21+ -d DEPTH , --depth DEPTH
3622 Queue depth (default: 10)
3723 -f FREQUENCY, --frequency FREQUENCY
3824 Publish frequency in Hz (default: 30)
@@ -42,18 +28,22 @@ optional arguments:
4228 -r {0,1}, --reliability {0,1}
4329 Reliability QoS setting, 0 - best effort, 1 - reliable
4430 (default: 1)
31+ -t TOPIC, --topic TOPIC
32+ Topic to publish on (default: image)
33+
4534 -s {0,1}, --show {0,1}
4635 Show the camera stream (default: 0)
4736 -x WIDTH, --width WIDTH
4837 Image width (default: 320)
4938 -y HEIGHT, --height HEIGHT
5039 Image height (default: 240)
40+ ```
5141
5242The -d, -k, and -r parameters control various aspects of the QoS implementation, and
5343are the most interesting to play with when testing out QoS.
5444
5545Note that this program also subscribes to a topic called "flip_image" of type
56- std_msgs:: msg:: Bool. If flip_image is set to False, the data coming out of the camera
46+ std_msgs/ msg/ Bool. If flip_image is set to False, the data coming out of the camera
5747is sent as usual. If flip_image is set to True, the data coming out of the camera is
5848flipped around the Y axis.
5949
@@ -63,13 +53,13 @@ the ROS 2 pub/sub model, so this window cannot show off the QoS parameters (it i
6353useful for debugging). See SHOWIMAGE_PY below for a program that can show QoS over the
6454pub/sub model.
6555
66- SHOWIMAGE_PY
67- ------------
56+ ### SHOWIMAGE_PY
6857This is a Python program that subscribes to the "image" topic, waiting for data. As
6958new data comes in, this program accepts the data and can optionally render it to
7059the screen. The usage output from the program looks like this:
7160
72- usage: showimage_py.py [-h] [-d QUEUE_DEPTH] [-k {0,1}] [-r {0,1}] [-s {0,1}]
61+ usage: showimage_py [ -h] [ -d QUEUE_DEPTH] [ -k {0,1}] [ -r {0,1}] [ -s {0,1}]
62+ [ -t TOPIC]
7363
7464optional arguments:
7565 -h, --help show this help message and exit
@@ -82,28 +72,35 @@ optional arguments:
8272 Reliability QoS setting, 0 - best effort, 1 - reliable
8373 (default: 1)
8474 -s {0,1}, --show {0,1}
85- Show the camera stream (default: 0)
75+ Show the camera stream (default: 1)
76+ -t TOPIC, --topic TOPIC
77+ use topic TOPIC instead of the default (default: image)
8678
8779The -d, -k, and -r parameters control various aspects of the QoS implementation, and
8880are the most interesting to play with when testing out QoS.
8981
9082If the -s parameter is set to 1, then this program opens up a window to show the images
9183that have been received over the ROS 2 pub/sub model. This program should be used
92- in conjunction with CAM2IMAGE_PY to demonstrate the ROS 2 QoS capabilities over lossy/slow
84+ in conjunction with cam2image_py to demonstrate the ROS 2 QoS capabilities over lossy/slow
9385links.
9486
95- EXAMPLE USAGE
96- -------------
87+ ### EXAMPLE USAGE
9788To use the above programs, you would run them something like the following:
9889
9990# In the first terminal, run the data publisher. This will connect to the 1st camera
10091# available, and print out "Publishing image #" for each image it publishes.
101- $ python3 cam2image_py.py
102-
103- # In a second terminal, run the data subscriber. This will subscribe to the "image"
104- # topic and render any frames it receives.
105- $ python3 showimage_py.py -s 1
92+ ```
93+ $ ros2 run image_tools_py cam2image_py
94+ ```
10695
10796# If you don't have a local camera, you can use the -b parameter to generate data on
10897# the fly rather than get data from a camera:
109- $ python3 cam2image_py.py -b
98+ ```
99+ $ ros2 run image_tools_py cam2image_py -b
100+ ```
101+
102+ # In a second terminal, run the data subscriber. This will subscribe to the "image"
103+ # topic and render any frames it receives.
104+ ```
105+ $ ros2 run image_tools_py showimage_py
106+ ```
0 commit comments