安装不同的版本,只需要将其安装的路径修改即可,我这里是ros noetic使用的默认路径,opencv3.4.6的安装修改了安装路径到/usr/opencv_v_346
版本3.4.6
ros中opencv4安装之后,相关文件路径(默认)
修改cmakelist中opencv的版本,使程序使用自己的opencv3.4.6
参考链接
opencvConfig.cmake
配置文件的路径/usr/opencv_v_346/share/Opencv
set(OpenCV_DIR /usr/opencv_v_346/share/Opencv)
find_package(OpenCV 3 REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${OpenCV_LIBS})
参考链接
参考链接
**方法:**进入cv_bridge配置文件所在目录,并用gedit指令打开相关配置文件进行修改
cd /opt/ros/noetic/share/cv_bridge/cmake/
sudo gedit cv_bridgeConfig.cmake
include;
#if(NOT "include;/usr/include/opencv4 " STREQUAL " ")
# set(cv_bridge_INCLUDE_DIRS "")
# set(_include_dirs "include;/usr/include/opencv4")
# 346表示安装的版本是opencv3.4.6
if(NOT "include;/usr/opencv_v_346/include;/usr/opencv_v_346/include/opencv" STREQUAL " ")
set(cv_bridge_INCLUDE_DIRS "")
set(_include_dirs "include;/usr/opencv_v_346/include;/usr/opencv_v_346/include/opencv")
cv_bridge;
,如果丢失会报cv_bridge中的函数未定义#set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dnn.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_features2d.so.4.2.0;/usr/lib/ x86_64-linux-gnu/libopencv_flann.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_ml.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_photo.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_stitching.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_video.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_videoio.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_aruco.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_ccalib.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_datasets.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dnn_objdetect.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dnn_superres.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dpm.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_face.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_freetype.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_hdf.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_hfs.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_img_hash.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_optflow.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_plot.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_quality.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_reg.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_rgbd.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_saliency.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_shape.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_stereo.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_structured_light.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_superres.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_text.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_tracking.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_viz.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_xphoto.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.4.2.0")
set(libraries "cv_bridge;/usr/opencv_v_346/lib/libopencv_videoio.so.3.4.6;/usr/opencv_v_346/lib/libopencv_imgproc.so.3.4.6;/usr/opencv_v_346/lib/libopencv_stitching.so.3.4.6;/usr/opencv_v_346/lib/libopencv_calib3d.so.3.4.6;/usr/opencv_v_346/lib/libopencv_objdetect.so.3.4.6;/usr/opencv_v_346/lib/libopencv_features2d.so.3.4.6;/usr/opencv_v_346/lib/libopencv_shape.so.3.4.6;/usr/opencv_v_346/lib/libopencv_imgcodecs.so.3.4.6;/usr/opencv_v_346/lib/libopencv_core.so.3.4.6;/usr/opencv_v_346/lib/libopencv_ml.so.3.4.6;/usr/opencv_v_346/lib/libopencv_flann.so.3.4.6;/usr/opencv_v_346/lib/libopencv_videostab.so.3.4.6;/usr/opencv_v_346/lib/libopencv_photo.so.3.4.6;/usr/opencv_v_346/lib/libopencv_superres.so.3.4.6;/usr/opencv_v_346/lib/libopencv_dnn.so.3.4.6;/usr/opencv_v_346/lib/libopencv_video.so.3.4.6;/usr/opencv_v_346/lib/libopencv_highgui.so.3.4.6")
sudo gedit cv_bridge-extras.cmake
如果不修改该文件,打印当前的opencv版本,仍是ros的,并且会有warning。(其实使用的还是自己安装的,只是显示的是ros的)
```python
#set(OpenCV_VERSION 4.2.0)
#set(OpenCV_VERSION_MAJOR 4)
#set(OpenCV_VERSION_MINOR 2)
#set(OpenCV_VERSION_PATCH 0)
#set(OpenCV_SHARED ON)
#set(OpenCV_CONFIG_PATH /usr/lib/x86_64-linux-gnu/cmake/opencv4)
#set(OpenCV_INSTALL_PATH /usr)
#set(OpenCV_LIB_COMPONENTS opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_hfs;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_viz;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto)
#set(OpenCV_USE_MANGLED_PATHS FALSE)
#set(OpenCV_MODULES_SUFFIX )
set(OpenCV_VERSION 3.4.6)
set(OpenCV_VERSION_MAJOR 3)
set(OpenCV_VERSION_MINOR 4)
set(OpenCV_VERSION_PATCH 6)
set(OpenCV_SHARED ON)
set(OpenCV_CONFIG_PATH /usr/opencv_v_346/share/OpenCV)
set(OpenCV_INSTALL_PATH /usr/opencv_v_346/)
set(OpenCV_LIB_COMPONENTS opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab)
set(OpenCV_USE_MANGLED_PATHS FALSE)
set(OpenCV_MODULES_SUFFIX )
```
参考链接:
自己编译功能包cv_bridge
相关命令
cmake文件输出打印消息:
SET(Opencv_DIR "/usr/local/opencv2.4.11")
find_package(OpenCV REQUIRED)
MESSAGE(STATUS "OpenCV version: "${OpenCV_VERSION})
MESSAGE(${PROJECT_SOURCE_DIR})
MESSAGE(${PROJECT_BINARY_DIR})
查看linux下的opencv安装路径:
sudo find / -iname "*opencv*"
在全盘上不区分大小写,搜索带有关键字opencv的所有文件及文件夹都会输出到终端,如果输出太长建议输出到txt文件里查看,如下:
sudo find / -iname "*opencv*" > /home/ubuntu/Desktop/opencv_find.txt
查看opencv版本:
pkg-config --modversion opencv
**目的:**使功能包使用opencv3编译而不是opencv4
源码官网地址
project(cv_bridge) 改为 project(cv_bridge_1)
cv_bridge 改为 cv_bridge_1
find_package(OpenCV 4)
的位置全改为OpenCv3
find_package(OpenCV 4)
的位置全改为OpenCv3
两个功能包同时编译,面临编译顺序的问题,因为vins功能包需要调用cv_bridge_1功能包,因此需要先对cv_bridge_1进行编译。
主要参考下面链接里方法2:手动修改依赖关系
功能包之间的相互调用
ROS中package.xml和cmakelist介绍
cv_bridge_1
cv_bridge_1
find_package(OpenCV 4)
的位置全改为OpenCv3