【OpenCV】多版本那是interesting

OpenCV在使用时的问题

摘要

如果多版本安装OpenCV,切勿默认安装,务必每安装一个版本都新建一个目录,这样就会少很多问题。但是安装ROS会不知不觉的将自带的OpenCV安装到默认路径。一样会导致冲突。这时候最好的解决办法还没找到,所以最好的办法就是用ROS自带的OpenCV,虽然有警告,但是可以用呀!

背景

  1. 安装Ubuntu20.04对应的ROS,顺带安装个OpenCV4.2.0安装到默认路径(相当讨厌,也有优势);
  2. 安装了OpenCV4.8.0 到指定目录,用于ORB-SLAM3,顺利使用没有啥问题,未见冲突;
  3. 配置OpenCV3.2.0和VINS-fusion,编译通过,但是显示有警告。最可怕的是运行失败(直接段错误)可以使用gdb调试查看原因,原因是,在链接库文件时它偷偷摸摸链接到OpenCV4.2.0。让人担心的警告直接发生了。可供参考
  4. 解决方法,就是修改找opencv直接链接到ROS自带的4.2.0,编译VINS-fusion通过,但是显示有警告。可是它真的没有偷偷摸摸链接到其他库。勉强可用!!!

关于第3条,警告信息如下,这几个可能conflict

bash 复制代码
 	/usr/local/opencv3.2.0/lib/libopencv_core.so.3.2
    /usr/local/opencv3.2.0/lib/libopencv_imgcodecs.so.3.2
    /usr/local/opencv3.2.0/lib/libopencv_calib3d.so.3.2
    /usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.4.2
    # /usr/local/opencv3.2.0/lib/libboost_filesystem.so.1.71.0
    /usr/local/opencv3.2.0/lib/libopencv_features2d.so.3.2

关于第4条,警告信息如下:

bash 复制代码
...
[ 97%] Linking CXX executable /home/pf/VINSfusionFix/devel/lib/vins/kitti_gps_test
[ 98%] Linking CXX executable /home/pf/VINSfusionFix/devel/lib/vins/kitti_odom_test
/usr/bin/ld: warning: libopencv_calib3d.so.4.2, needed by /home/pf/VINSfusionFix/devel/lib/libvins_lib.so, may conflict with libopencv_calib3d.so.3.2
/usr/bin/ld: warning: libopencv_imgcodecs.so.3.2, needed by /home/pf/VINSfusionFix/devel/lib/libvins_lib.so, may conflict with libopencv_imgcodecs.so.4.2
/usr/bin/ld: warning: libopencv_core.so.3.2, needed by /usr/local/opencv3.2.0/lib/libopencv_calib3d.so.3.2, may conflict with libopencv_core.so.4.2
/usr/bin/ld: warning: libopencv_calib3d.so.4.2, needed by /home/pf/VINSfusionFix/devel/lib/libvins_lib.so, may conflict with libopencv_calib3d.so.3.2
/usr/bin/ld: warning: libopencv_imgcodecs.so.3.2, needed by /home/pf/VINSfusionFix/devel/lib/libvins_lib.so, may conflict with libopencv_imgcodecs.so.4.2
/usr/bin/ld: warning: libopencv_core.so.3.2, needed by /usr/local/opencv3.2.0/lib/libopencv_calib3d.so.3.2, may conflict with libopencv_core.so.4.2
[ 98%] Built target kitti_gps_test
[ 98%] Built target kitti_odom_test
[100%] Linking CXX executable /home/pf/VINSfusionFix/devel/lib/vins/vins_node
/usr/bin/ld: warning: libopencv_calib3d.so.4.2, needed by /home/pf/VINSfusionFix/devel/lib/libvins_lib.so, may conflict with libopencv_calib3d.so.3.2
/usr/bin/ld: warning: libopencv_core.so.3.2, needed by /usr/local/opencv3.2.0/lib/libopencv_calib3d.so.3.2, may conflict with libopencv_core.so.4.2
[100%] Built target vins_node

重点解释说明第4条

解决方法,就是修改找opencv直接链接到ROS自带的4.2.0,编译VINS-fusion通过,但是显示有警告。可是它真的没有偷偷摸摸链接到其他库。勉强可用!!!

修改一些报错

ROS noetic版本中的OpenCV4.2和VINS-fusion中需要使用的OpenCV3冲突,修改以兼容OpenCV4。幸运的是发现不用修改代码中不兼容的变量,可以直接添加缺失的头文件即可:

