ROS工程不使用ROS自带的OpenCV

ROS工程不使用ROS自带的OpenCV

    • 0.引言
    • 1.多版本opencv安装
    • 2.安装cv_bridge
    • 3.使用

0.引言

ROS自带的opencv没有带CUDA、contrib库编译,如果程序使用了这两者则ROS自带的opencv就没办法使用。于是在系统中安装多个版本的opencv,同时将CMakeLists.txt更改符合要求opencv的路径;但是就算如此,使用catkin_make能成功编译,但是程序执行时却依然是链接的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.3.1/modules/core/include/opencv2/core/private.cuda.hpp, line 107
terminate called after throwing an instance of 'cv::Exception'
  what():  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/include/opencv2/core/private.cuda.hpp:107: error: (-216) The library is compiled without CUDA support in function throw_no_cuda

解决办法则是,自己再安装一个cv_bridge使自定义opencv版本与ROS进行链接。

1.多版本opencv安装

  • 参考博客.

2.安装cv_bridge

ROS里面是自带cv_bridge的,但他是连接到自带的opencv,遇事自己重现安装cv_bridge链接到自定义的opencv版本。

  • cv_bridge 下载,注意切换分支.

下载后将cv_bridge单独取出然后将CMakeLists.txt里面的opencv路径更改为自己的opencv路径再安装。以我的opencv3.4.0为例:

set(OpenCV_DIR "/usr/local/opencv340/share/OpenCV")
find_package(OpenCV 3.4.0 REQUIRED
  COMPONENTS
    opencv_core
    opencv_imgproc
    opencv_imgcodecs
  CONFIG
)

然后安装:

mkdir build && cd build && cmake -D CMAKE_INSTALL_PREFIX=/usr/local/cv_bridge340 ..
sudo make -j8
sudo make install

3.使用

安装成功后,使用时将源代码CMakeLists.txt中,首先指定cv_bridge路径:

set(cv_bridge_DIR /usr/local/cv_bridge340/share/cv_bridge/cmake)

然后在find_package()函数中如果没有cv_bridge则加上:

find_package(catkin REQUIRED COMPONENTS
    message_generation
    message_runtime
    roscpp
    std_msgs
    geometry_msgs
    nav_msgs
    tf
    cv_bridge ####
    camera_models
    image_transport
    nodelet
    message_filters
)

最后更改opencv路径:

SET(OpenCV_DIR  "/usr/local/opencv340/share/OpenCV")
find_package(OpenCV 3.4.0 REQUIRED)

问题解决.

你可能感兴趣的:(DeBug备忘,opencv,ROS,不使用ROS自带opencv,cv_bridge,opencv)