之前的slam环境是在Ubuntu14.04下的,最近电脑出了些问题,索性直接换到18.04版本。
Ubuntu14.04下的环境是根据《视觉SLAM十四讲 从理论到实践》书中的提示进行安装的。在Ubuntu18.04下安装有些库的安装和依赖改变,还是有一些坑的。
修改源Ubuntu 18.04的默认源1、输入命令修改sources.list文件,当然需要超级权限,所以要加sudo;
sudo gedit /etc/apt/sources.list #将国内源地址复制粘贴到文件中
编辑/etc/apt/sources.list文件。
2、在文件最前面添加以下条目(操作前请做好相应备份):
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
3、修改完成后,保存文件,警告什么的都不理,然后运行下面的命令。
sudo apt-get update
sudo apt-get upgrade
4、到此完成国内源更新。
5、附加其他源
需要的自己添加进sources.list文件里面就ok了。
阿里源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
cmake
sudo apt-get install cmake
cmake -version
>>3.10.2
版本有些低,更新需要更新一下。
$ sudo make update
$ make -v
>>GUN make 4.1
g++
首先是最基本的c++编译环境,需要安装g++,可以直接
sudo apt-get install g++
在Ubuntu14.04下这样安装是不会出现任何问题的,但是在Ubuntu18.04下,由于18.04默认安装的gcc和g++版本问题,在安装Sophus时会出现一个小问题,在下边安装Sophus时会提到。
vim
vim是一个很重要的文本编辑器。
$:sudo apt-get install vim
进入目录>vim>i>输入内容>Esc>:>w [文件名]>enter>:>wq>enter>ls查看(流程助记)
Eigen
线性代数库Eigen的安装不存在问题
sudo apt-get install libeigen3-dev
git
sudo apt-get install git
使用github上的源,下载起来很慢。可以在码云gitee.com上做相应的镜像下载,速度能快不少。
Sophus
Sophus的安装存在两个问题,一个是Sophus模板类和非模板类的区别,为了新手方便使用高博在十四讲中推荐的是非模板类的Sophus,需要将git到的Sophus回滚到a621ff版本;另一个就是由于编译器版本的不同,出现非模板类Sophus编译不过。
先贴上Ubuntu14.04下的安装过程,在对Ubuntu18.04的问题进行解决,Sophus只需要编译不需要安装。
git clone https://github.com/strasdat/Sophus.git
cd Sophus
git checkout a621ff
mkdir build
cd build
cmake ..
在ubuntu18.04下遇到的问题:
出现“unit_complex_.real() = 1.; unit_complex_.imag() = 0. ;"的错误
解决方法:在sophus/so2.cpp文件中,将
unit_complex_.real() = 1. ;
unit_complex_.imag() = 0. ;
改为
unit_complex_.real(1.) ;
unit_complex_.imag(0.) ;
然后重新编译即可。
或更换gcc,g++为以前的版本,
卸载gcc,g++
安装gcc5,g++5
OpenCV
先写上ubuntu18.04的不同。之前版本的ubuntu终端apt-get安装到的opencv是二系的,而在ubuntu18.04安装到的是3.2版本的,这一区别之前直接下载源码安装的三系,用到二系安装时才发现的不对。
下边是18.04下的安装方法:
apt-get安装OpenCV-3.2.0
sudo apt-get install libopencv-dev
而2系OpenCV需要从官网下载自己编译安装,
首先在官网https://opencv.org/下载OpenCV源码,解压。
安装依赖项
$:sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$:sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
# libjasper-dev 依赖项可能会需要单独附加
$:sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
$:sudo apt update
$: sudo apt install libjasper1 libjasper-dev#其中libjasper1是libjasper-dev的依赖包
$:git clone https://github.com/opencv/opencv.git
进入解压后的文件夹
cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-3.2.0\
-D OPENCV_EXTRA_MODULES_PATH=~/opencv-3.2.0/opencv_contrib/modules ..
make -j4
sudo make install
笔者之前先源码安装的opencv3.4.6,在发现apt-get安装的版本为3.2.0后,选择源码安装版本。
通过源码同时安装两个版本,需要将两个版本安装在不同位置,具体步骤可以自行百度。
参考链接https://blog.csdn.net/stjuliet/article/details/88674107
PCL
Ubuntu16.04之后安装pcl可以直接apt-get,
sudo apt-get install libpcl-dev pcl-tools
Pangolin
安装依赖项
sudo apt-get install libglew-dev libboost-dev libboost-thread-dev libboost-filesystem-dev
然后就是git下源码,编译安装
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake -DCPP11_NO_BOOST= 1 ..
make -j4
sudo make install
Ceres
Ceres依赖谷歌的日志和测试工具
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev libgoogle-glog-dev libgtest-dev
然后是git,编译安装
git clone https://github.com/ceres-solver/ceres-solver.git
cd ceres-solver
mkdir build
cd build
cmake ..
make -j4
sudo make install
g2o
在ubuntu18.04安装g2o与在14.04下安装的主要区别在于qt,18.04默认安装 qt5,
安装依赖项
sudo apt-get install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev
所需要的依赖项在下载的源码中 README.md 文件中有写
依旧是git,编译安装
git clone https://github.com/RainerKuemmerle/g2o
cd g2o
mkdir build
cd build
cmake ..
make -j4
sudo make install
DBoW3
git clone https://github.com/rmsalinas/DBow3.git
cd DBow3
mkdir build
cd build
cmake ..
make
sudo make install
作者:BeeGreen