如下

  • 在camera_models包中的头文件Chessboard.h中添加

    #include <opencv2/imgproc/types_c.h>
    #include <opencv2/calib3d/calib3d_c.h>

  • 在camera_models包中的头文件CameraCalibration.h、pose_graph包中的头文件pose_graph.h和keyframe.h、BRIEF.h中添加

    #include <opencv2/imgproc/types_c.h>
    #include <opencv2/imgproc/imgproc_c.h>

  • 若vins_estiamtor包中报错,将头文件替换为

    // #include <opencv/cv.h>
    // #include <opencv/highgui.h>
    #include <opencv2/highgui.hpp>
    #include <opencv2/cvconfig.h>

找OpenCV

重点是找默认的opencv ,

  • 你以为直接确定版本可以找到ROS对应的4.2.0,可是它找不到

    find_package(OpenCV 4.2 REQUIRED)
    message(WARNING "OpenCV_VERSION: ${OpenCV_VERSION}")

    #输出:
    #CMake Warning at CMakeLists.txt:21 (message):
    #OpenCV_VERSION: 4.8.0

  • 你以为不加版本直接找可以找到ROS对应的4.2.0,可是它也找不到,不仅找不到,它找上一次有版本的opencv(自己体会这句话)

    find_package(OpenCV REQUIRED)
    message(WARNING "OpenCV_VERSION: ${OpenCV_VERSION}")

    #输出:
    #CMake Warning at CMakeLists.txt:21 (message):
    #OpenCV_VERSION: 4.8.0

  • 正确的方法 去找ROS对应的4.2.0对应的文件OpenCVConfig.cmake 然后找到路径,这就可以了。

  • cmake编译原理是需要CMakeLists.txt找到 .cmake 文件,就在那几个目录下面,

    1. /usr/share/OpenCV/
    2. /usr/lib/x86_64-linux-gnu/cmake/opencv4/
    3. ...

    set(OpenCV_DIR /usr/lib/x86_64-linux-gnu/cmake/opencv4/)
    find_package(OpenCV REQUIRED)

    -- Found OpenCV: /usr (found version "4.2.0")

    OPENCV VERSION: 4.2.0

    find_package(catkin REQUIRED COMPONENTS
    OpenCV
    )

bash 复制代码
pf@pf-NUC12WSKi7:~/VINSfusionFix$ catkin_make
Base path: /home/pf/VINSfusionFix
Source space: /home/pf/VINSfusionFix/src
Build space: /home/pf/VINSfusionFix/build
Devel space: /home/pf/VINSfusionFix/devel
Install space: /home/pf/VINSfusionFix/install
####
#### Running command: "make cmake_check_build_system" in "/home/pf/VINSfusionFix/build"
####
####
#### Running command: "make -j16 -l16" in "/home/pf/VINSfusionFix/build"
####
[  5%] Built target libGeographiccc
[ 24%] Built target camera_models
[ 45%] Built target Calibrations
[ 49%] Built target global_fusion_node
[ 68%] Built target loop_fusion_node
[ 91%] Built target vins_lib
[ 97%] Built target kitti_gps_test
[ 97%] Built target kitti_odom_test
[100%] Built target vins_node
相关推荐
ctrey_1 小时前
2024-11-4 学习人工智能的Day21 openCV(3)
人工智能·opencv·学习
可均可可2 小时前
C++之OpenCV入门到提高004:Mat 对象的使用
c++·opencv·mat·imread·imwrite
蒙娜丽宁2 小时前
《Python OpenCV从菜鸟到高手》——零基础进阶,开启图像处理与计算机视觉的大门!
python·opencv·计算机视觉
plmm烟酒僧3 小时前
Windows下QT调用MinGW编译的OpenCV
开发语言·windows·qt·opencv
AI小杨3 小时前
【车道线检测】一、传统车道线检测:基于霍夫变换的车道线检测史诗级详细教程
人工智能·opencv·计算机视觉·霍夫变换·车道线检测
冷凝女子4 小时前
【QT】海康视频及openCv抓拍正脸接口
qt·opencv·音视频·海康
撞南墙者6 小时前
OpenCV自学系列(1)——简介和GUI特征操作
人工智能·opencv·计算机视觉
柳鲲鹏7 小时前
OpenCV视频防抖源码及编译脚本
人工智能·opencv·计算机视觉
jndingxin7 小时前
OpenCV视觉分析之目标跟踪(8)目标跟踪函数CamShift()使用
人工智能·opencv·目标跟踪
ctrey_18 小时前
2024-11-1 学习人工智能的Day20 openCV(2)
人工智能·opencv·学习