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

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

Comments

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 image ahendrix  ( 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 image daniel_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 image daniel_dsouza  ( 2016-08-25 14:13:46 -0500 )edit

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

ashwath1993 gravatar image ashwath1993  ( 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 image daniel_dsouza  ( 2017-06-15 10:58:20 -0500 )edit
ashwath1993 gravatar image ashwath1993  ( 2017-06-15 12:07:21 -0500 )edit

Could you please link your entire ros package? Until then, look at this (working) example https://github.com/daniel-dsouza/solid-succotash

daniel_dsouza gravatar image daniel_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 image ashwath1993  ( 2017-06-15 15:27:18 -0500 )edit

2 Answers

Sort by » oldest newest most voted
9

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)

to

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

Comments

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 image ashwath1993  ( 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 image naveenT1010  ( 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 image ashwath1993  ( 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 image ashwath1993  ( 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 image k_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 image daniel_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 image daniel_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 image k_totoro  ( 2017-10-13 22:02:05 -0500 )edit
0

answered 2020-12-04 11:10:35 -0500

updated 2020-12-04 11:11:26 -0500

I managed to build a CUDA-enabled OpenCV without having to modify the CMakeLists. Here are the steps for Kinetic:

First, install CUDA 10.2 or earlier (OpenCV 3.3.1 is not compatible with CUDA 11). Then:

cd catkin_ws/src
git clone -b release/kinetic/opencv3 https://github.com/ros-gbp/opencv3-release.git opencv3
git clone -b kinetic https://github.com/ros-perception/vision_opencv.git
cd ..

catkin config --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebugInfo -DCUDA_HOST_COMPILER=/usr/bin/g++ 
# you can add more arguments for OpenCV, like -DWITH_CUDA=ON, but OpenCV should autodetect your 
# CUDA installation, so that won't be necessary

# since opencv3 isn't a catkin package, it won't be built before dependent packages, so we have 
# to build it manually first
catkin clean
catkin build opencv3
source devel/setup.bash

# build the rest of the packages
catkin build --force-cmake
edit flag offensive delete link more

Question Tools

4 followers

Stats

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

Seen: 7,618 times

Last updated: Dec 04 '20