ubuntu 替换ros编译使用的opencv版本

- 以Ubuntu 18.04为例:ROS Melodic -> opencv-3.2.0 -> opencv-4.5.4

1、安装完opencv后,记住自己make install时opencv的安装路径

输入命令修改内容:

vim /opt/ros/melodic/share/cv_bridge/cmake +94

2、模范如下方法进行修改

# --------------------------------------------------------------------zhaocai
# if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
if(NOT "include;/usr/local/opencv4/include/opencv4/opencv2 " STREQUAL " ")
# --------------------------------------------------------------------zhaocai
    set(cv_bridge_INCLUDE_DIRS "")
# --------------------------------------------------------------------zhaocai
#  set(_include_dirs "include;/usr/include;/usr/include/opencv")
   set(_include_dirs "include;/usr/local/opencv4/include/opencv4/opencv2")
# --------------------------------------------------------------------zhaocai
if(NOT "https://github.com/ros-perception/vision_opencv/issues " STREQUAL " ")
     set(_report "Check the issue tracker 'https://github.com/ros-perception/vision_opencv/issues' and consider creating a ticket if the problem has not been reported yet.")
   elseif(NOT "http://www.ros.org/wiki/cv_bridge " STREQUAL " ")
     set(_report "Check the website 'http://www.ros.org/wiki/cv_bridge' for information and consider reporting the problem.")
   else()
     set(_report "Report the problem to the maintainer 'Vincent Rabaud <vincent.rabaud@gmail.com>' and request to fix the problem.")
   endif()
   foreach(idir ${_include_dirs})
     if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir})
       set(include ${idir})
     elseif("${idir} " STREQUAL "include ")
       get_filename_component(include "${cv_bridge_DIR}/../../../include" ABSOLUTE)
       if(NOT IS_DIRECTORY ${include})
         message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found.  It does not exist in '${include}'.  ${_report}")
       endif()
     else()
       message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found.  It does neither exist as an absolute directory nor in '\${prefix}/${idir}'.  ${_report}")
     endif()
     _list_append_unique(cv_bridge_INCLUDE_DIRS ${include})
   endforeach()
 endif()
 
# --------------------------------------------------------------------zhaocai
# set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0")
 set(libraries "cv_bridge;/usr/local/opencv4/lib/libopencv_core.so.4.5.4;/usr/local/opencv4/lib/libopencv_imgproc.so.4.5.4;/usr/local/opencv4/lib/libopencv_imgcodecs.so.4.5.4")
# --------------------------------------------------------------------zhaocai

3、修改完成就可以重新编译了!

enjoy!


版权声明:本文为zc15210073939原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。