使用支持 CUDA 的 OpenCV 编译 ROS 节点时不支持 CUDA
No CUDA support when ROS node is compiled using CUDA-enabled OpenCV
我在 cuda 支持下编译了 OpenCV,它在不使用 ROS 的程序上运行良好。
我在ROS Kinetic中创建了一个使用OpenCV CUDA实现算法的节点,并使用catkin_make编译它,指向/usr/local
中的OpenCV安装。 catkin_make 的输出如下所示:
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/degraw/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python (found version "2.7.12")
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/degraw/catkin_ws/build/test_results
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.6
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 2 packages in topological order:
-- ~~ - depth_calculator
-- ~~ - zed_wrapper
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'depth_calculator'
-- ==> add_subdirectory(depth_calculator)
-- Found CUDA: /usr/local/cuda (found suitable exact version "8.0")
-- Found OpenCV: /usr/local (found version "3.2.0")
在运行时我得到错误:
OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file /tmp/binarydeb/ros-kinetic-opencv3-3.2.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.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
[1] 21085 abort (core dumped) rosrun depth_calculator double_image_acq
即使 /tmp 中没有文件(我删除了所有内容,删除了 catkin_ws 中的构建和开发文件夹并重新运行 catkin_make,其输出如上所示)。
这可能是之前运行的缓存问题吗?
是否有任何运行时环境变量指向 /opt/ros/kinetic 中安装的 OpenCV 而不是 /usr/local 中的那个,节点是用它编译和链接的?
catkin_make
默认使用 ROS OpenCV 库版本安装,不支持 CUDA。为了使用外部版本的 OpenCV 库,您必须按照以下说明手动强制 CMake 使用它:
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
一般来说,混合 OpenCV 库版本是一件坏事。因此,您可能应该使用支持 CUDA 的版本重新构建所有其他使用默认 OpenCV 版本的 ROS 包(image_geometry, cv_bridge). Although personally I haven't tested this yet. I base my answer on this post。
您可以在 ROS kinetic here 中找到有关 OpenCV 的一些信息。
问这样的问题更好的地方是 ROS Answers site.
我在 cuda 支持下编译了 OpenCV,它在不使用 ROS 的程序上运行良好。
我在ROS Kinetic中创建了一个使用OpenCV CUDA实现算法的节点,并使用catkin_make编译它,指向/usr/local
中的OpenCV安装。 catkin_make 的输出如下所示:
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/degraw/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python (found version "2.7.12")
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/degraw/catkin_ws/build/test_results
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.6
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 2 packages in topological order:
-- ~~ - depth_calculator
-- ~~ - zed_wrapper
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'depth_calculator'
-- ==> add_subdirectory(depth_calculator)
-- Found CUDA: /usr/local/cuda (found suitable exact version "8.0")
-- Found OpenCV: /usr/local (found version "3.2.0")
在运行时我得到错误:
OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file /tmp/binarydeb/ros-kinetic-opencv3-3.2.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.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
[1] 21085 abort (core dumped) rosrun depth_calculator double_image_acq
即使 /tmp 中没有文件(我删除了所有内容,删除了 catkin_ws 中的构建和开发文件夹并重新运行 catkin_make,其输出如上所示)。
这可能是之前运行的缓存问题吗? 是否有任何运行时环境变量指向 /opt/ros/kinetic 中安装的 OpenCV 而不是 /usr/local 中的那个,节点是用它编译和链接的?
catkin_make
默认使用 ROS OpenCV 库版本安装,不支持 CUDA。为了使用外部版本的 OpenCV 库,您必须按照以下说明手动强制 CMake 使用它:
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
一般来说,混合 OpenCV 库版本是一件坏事。因此,您可能应该使用支持 CUDA 的版本重新构建所有其他使用默认 OpenCV 版本的 ROS 包(image_geometry, cv_bridge). Although personally I haven't tested this yet. I base my answer on this post。
您可以在 ROS kinetic here 中找到有关 OpenCV 的一些信息。 问这样的问题更好的地方是 ROS Answers site.