使用ros自带的opencv3.2.0时vins系列的代码都可以正常跑通,因为项目需要opencv3.4.0,安装后出现编译错误
参考:
https://blog.csdn.net/weixin_40749043/article/details/127547954
重要 https://blog.csdn.net/llllldm/article/details/126334841
解决办法(首先确保其他版本的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
在[/home/yzl/Learn_SLAM/vins-fusion_ws/devel/lib]
ldd libvins_lib.so | grep opencv
有三个库链接错
执行
cd /opt/ros/melodic/lib/
ldd libcv_bridge.so | grep opencv
尝试
sudo apt-get install --reinstall ros-melodic-desktop-full
然后重新按照上面的步骤来,就没有warning了
到这里vins-mono和vins-fusion都没有问题了,但是openvins报错了
aruco.hpp好像是额外的库
https://stackoverflow.com/questions/33200173/opencv-3-0-error-aruco-hpp-no-such-file-or-directory
locate没有
下载opencv_contrib-3.4.0到opencv-3.4.0同文件夹
然后
cmake .. -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules/
报错了:
gflags的问题,重新编译gflags
cd build/
cmake -DCMAKE_CXX_FLAGS=-fPIC ..
make
sudo make install
sudo ldconfig
成功,感动。。。
然后
sudo make install
后catkin build