OpenCV in ROS

ROS provides a very simple integration with OpenCV, the most widely used open source Computer Vision library. However, it does not ship a specific Debian for ROS kinetic because that would force users to use a single version. Instead of that, it allows you to use the latest OpenCV library on the system and provides additional integration tools to use OpenCV in ROS. In the following sections we will explain how to install OpenCV and those additional tools.

Installing OpenCV 3.0

In ROS Kinetic we can start using OpenCV 3.0, in contrast to previous versions where some packages had some dependencies on OpenCV 2.* or compatibility issues with 3.0.

The installation follows the standard workflow of installing Ubuntu packages, so you only have to do the following:

$ sudo apt-get install libopencv-dev

Alternatively, you can also install an ROS package that installs the library too:

$ sudo apt-get install ros-kinetic-opencv3

Using OpenCV in ROS

ROS uses the standalone OpenCV library installed on your system. However, you must specify a build and running dependency with an opencv2 package in the package.xml file:

<build_depend>opencv2</build_depend>
<run_depend>opencv2</run_depend>

In CMakeLists.xml, we have to insert the following lines:

find_package(OpenCV)
include_directories(${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})

Then, for each library or executable that uses OpenCV, we must add ${OpenCV_LIBS} to target_link_libraries (see CMakeLists.txt provided for the chapter5_tutorials package).

In our node .cpp file, we include any of the OpenCV libraries we need. For example, for highgui.hpp, we use the following line:

#include <opencv2/highgui/highgui.hpp>

Now you can use any of the OpenCV API classes, functions, and so on in your code, as usual. Simply use its cv namespace and follow any OpenCV tutorial if you are starting with it. Note that this book is not about OpenCV—just how we can do Computer Vision inside ROS.

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

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