安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功

使用ros自带的opencv3.2.0时vins系列的代码都可以正常跑通,因为项目需要opencv3.4.0,安装后出现编译错误

文章目录

  • (一)ros-melodic-cv-bridge和opencv3.4.0冲突(vins-mono vins-fusion问题解决,open-vins部分解决)
  • (二)open-vins缺少opencv-contrib-3.4.0中的库(open-vins问题解决)

参考:

https://blog.csdn.net/weixin_40749043/article/details/127547954

重要 https://blog.csdn.net/llllldm/article/details/126334841

img

(一)ros-melodic-cv-bridge和opencv3.4.0冲突(vins-mono vins-fusion问题解决,open-vins部分解决)

解决办法(首先确保其他版本的opencv是否卸载干净!)

然后

1 更改 gedit /opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake

# yzl 2023.2.19 modified
# if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
if(NOT "include;/usr/local/include/opencv;/usr/local/include/opencv2 " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  #set(_include_dirs "include;/usr/include;/usr/include/opencv")
  set(_include_dirs "include;/usr/local/lib;/usr/local/include/opencv;/usr/local/include/opencv2;/usr/local/include;")
  set(libraries "cv_bridge;/usr/local/lib/libopencv_core.so.3.4.0;/usr/local/lib/libopencv_imgproc.so.3.4.0;/usr/local/lib/libopencv_imgcodecs.so.3.4.0")

以及

# yzl 2023.2.19 modified
#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/lib/libopencv_core.so.3.4.0;/usr/local/lib/libopencv_imgproc.so.3.4.0;/usr/local/lib/libopencv_imgcodecs.so.3.4.0")

2 更改/opt/ros/melodic/share/cv_bridge/cmake/cv_bridge-extras.cmake

# yzl 2023.2.19 modifed
#set(OpenCV_VERSION 3.2.0)
#set(OpenCV_VERSION_MAJOR 3)
#set(OpenCV_VERSION_MINOR 2)
#set(OpenCV_VERSION_PATCH 0)
set(OpenCV_VERSION 3.4.0)
set(OpenCV_VERSION_MAJOR 3)
set(OpenCV_VERSION_MINOR 4)
set(OpenCV_VERSION_PATCH 5)

**3 更改sudo gedit /opt/ros/melodic/lib/pkgconfig/cv_bridge.pc **

# yzl 2023.2.29 modified
#Libs: -L${prefix}/lib -lcv_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
Libs: -L${prefix}/lib -lcv_bridge /usr/local/lib/libopencv_core.so.3.4.0 /usr/local/lib/libopencv_imgproc.so.3.4.0 /usr/local/lib/libopencv_imgcodecs.so.3.4.0

通过上述修改后没有报错,但是有如下warnning

安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第1张图片

在[/home/yzl/Learn_SLAM/vins-fusion_ws/devel/lib]

ldd libvins_lib.so | grep opencv

安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第2张图片

有三个库链接错

执行

cd /opt/ros/melodic/lib/
ldd libcv_bridge.so | grep opencv

安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第3张图片

尝试

sudo apt-get install --reinstall ros-melodic-desktop-full

然后重新按照上面的步骤来,就没有warning了

到这里vins-mono和vins-fusion都没有问题了,但是openvins报错了

(二)open-vins缺少opencv-contrib-3.4.0中的库(open-vins问题解决)

安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第4张图片

aruco.hpp好像是额外的库

https://stackoverflow.com/questions/33200173/opencv-3-0-error-aruco-hpp-no-such-file-or-directory

安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第5张图片

locate没有

下载opencv_contrib-3.4.0到opencv-3.4.0同文件夹

然后

cmake .. -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules/        

报错了:

安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第6张图片

gflags的问题,重新编译gflags

cd build/
cmake -DCMAKE_CXX_FLAGS=-fPIC ..
make
sudo make  install
sudo ldconfig

成功,感动。。。

然后

sudo make install

后catkin build

open_vins编译成功
安装opencv-3.4.0后和ros自带的3.2.0版本冲突,导致open_vins、vins-mono、vins-fusion均无法编译成功_第7张图片

你可能感兴趣的:(SLAM进阶之路,ROS,opencv,人工智能,计算机视觉)