系统:Ubuntu16.04 LST
ros版本:kinetic

安装 opencv 3.4.1

3.1 通过脚本下载并编译

压缩包为: opencv-3.4.1.tar.gz ,opencv_contrib-3.4.1.tar发发gz
本教程使用脚本一次性直接下载并编译安装
新建如下.sh脚本 install_opencv.sh:

#!/bin/bash
echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev  libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer-plugins-base-devel libgphoto2-dev
sudo apt-get install -y libavresample-dev gtk+-3.0
sudo apt-get update

echo "** Download opencv-3.4.1"
curl -L https://github.com/opencv/opencv/archive/3.4.1.tar.gz -o opencv-3.4.1.tar.gz
curl -L https://github.com/opencv/opencv_contrib/archive/3.4.1.tar.gz -o opencv_contrib-3.4.1.tar.gz
tar -zxvf opencv-3.4.1.tar.gz
tar -zxvf opencv_contrib-3.4.1.tar.gz

echo "** Building..."
cd opencv-3.4.1/
mkdir build
cd build
cmake -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.1/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_xfeatures2d=OFF ..
make -j8
sudo make install
sudo apt-get install -y python-opencv python3-opencv
echo "** Install opencv-3.4.1 successfully"
echo "** Bye :)"

运行 install_opencv.sh ,安装在home目录下

sudo sh install_opencv.sh

ubuntu16.04编译vins-mono_Ubuntu教程

3.2 测试

ubuntu16.04编译vins-mono_Ubuntu教程_02

安装 c++的非线性优化库ceres solver

本教程使用脚本一次性直接下载并编译安装
新建如下.sh脚本 install_ceres.sh:

#!/bin/bash
sudo apt-get install -y cmake libgoogle-glog-dev libatlas-base-dev libeigen3-dev libsuitesparse-dev
sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687
sudo apt-get update && sudo apt-get install -y libsuitesparse-dev

source ~/.bashrc
workdir=$PWD

if test ! -d ceres-solver ; then git clone https://github.com/ceres-solver/ceres-solver ; fi
cd ceres-solver
if test ! -d ceres-bin ; then mkdir ceres-bin ; fi
cd ceres-bin
if ! cmake .. ; then echo "ceres cmake init fail" ; exit 1 ; fi
if ! make -j4 ; then echo "ceres make fail" ; exit 1 ; fi
if ! sudo make install ; then echo "ceres make install fail" ; exit 1 ; fi

cd $workdir

运行 install_ceres.sh ,安装在home目录下

sudo sh install_ceres.sh

注意,如果安装失败有可能是因为eigen3库的问题,请查看log自行分析

如果是eigen3的问题(Could not find a configuration file for package “Eigen3” that is compatible with requested version),重新安装eigen3就可以了

git clone https://github.com/eigenteam/eigen-git-mirror
 
cd eigen-git-mirror
mkdir build
cd build
cmake ..
sudo make install
#after installation, the header file will be in /usr/local/include/eigen3/

然后,运行以下命令:

sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include 
创建ros工作空间

创建名称为catkin_ws 的工作空间,路径为 : ~/slam/catkin_ws/src

cd ~  #进入home目录

mkdir slam # 创建名为slam的文件夹

cd slam 

mkdir -p /catkin_ws/src  #新建catkin_ws/src 目录

cd catkin_ws/src

catkin_init_workspace

cd ..               #退到 catkin_ws 路径下

catkin_make         #编译

配置环境变量

echo "source ~/slam/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc #在终端内重新加载 .bashrc文件

ros package 路径包含有刚刚创建的工作空间目录

下载并编译相机SDK

6.1 下载

进入~/slam 下载小觅相机SDK

git clone https://github.com/slightech/MYNT-EYE-S-SDK.git

6.2 编译

cd MYNT-EYE-S-SDK  # 进入SDK文件夹
make init
make install
make samples
cd wrappers/ros
catkin_make

6.3 配置环境变量

echo "source ~/slam/MYNT-EYE-S-SDK/wrappers/ros/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc #在终端内重新加载 .bashrc文件

6.4 测试

插上相机运行如下命令,测试

roslaunch mynt_eye_ros_wrapper display.launch
下载并编译vins工程

7.1 下载

进入~/slam/catkin_ws/src 目录

cd ~/slam/catkin_ws/src  # 进入SDK文件夹
git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git

7.2 编译

编译 (在前面创建的工作空间之下)

cd ..         # 退到   ~/slam/catkin_ws 目录
catkin_make   # 在 ~/slam/catkin_ws 下编译
安装上述版本的ceres后后面编译会报错
error: ‘face::EigenFaceRecognizer’ has not been declared
             model_ = face::EigenFaceRecognizer::create(config.model_num_components,
                            ^~~~~~~~~~~~~~~~~~~
/home/star/rikirobot/catkin_ws/src/opencv_apps/src/nodelet/face_recognition_nodelet.cpp:476:28: error: ‘face::FisherFaceRecognizer’ has not been declared
             model_ = face::FisherFaceRecognizer::create(config.model_num_components,
                            ^~~~~~~~~~~~~~~~~~~~
/home/star/rikirobot/catkin_ws/src/opencv_apps/src/nodelet/face_recognition_nodelet.cpp:484:48: error: ‘create’ is not a member of ‘cv::face::LBPHFaceRecognizer’
             model_ = face::LBPHFaceRecognizer::create(config.lbph_radius,
                                                ^~~~~~
opencv_apps/CMakeFiles/opencv_apps.dir/build.make:494: recipe for target 'opencv_apps/CMakeFiles/opencv_apps.dir/src/nodelet/face_recognition_nodelet.cpp.o' failed
make[2]: *** [opencv_apps/CMakeFiles/opencv_apps.dir/src/nodelet/face_recognition_nodelet.cpp.o] Error 1
CMakeFiles/Makefile2:11736: recipe for target 'opencv_apps/CMakeFiles/opencv_apps.dir/all' failed
make[1]: *** [opencv_apps/CMakeFiles/opencv_apps.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j1" failed

可以参考下面博客解决:
https://blog.csdn.net/qq_41586768/article/details/107541917
https://zhuanlan.zhihu.com/p/158824514
大概思路是改用1.14.0版本,ps,该版本的ceres不需要重新安装上面的eigen3.

7.3 配置环境变量

echo "source ~/slam/catkin_ws/devel/setup.bash" >> ~/.bashrc # 写入 source 命令到.bashrc中
source ~/.bashrc #在终端内重新加载 .bashrc文件