Image visualization

In ROS, we have a node that allows the display of images coming from a camera on-the-fly. This is an example of a topic with complex data, which is better visualized or analyzed with special tools. You only need a camera to do this, such as your laptop webcam. The example8 node implements a basic camera capture program using OpenCV and ROS bindings to convert cv::Mat images into ROS Image messages that can be published in a topic. This node publishes the camera frames in the /camera topic.

We are only going to run the node with a launch file created to do so. The code inside the node is still new for the reader, but in the next chapters, we will cover how to work with cameras and images in ROS, so we will be able to come back to this node and understand it:

$ roslaunch chapter3_tutorials example8.launch

Once the node is running, we can list the topics (rostopic list) and see that the /camera topic is there. A straightforward way to verify that we are actually capturing images is to see at which frequency we are receiving images in the topic with rostopic hz /camera. It should be something in the region of 30 Hz usually. This is shown in the following screenshot:

Image visualization

Visualizing a single image

We cannot use rostopic echo /camera because, as it's an image, the amount of information in plain text would be very huge and not human readable. Hence, we are going to use the following command:

$ rosrun image_view image_view image:=/camera

This is the image_view node, which shows the images in the given topic (the image argument) in a window. This way, we can visualize every image or frame published in a topic in a very simple and flexible manner—even over a network. If you press the right-hand side button of your mouse on the window, you can save the current frame in the disk, usually in your home directory or ~/.ros.

ROS hydro also has rqt_image_view, which supports viewing multiple images in a single window but does not allow the saving of images by pressing the right-hand side button. We can select the image topic manually on the GUI, or as we do with image_view:

$ rosrun rqt_image_view rqt_image_view

The preceding command yields an output shown in the following screenshot:

Visualizing a single image

ROS provides a camera calibration interface built on top of the OpenCV calibration API. We will cover this in Chapter 5, Computer Vision, when we see how to work with cameras. There, we will see monocular and stereo cameras as well as the ROS image pipeline (image_proc and stereo_image_proc), which allow the rectification of the camera image distortion and compute the depth image disparity for stereo pairs, so that we obtain a point cloud.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset