ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
8

Use ros-indigo-opencv3 alongside 2.4.8?

asked 2015-07-18 07:34:50 -0500

lucasw gravatar image

updated 2020-11-21 11:19:18 -0500

Maybe it is brand new but I've recently noticed I can install ros-indigo-opencv3. It installs into the /opt/ros/indigo. There is also a opencv 2.4.8 already installed into the system outside of /opt in /usr/lib/x86_64-linux-gnu/, and every ros package from the repositories linked against opencv is linked to that.

When I try to build a package that depends on cv_bridge it fails:

CMakeFiles/rotate_cam.dir/src/rotate_cam.cpp.o: In function `RotateImage::RotateImage()':
rotate_cam.cpp:(.text+0x6dc): undefined reference to `cv::imread(cv::String const&, int)'
CMakeFiles/rotate_cam.dir/src/rotate_cam.cpp.o: In function `cv::String::~String()':
rotate_cam.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/rotate_cam.dir/src/rotate_cam.cpp.o: In function `cv::String::String(std::string const&)':
rotate_cam.cpp:(.text._ZN2cv6StringC2ERKSs[_ZN2cv6StringC5ERKSs]+0x69): undefined reference to `cv::String::allocate(unsigned long)'

And if I remove ros-indigo-opencv3 it builds fine. With VERBOSE=1 I don't see any trace of opencv3 includes or libraries (cv_bridge properly brings in 2.4.8 libraries, and includes /usr/include/opencv which is still 2.4.8).

The problem is that it is using opencv 3.0 headers and linking against 2.4.8, and breakage between those produces the link error.

When the a node dependent on opencv 2.4.8 builds it runs:

c++ ... -I/opt/ros/jade/include -I/usr/include/opencv ...

It seem like one problem is that opencv 3.0 is installed in the jade directories and 2.4.8 is in the usr directory- so it is using the wrong header files. But even when I correct this ordering the linker error still occurs.

What I'd like is to have opencv 3.0 available for special packages that need it (though they can't also link to cv_bridge, no mixing of 2.4.8 and 3.0 in the same package?).

I'm going to try to duplicate this problem on a small scale, it is possibly an artifact of something in one of my cmake files in my large workspace.

Ubuntu 14.04.2

edit retag flag offensive close merge delete

Comments

Any update on this? I working on a project with similar concerns.

jeremya gravatar image jeremya  ( 2015-09-28 15:22:47 -0500 )edit

Tried this with ros-jade-opencv3.0 and it fails the same way.

lucasw gravatar image lucasw  ( 2015-11-30 16:30:08 -0500 )edit
lucasw gravatar image lucasw  ( 2015-11-30 16:34:55 -0500 )edit

@jeremya I was able to get opencv 3.0 installed from source to a non-standard location and have a specific package find_package it. ros-indigo-opencv3 seems just plain broken. http://answers.ros.org/question/21392...

lucasw gravatar image lucasw  ( 2015-11-30 16:47:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2015-12-01 10:29:36 -0500

lucasw gravatar image

My current solution is to build OpenCV 3.0 from source and then install it into a location that is not on any paths. Then in the package

# don't use opencv as found by any prior running of find_package
unset(OpenCV_CONFIG_PATH CACHE)
unset(OpenCV_DIR CACHE)

set(TMP_PREFIX_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH "$ENV{HOME}/special/install")
find_package(OpenCV 3.0 REQUIRED)

# restore CMAKE_PREFIX_PATH and other cached variables
# so nothing other package finds this opencv
set(CMAKE_PREFIX_PATH ${TMP_PREFIX_PATH})

unset(OpenCV_CONFIG_PATH CACHE)
unset(OpenCV_DIR CACHE)

...

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

target_link_libraries(foo_node
  ${catkin_LIBRARIES}
  ${OpenCV_LIBS}
)
edit flag offensive delete link more

Comments

With this solution do you still have the limitation that you can't use cv_bridge in the same node?

Thomas D gravatar image Thomas D  ( 2015-12-31 14:58:35 -0500 )edit

It does have that limitation- I haven't done it but cv_bridge could maybe be recompiled against cv 3.0 in the workspace.

lucasw gravatar image lucasw  ( 2016-01-19 16:05:38 -0500 )edit
2

I spent hours trying to do this before finding this answer! I can confirm that cv_bridge can be used in the same node: recompile cv_bridge from source and use this approach for both your code and cv_bridge.

cyberguy42 gravatar image cyberguy42  ( 2016-02-23 19:40:20 -0500 )edit

@cyberguy42 did you do something special to compile from source, because dpkg did not help me.

jtim gravatar image jtim  ( 2016-07-27 06:08:45 -0500 )edit
1

I didn't use dpkg at all; I downloaded this package link text to my catkin workspace, applied the suggested changes to each affected CMakeLists, and compiled.

cyberguy42 gravatar image cyberguy42  ( 2016-07-28 10:27:15 -0500 )edit
1

However, I did encounter issues making my program into a nodelet: it compiled fine, but crashed at run time. Debugging revealed that it was trying to call the 2.4.8 library. Static compiling of 3.0 into my program didn't fix the problem. Lesson: run 2.4.8 and 3.0 code in separate processes.

cyberguy42 gravatar image cyberguy42  ( 2016-07-28 10:32:16 -0500 )edit

Question Tools

6 followers

Stats

Asked: 2015-07-18 07:34:50 -0500

Seen: 6,607 times

Last updated: Dec 01 '15