环境:
ubuntu20.04
opencv4.2.0(此次使用) 3.3.1(其他程序在使用)
vins-fusion
vision_opencv
1.下载VINS-Fusion和cv_bridge,并进行修改,方便使用opencv4.2.0和对应的cv_bridge。
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
# 下载 VINS-Fusion
git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git
# 下载cv_bridge 1.16,不存在多个版本的opencv可以不下,直接编译VINS-Fusion
git clone https://github.com/ros-perception/vision_opencv.git --branch noetic
# 我只想保留cv_bridge,想带着vision_opencv的可以不做
mv /vision_opencv/cv_bridge ./
rm -rf vision_opencv
2.编译cv_bridge
修改cv_bridge中的CMakeLists.txt和package.xml
# CMakeLists.txt
project(cv_bridge_4)
# package.xml
cv_bridge_4
编译cv_bridge
cd ~/catkin_ws
catkin build cv_bridge_4
3.编译VINS-Fusion
修改CMakeLists.txt,这一步是因为系统中有多个opencv,所以我需要确定是哪个并使用对应版本的cv_bridge
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/CMakeLists.txt
# /home/robot/catkin_ws/src/VINS-Fusion/loop_fusion/CMakeLists.txt
# /home/robot/catkin_ws/src/VINS-Fusion/vins_estimator/CMakeLists.txt
find_package(OpenCV REQUIRED) ⇒ find_package(OpenCV 4 REQUIRED)
cv_bridge ⇒ cv_bridge_4
编译
catkin build
ERROR 1:
error: ‘integer_sequence’ is not a member of ‘std’
FIX:
修改文件,不使用c++11而是c++14
# 修改/home/robot/catkin_ws/src/VINS-Fusion/camera_models/CMakeLists.txt
# 修改/home/robot/catkin_ws/src/VINS-Fusion/global_fusion/CMakeLists.txt
# 修改/home/robot/catkin_ws/src/VINS-Fusion/loop_fusion/CMakeLists.txt
# 修改/home/robot/catkin_ws/src/VINS-Fusion/vins_estimator/CMakeLists.txt
set(CMAKE_CXX_FLAGS "-std=c++14")
ERROR 2:
所有由于opencv版本引发的错误均集中在这里:
2.1 error: ‘CV_GRAY2BGR’ was not declared in this scope
error: ‘CV_BGR2GRAY’ was not declared in this scope
2.2 error: ‘CV_CALIB_CB_ADAPTIVE_THRESH’ was not declared in this scope
2.3 error: ‘CV_ADAPTIVE_THRESH_MEAN_C’ was not declared in this scope
2.4 error: ‘CV_THRESH_BINARY’ was not declared in this scope
2.5 error: ‘CV_AA’ was not declared in this scope; did you mean ‘CV_MSA’?
2.6 error: ‘CV_SHAPE_CROSS’ was not declared in this scope
2.7 error: ‘CV_RETR_CCOMP’ was not declared in this scope
error: ‘CV_CHAIN_APPROX_SIMPLE’ was not declared in this scope
2.8 error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
2.9 error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope
FIX:
修改格式:未修改CV_*==>修改后
# 2.1
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
CV_GRAY2BGR ⇒ cv::COLOR_GRAY2BGR
CV_BGR2GRAY ⇒ cv::COLOR_BGR2GRAY 两处
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/calib/CameraCalibration.cc
CV_GRAY2BGR ⇒ cv::COLOR_GRAY2BGR
# /home/robot/catkin_ws/src/VINS-Fusion/vins_estimator/src/featureTracker/feature_tracker.cpp
CV_GRAY2RGB ⇒ cv::COLOR_GRAY2RGB
/home/robot/catkin_ws/src/VINS-Fusion/loop_fusion/src/ThirdParty/DVision/BRIEF.cpp
CV_RGB2GRAY ⇒ cv::COLOR_RGB2GRAY
# 2.2
# 还是/home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
添加 #include
# 2.3
# 还是/home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
添加#include
# 2.4
# 还是/home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
CV_THRESH_BINARY ⇒ cv::THRESH_BINARY 四处
# 2.5
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/calib/CameraCalibration.cc
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/intrinsic_calib.cc
添加#include “opencv2/imgproc/imgproc_c.h”
#2.6
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
CV_SHAPE_CROSS ⇒ cv::MORPH_CROSS
CV_SHAPE_RECT ⇒ cv::MORPH_RECT
# 2.7
# /home/robot/catkin_ws/src/VINS-Fusion/camera_models/src/chessboard/Chessboard.cc
CV_RETR_CCOMP ⇒ cv::RETR_CCOMP 三处
CV_CHAIN_APPROX_SIMPLE ⇒ cv::CHAIN_APPROX_SIMPLE 三处
# 2.8
# /home/robot/catkin_ws/src/VINS-Fusion/vins_estimator/src/KITTIGPSTest.cpp
# /home/robot/catkin_ws/src/VINS-Fusion/vins_estimator/src/KITTIOdomTest.cpp
CV_LOAD_IMAGE_GRAYSCALE ⇒ cv::IMREAD_GRAYSCALE 各两处
# 2.9
# /home/robot/catkin_ws/src/VINS-Fusion/loop_fusion/src/keyframe.cpp
# /home/robot/catkin_ws/src/VINS-Fusion/loop_fusion/src/pose_graph.cpp
CV_FONT_HERSHEY_SIMPLEX ⇒ cv::FONT_HERSHEY_SIMPLEX 一个两处,一个五处
ERROR 3:
Segmentation Fault(core dump)
OpenCV版本和cv_bridge版本问题
FIX:
查看上方步骤,选择对应的opencv版本和cv_bridge版本,并修改CMakeLists.txt