Ask Your Question

Having trouble using CUDA enabled OpenCV with kinetic

asked 2016-08-24 23:36:53 -0500

daniel_dsouza gravatar image

updated 2016-09-01 15:06:58 -0500

Hello everyone.

I started a new install of ROS Kinetic, and I was hoping to use a few CUDA features from OpenCV. I have successfully compiled and tested CUDA and OpenCV (which is installed in /usr/local), but I am having trouble using my OpenCV instead of the ros-kinetic-opencv3 package.

I have tried adding /usr/local to the front of my CMAKE_PREFIX_PATH, as well renaming the opencv pkgconfig file in /opt/ros/lib/pkconfig. However I still get the below error, indicating that I am building against the ROS OpenCv.

OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/core/include/opencv2/core/private.cuda.hpp, line 97 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/core/include/opencv2/core/private.cuda.hpp:97: error: (-216) The library is compiled without CUDA support in function throw_no_cuda

Any ideas?

edit retag flag offensive close merge delete


It looks like its loading the wrong library at runtime; this is usually controlled by the system library search paths (ldconfig) and LD_LIBRARY_PATH

ahendrix gravatar imageahendrix ( 2016-08-25 00:42:59 -0500 )edit

LD_LIBRARY_PATH looks like /usr/local/lib:/home/user/catkin_ws/devel/lib:/opt/ros/kinetic/lib

shouldn't it be pulling from /usr/local/lib where OpenCV is first if that was the case?

daniel_dsouza gravatar imagedaniel_dsouza ( 2016-08-25 02:07:33 -0500 )edit

if I manually run the CMakeLists.txt file, then the code build and executes correctly. However using catkin_make give different results?

daniel_dsouza gravatar imagedaniel_dsouza ( 2016-08-25 14:13:46 -0500 )edit

@daniel_dsouza, how did you run it manually? Just CMake .. and make?

ashwath1993 gravatar imageashwath1993 ( 2017-06-15 10:15:49 -0500 )edit

I believe so. Do you have a Github link to your code? I can try to compile it myself.

daniel_dsouza gravatar imagedaniel_dsouza ( 2017-06-15 10:58:20 -0500 )edit
ashwath1993 gravatar imageashwath1993 ( 2017-06-15 12:07:21 -0500 )edit

Could you please link your entire ros package? Until then, look at this (working) example

daniel_dsouza gravatar imagedaniel_dsouza ( 2017-06-15 14:58:23 -0500 )edit

@daniel_dsouza I have added the entire projecct on git. I will look into your project as well! Thanks!

ashwath1993 gravatar imageashwath1993 ( 2017-06-15 15:27:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-09-01 15:03:28 -0500

daniel_dsouza gravatar image

updated 2017-10-12 12:27:03 -0500

Hello previous me,

So you have the opencv3 package installed, which provides libraries in /opt/ros/kinetic/lib, and you also have OpenCV compiled from source, installed to usr/local. The trick is to tell catkin to use the libraries from usr/local.

By default, catkin is hardwired to look for packages in your workspace, then in /opt/ros/kinetic. CMake by itself will use the libraries in /usr/local. I tried to prioritize /usr/local by modifying the CMAKE_PREFIX_PATH environment variable, as suggested in pre kinetic posts, but no luck.

So if I cannot modify catkin itself, I should to explicitly tell CMake which OpenCV to use. I had to change my declaration from

find_package(OpenCV REQUIRED)


find_package(OpenCV REQUIRED
NO_MODULE # should be optional, tells CMake to use config mode
PATHS /usr/local # look here
NO_DEFAULT_PATH) # and don't look anywhere else

So that will pull in the correct libraries. If another package is built that requires OpenCV, catkin will also pull in the wrong dependencies. Mixed dependencies is a bad thing. So you have to add the modified OpenCV configuration to any other packages that require OpenCV. This includes the vision_opencv package that provides cv_bridge.

UPDATE 10/12/2017: Please see my fork of vision_opencv for the necessary changes and my cvTest example package. In the example, I demonstrate the use of my custom version of OpenCV 3.3 build with CUDA 8.

edit flag offensive delete link more


I have a similar problem. I replaced the CMake file as you have, but I still get the same error. find_package(OpenCV REQUIRED NO_MODULE PATHS /usr/local NO_DEFAULT_PATH) I can compile the code and run it outside ROS.

ashwath1993 gravatar imageashwath1993 ( 2017-05-27 07:54:04 -0500 )edit

ashwath1993 did you recompile other packages dependent on opencv or not? I was also having a similar problem, but when I compiled the vision_opencv from source, it all worked.

naveenT1010 gravatar imagenaveenT1010 ( 2017-05-28 17:23:13 -0500 )edit

I am able to run the opencv samples from the same path. Doesn't work with ROS alone.

ashwath1993 gravatar imageashwath1993 ( 2017-06-12 07:27:48 -0500 )edit

what(): /tmp/binarydeb/ros-kinetic-opencv3-3.2.0/modules/core/include/opencv2/core/private.cuda.hpp:97: error: (-216) The library is compiled without CUDA support in function throw_no_cuda My CMakeLists.txt contain the same find_package as you have mentioned

ashwath1993 gravatar imageashwath1993 ( 2017-06-15 07:30:07 -0500 )edit

Hi. I have same trouble and got same error. In the sentence "So you have to add the modified OpenCV configuration to any other packages that require OpenCV.", do you mean I have to change all Cmakelist in my packages?

k_totoro gravatar imagek_totoro ( 2017-10-12 01:13:28 -0500 )edit

@k_totoro Hello. I had to download the vision_opencv metapackage , and make the above changes to the cv_bridge and image_geometry packages' CMakeLists.txt. You only need to make the changes in packages that use/are used by your node that uses your custom OpenCV.

daniel_dsouza gravatar imagedaniel_dsouza ( 2017-10-12 01:38:49 -0500 )edit

@k_totoro, please see the update to my answer with the github repo

daniel_dsouza gravatar imagedaniel_dsouza ( 2017-10-12 12:35:50 -0500 )edit

Thank you daniel. I read your Github sample but still do not understand what you mean. So, I have to remove my "cv_bridge" or some package from apt-get and rebuild it for myself? Your test CMake file in CVTest looks the same with mine.

k_totoro gravatar imagek_totoro ( 2017-10-13 22:02:05 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2016-08-24 23:36:53 -0500

Seen: 4,993 times

Last updated: Oct 12 '17