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

How to use newer versions of opencv in Fuerte

asked 2013-05-01 04:49:23 -0500

K Chen gravatar image

updated 2013-05-07 17:02:19 -0500

Recently I had an issue building my own package depending on cv_bridge package and a custom-built opencv library. I was able to solve the linking problem in previous ROS versions here, but later I found out that the package was in fact using the fuerte/include/opencv header, but linking with the right /usr/local/lib libs. Everything should be OK if the headers were not changed, but if they do, it will fail.

To find out why I listed all the include dirs in cmake, and I got the following result(only the first 5 items)

-- --> include dir='/home/kai/Projects/my_pkg/include'
-- --> include dir='/opt/ros/fuerte/include'
-- --> include dir='/usr/local/include/opencv'
-- --> include dir='/usr/local/include'
-- --> include dir='/opt/ros/fuerte/stacks/vision_opencv/cv_bridge/include'

As can be seen, the ros/fuerte/include dir precedes the /usr/local/include; as a result, even if I can find my custom-built opencv headers and libraries through FindPackage() in CMakeLists.txt from setting the right $CMAKE_PREFIX_PATH env var, the #include <opencv.h> will still find the ros/fuerte/include/opencv first.

To reproduce this problem, try the following:

  1. Install ros fuerte opencv package
  2. Download opencv from opencv.org and make&make install it with your own build options(namely, with CUDA)
  3. Create a package depending on cv_bridge package
  4. Follow the link provided above to make sure your CMakeLists.txt can use FindPackage() to find your custom built opencv package(default in /usr/local)
  5. Write some pieces of code using opencv's specific features(CUDA, if you built with it)
  6. rosmake or cmake ..& make it.
  7. Check the depend.make file under your_pkg/build/CMakeFiles/your_pkg.dir, find opencv occurrences, it will be /opt/ros/fuerte/include/opencv, not /usr/local/include/opencv

So what I am writing to ask is, is there any way to make my own opencv include path precedes the ros include path? Or it won't be found because there is a opencv/opencv2 dir in the fuerte/include dir and they will be found first. Currently I renamed ROS's provided opencv&opencv2 dirs names to hide them from being found, but I think there should be some better way.

Thanks in advance.

edit retag flag offensive close merge delete

Comments

And, I am under ubuntu 12.04 32-bit. No catkin build or ros_ws(still uses the old fashioned $ROS_PACKAGE_PATH way).

K Chen gravatar image K Chen  ( 2013-05-01 04:51:06 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-05-17 00:45:02 -0500

DiogoRolo gravatar image

updated 2013-05-20 05:32:55 -0500

I cheated and went to /opt/ros/fuerte/include and changed the name of opencv2 to opencv2bak. This way it finds the right includes. I don't think it's the right way to do it, though.

Also, went to /opt/ros/fuerte/share/OpenCV/OpenCVConfig.cmake and edited the Install path variable to /usr/local (where I installed)

edit flag offensive delete link more

Comments

1

Yes, this is what I am doing right now, but this would be overwritten when it updates, so I am asking for some more "elegant" way

K Chen gravatar image K Chen  ( 2013-05-24 02:33:29 -0500 )edit
2

We should always note for future reference that modifying protected location like under `/opt` isn't recommended.

130s gravatar image 130s  ( 2014-05-12 20:34:56 -0500 )edit
1

answered 2014-02-17 03:41:06 -0500

Jep gravatar image

I had the same problem. The thing is ros sets CPATH variable to something like:

/home/jep/catkin_ws/devel/include:/opt/ros/groovy/include

Then when compiling gcc always finds ROS opencv headers instead of the new ones... So I ended up just deleting CPATH whenever I need to compile somthing with the new OpenCV version.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2013-05-01 04:49:23 -0500

Seen: 4,405 times

Last updated: Feb 17 '14