Ask Your Question
1

How can I reference a standalone OpenCV installation inspite of having other version of Opencv version in ROS

asked 2014-01-09 20:52:43 -0600

saimanoj18 gravatar image

I have ROS in the system and it comes with opencv2.4.2. I have also installed opencv from sourceforge.net which is opencv2.4.8 following samontab blog.

Now I have a source code which when run automatically selects the opencv2.4.2. I want the program to run using opencv2.4.8.

I tried adding this to CMakeLists.txt

include_directories("/home/sai/workspace/opencv-2.4.8/include/opencv") 
   link_directories("/home/sai/workspace/opencv-2.4.8/lib") 
   set(OpenCV_LIBS 
"opencv_gpu;opencv_contrib;opencv_legacy;opencv_objdetect;opencv_calib3d;opencv_features2d;opencv_video;opencv_highgui;opencv_ml;opencv_imgproc;opencv_flann;opencv_core") 

find_package(OpenCV 2.4.8 REQUIRED) 

target_link_libraries(exec {OpeCV_LIBS})

But still it uses Opencv that comes with ROS and also gives an error like this

             from /home/sai/workspace/loop_detector_on_depth_images/depth_loops/generic/src/dbow/FBit.h:5,
             from /home/sai/workspace/loop_detector_on_depth_images/depth_loops/generic/src/dbow/FBit.cpp:1:

/opt/ros/fuerte/include/opencv2/flann/lsh_table.h: In member function ‘void cvflann::lsh::LshTable<elementtype>::add(cvflann::Matrix<t>)’: /opt/ros/fuerte/include/opencv2/flann/lsh_table.h:196:14: error: ‘use_speed_’ was not declared in this scope

and

pkg-config --cflags opencv says

-I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include

edit retag flag offensive close merge delete

4 answers

Sort by » oldest newest most voted
1

answered 2014-02-17 09:39:44 -0600

Josep Bosch 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 standalone ones... So I ended up just deleting CPATH whenever I need to compile somthing with the OpenCV standalone version.

edit flag offensive delete link more

Comments

Adding your OpenCV include, libs and pkgconfig paths to CPATH, LD_LIBRARY_PATH and PKG_CONFIG_PATH is the way to go. Then you should rm -fr build devel under your ROS workspace and rebuild every package from scratch. The newly built executables should now be using your custom installation of OpenCV (you can check it with ldd <executable_name>. Note that some dependency package (e.g. cv_bridge) may still cause your executable to depend from "official" OpenCV installation (/usr/lib/x86_64-linux-gnu/libopencv*.so*). If you want to get rid of all of them, you should also git clone the relevant packages and repeat the operation (delete build/ devel/ and rebuild from scratch).

Avio gravatar imageAvio ( 2016-11-11 06:21:38 -0600 )edit
0

answered 2014-01-10 05:12:28 -0600

decision gravatar image

updated 2014-01-10 05:13:50 -0600

I imagine the ROS package is just found (and used) before the installation that you added.

Instead of fiddling with CMakeLists.txt, add the exact path on commandline as an argument to cmake or - easier - find the appropriate field when using ccmake GUI.

edit flag offensive delete link more
0

answered 2014-01-13 03:57:52 -0600

saimanoj18 gravatar image

updated 2014-01-13 03:58:13 -0600

Finally its solved.

From the link http://answers.ros.org/question/61923/how-to-use-newer-versions-of-opencv-in-fuerte/

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
0

answered 2014-01-10 03:30:19 -0600

Nghia gravatar image

You create a shell wrapper script (eg. run.sh) containing:

  #!/bin/sh
  export LD_LIBRARY_PATH=/home/sai/workspace/opencv-2.4.8/lib
  exec your_program $*

This will look for the OpenCV libs in your chosen path before anywhere else.

edit flag offensive delete link more

Comments

1

This did not solve the issue, I am still getting the same error. I am trying to compile the program first.

saimanoj18 gravatar imagesaimanoj18 ( 2014-01-12 08:29:13 -0600 )edit

Misread your post. Try an export C_INCLUDE_PATH=/home/sai/workspace/opencv-2.4.8/include/opencv

Nghia gravatar imageNghia ( 2014-01-12 08:58:39 -0600 )edit
1

still the same error!

saimanoj18 gravatar imagesaimanoj18 ( 2014-01-12 22:45:15 -0600 )edit

Hmm. Can you verify the correctness of the opencv-2.4.8 path by temporarily renaming the OpenCV directory in ROS. See if it can compile and find the 2.4.8 headers.

Nghia gravatar imageNghia ( 2014-01-13 01:21:07 -0600 )edit

Finally its solved.. From the link http://answers.ros.org/question/61923/how-to-use-newer-versions-of-opencv-in-fuerte/

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)

saimanoj18 gravatar imagesaimanoj18 ( 2014-01-13 03:45:20 -0600 )edit

Question Tools

Stats

Asked: 2014-01-09 20:52:43 -0600

Seen: 5,587 times

Last updated: Feb 17 '14