ThaHypnotoad
ThaHypnotoad

Reputation: 185

c++ opencv setup for ros Jade

I posted this question on the ros answers forums but haven't gotten an answer as of yet, so here's to hedging my bets.

I have successfully set up eclipse for use with ros. I have successfully set up eclipse for use with opencv (as a c++ project with all the linker dohickeys.)

I have yet to find comprehensive documentation on setting up ros for use with opencv. There are plenty of tutorials regarding its use, but I have no idea what I'm supposed to be putting into the manifest.xml and CMakeLists.txt.

simply putting:

and

find_package( OpenCV REQUIRED )

in manifest and CMakeLists respectively doesn't work, and gives me a predictable error message when I attempt to build it using the rosmake command: Package opencv3 was not found in the pkg-config search path.

What am I supposed to be doing here?

Upvotes: 0

Views: 211

Answers (2)

Vtik
Vtik

Reputation: 3130

We have an indigo package that uses image_transport to subscribe to an image topic, converts it to an OpenCV type and then internally uses OpenCV directly to work with the images. The scenario is pretty much the same as in the example ROS node of the Using CvBridge To Convert Between ROS Images And OpenCV Images tutorial.

There are several problems as soon as ros-indigo-opencv3 is installed on the system. It took us some time to figure that out, because the opencv3 package was installed as a dependency of another package for a completely different project.

1 - The line

find_package(OpenCV REQUIRED)

in the cmake snippet in http://wiki.ros.org/vision_opencv#Using_OpenCV_in_your_ROS_code always finds the OpenCV 3 installation in /opt/ros/indigo from now on, which is bad. We observed all kind of consequences ranging from compilation errors, linker errors to segfaults, especially in combination with ros-indigo-cv-bridge, which is linked against the system installation of OpenCV 2.4.8.

2 - The workaround would be to add a specific version requirement, like

find_package(OpenCV 2.4.8 EXACT REQUIRED)

or to rely on cv_bridge or image_geometry to link to the correct version of opencv indirectly as recommended in the ROS indigo migration guide.

Even if you somehow can avoid that cmake picks up the OpenCV 3 installation in /opt/ros/indigo, the preprocessor will still prefer the headers found in /opt/ros/include/opencv2 (installed by ros-indigo-opencv3) over /usr/include/opencv2 from now on whenever it finds a

#include <opencv2/core/core.hpp>

like in cv_bridge.h:43, because some dependency will always add /opt/ros/indigo to the include path.

The only workaround I found so far is the following cmake snippet:

find_package(OpenCV 2.4.8 EXACT REQUIRED)
include_directories(
 include
 ${OpenCV_INCLUDE_DIRS}        # /usr/include/opencv;/usr/include
 ${catkin_INCLUDE_DIRS}        # contains /opt/ros/indigo/include
 # ...other include directories
)

to make sure that the OpenCV 2.4.8 headers in /usr/include are ordered before any other packages' headers.

Probably the situation is the same in ROS jade.

Upvotes: 1

ThaHypnotoad
ThaHypnotoad

Reputation: 185

Alright, I'm not going to set this as the correct answer until I know what's actually going on with the manifest, but if I get rid of the opencv3 dependency (or opencv2, they both behave the same) it all works fine.

Seriously though, can someone with a half decade more experience tell me what's going on here?

Upvotes: 0

Related Questions