1.安装WSL子系统
为了避免安装Windows+Linux双系统的麻烦和资源浪费,安装Windows版本的Linux系统即WSL子系统。
1.1 默认安装
一般情况下默认安装WSL子系统的安装路径在C盘。
0.进入Windows PowerShell界面
1.注销Ubuntu-18.04(因之前安装过的Ubuntu-18.04配置有些问题)
wsl --unregister Ubuntu-18.04
2.安装Ubuntu-20.04(默认安装wsl1)
wsl --install -d Ubuntu-20.04
3.将wsl1升级到wsl2
wsl --set-version Ubuntu-20.04 2
4.查看当前wsl版本
wsl -l -v
5.进入WSL子系统并更新
sudo apt-get update
sudo apt-get upgrade
6.更换WSL子系统镜像源
备份并更换sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
将sources.list内容更换如下:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#参考链接:Ubuntu 20.04 国内源_哈哈虎的博客-CSDN博客_阿里云ubuntu源
#这里是Ubuntu-20.04的镜像源,Ubuntu-18.04镜像源有所不同
更换完sources.list内容后更新系统
sudo apt-get update
sudo apt-get upgrade
1.2 自定义安装
默认安装好WSL子系统后,如果C盘不够用想把WSL子系统重新安装到其他磁盘,可将WSL子系统从默认安装的C盘转移到自定义的其他磁盘(比如D盘)。
1.查看WSL分发版本
在Windows PowerShell中输入如下命令:
wsl -l --all -v
2.导出分发版为tar文件到d盘
wsl --export Ubuntu-20.04 d:\wsl-ubuntu20.04.tar |
3.注销当前分发版
wsl --unregister Ubuntu-20.04 |
4.重新导入并安装WSL在d:\wsl-ubuntu20.04
wsl --import Ubuntu-20.04 d:\wsl-ubuntu20.04 d:\wsl-ubuntu20.04.tar --version 2 |
5.设置默认登陆用户为安装时用户名
ubuntu2004 config --default-user Username |
6.删除tar文件(可选)
del d:\wsl-ubuntu20.04.tar |
7.结束
经过以上操作后,就将WSL的默认安装目录迁移到D:\wsl-ubuntu20.04目录下了。此目录即为WSL的跟文件系统。
#参考链接WSL修改默认安装目录到其他盘 - 闲云-野鹤 - 博客园
2.安装配置SLAM依赖库
2.1 SLAM依赖库及其作用
2.1.1 SLAM依赖库
SLAM需要安装配置的库主要有:cmake DBow3 Pangolin Sophus ceres-solver g2o gtsam octomap opencv opencv_contrib pcl vtk
在《视觉SLAM十四讲》各章节分布如下:
ch2 概述,cmake基础
ch3 Eigen,三维几何
ch4 Sophus,李群与李代数
ch5 OpenCV,图像与相机模型
ch6 Ceres and g2o,非线性优化
ch7 特征点法视觉里程计
ch8 直接法视觉里程计
ch9 project
ch10 Ceres and g2o,后端优化1
ch11 g2o and gtsam,位姿图优化
ch12 DBoW3,词袋方法
ch13 稠密地图构建
2.1.2 SLAM依赖库作用
各个库的主要作用
编译相关库:cmake
线性代数:eigen
李群和李代数:Sophus
图像处理:opencv、opencv_contrib
非线性优化:ceres、g2o
位姿图优化:gtsam
视觉检索:DBoW3
3D地图创建:octomap
3D绘图:Pangolin
点云处理:pcl
可视化:vtk
#参考链接:slam 十四讲 环境配置_xiaohu的博客-CSDN博客_slam环境配置
2.2 SLAM依赖库安装过程
2.2.1 安装相应的cmake编译器
#安装gcc、g++ 、libc和make等基础库
sudo apt-get install build-essential
#安装相应的cmake编译器
sudo apt-get install automake autoconf g++ libtool cmake
#或者获取cmake最新版本源码
git clone https://gitlab.kitware.com/cmake/cmake.git
#或者wget获取cmake-3.22.2.版本源码
wget https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2.tar.gz
tar -xzvf cmake-3.22.2.tar.gz
cd cmake-3.22.2
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.2 SLAM各个依赖库的依赖库
#Pangolin依赖库
sudo apt-get install libglew-dev libpython2.7-dev libboost-dev libboost-thread-dev libboost-filesystem-dev -y
#opencv依赖库
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
#pcl依赖库
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev
#ceres依赖库
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.4 libgflags-dev libgoogle-glog-dev libgtest-dev
#g2o依赖库
sudo apt-get install libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3.1.4 libcholmod3.0.6
#otomap依赖库
sudo apt-get install build-essential cmake doxygen libqt4-dev libqt4-opengl-dev qt4-qmake libqglviewer-dev-qt4
#gtsam依赖库
sudo apt-get install cmake
sudo apt-get install libboost-dev
sudo apt-get install libtbb-dev
sudo apt-get install mkl-xxx
#安装boost库
sudo apt-get install mpi-default-dev #安装mpi库
sudo apt-get install libicu-dev #支持正则表达式的UNICODE字符集
sudo apt-get install python-dev #需要python的话
sudo apt-get install libbz2-dev #如果编译出现错误:bzlib.h: No such file or directory
sudo apt-get install libboost-dev
2.2.3 安装eigen库
suo apt-get install libeigen3-dev
# it clone获取eigen最新源码
git clone libeigen / eigen · GitLab
cd eigen
#或者wget获取eigen最新源码
wget https://gitlab.kitware.com/cmake/cmake/-/archive/master/cmake-master.zip
unzip cmake-master.zip
cd cmake-master
#或者wget获取eigen3.4.0稳定版本源码
#wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip
unzip eigen-3.4.0.zip
cd eigen-3.4.0.zip
mkdir build && cd build && cmake .. && make -j6 && sudo make install
sudo updatedb
locate eigen3
2.2.4 安装Sophus库
# git clone获取Sophus最新源码
git clone http://github.com/strasdat/Sophus.git
git checkout a621ff
cd Sophus
# 或者wget获取Sophus最新源码
wget https://github.com/strasdat/Sophus/archive/refs/heads/master.zip
unzip Sophus-master.zip
cd Sophus-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.5 安装g2o库
# git clone获取g2o最新源码
git clone https://github.com/RainerKuemmerle/g2o.git
cd g2o
# 或者wget获取g2o最新源码
wget https://github.com/RainerKuemmerle/g2o/archive/refs/heads/master.zip
unzip g2o-master.zip
cd g2o-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.6 安装ceres库
# git clone获取ceres最新源码
git clone https://github.com/ceres-solver/ceres-solver.git
cd ceres-solver
# 或者wget获取ceres最新源码
wget https://github.com/ceres-solver/ceres-solver/archive/refs/heads/master.zip
unzip ceres-solver-master.zip
cd ceres-solver-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.7 安装Pangolin库
# git clone获取Pangolin最新源码
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
# 或者wget获取Pangolin最新源码
wget https://github.com/stevenlovegrove/Pangolin /archive/refs/heads/master.zip
unzip Pangolin-master.zip
cd Pangolin-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.8 安装octomap库
# git clone获取octomap最新源码
git clone https://github.com/OctoMap/octomap.git
cd octomap
# 或者wget获取octomap最新源码
wget https://github.com/OctoMap/octomap/archive/refs/heads/master.zip
unzip octomap-master.zip
cd octomap-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.9 安装VTK库
# git clone获取vtk最新源码
git clone VTK / VTK · GitLab
cd vtk
# 或者wget获取vtk最新源码
wget Sign in · GitLab
unzip vtk-master.zip
cd vtk-master
# 或者wget获取VTK-9.1.0版本源码
wget https://www.vtk.org/files/release/9.1/VTK-9.1.0.tar.gz
tar -zxvf VTK-9.1.0.tar.gz
cd VTK-9.1.0
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.10 安装opencv+opencv_contrib库
# git clone获取opencv+opencv_contrib最新源码
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd opencv
#或者wget下载opencv+opencv_contrib最新版本源码
wget https://github.com/opencv/opencv/archive/refs/heads/4.x.zip
wget wget https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip
unzip opencv4.x.zip
unzip opencv_contrib4.x.zip
cd opencv4.x
#或者wget下载opencv+opencv_contrib4.5.5版本源码
wget https://github.com/opencv/opencv/archive/4.5.5.zip
wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.5.zip
unzip opencv4.5.5.zip
unzip opencv_contrib4.5.5.zip
cd opencv4.5.5
mkdir build && cd build && sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH= ../../opencv_contrib/modules/ -D WITH_VTK=ON -D BUILD_EXAMPLES=OFF -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_IPP=ON -D WITH_OPENGL=ON -D OPENCV_ENABLE_NONFREE=ON -D WITH_EIGEN=ON .. && make -j6 && sudo make install
/**
mkdir build && cd build
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH= ../../opencv_contrib/modules/ -D WITH_VTK=ON -D BUILD_EXAMPLES=OFF -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_IPP=ON -D WITH_OPENGL=ON -D OPENCV_ENABLE_NONFREE=ON -D WITH_EIGEN=ON ..
make -j6 && sudo make install
**/
2.2.11 安装DBow3库
# git clone获取DBow3最新源码
git clone https://github.com/rmsalinas/DBow3.git
cd DBow3
#或者wget下载DBow3最新版本源码
wget https://github.com/rmsalinas/DBow3/archive/refs/heads/master.zip
unzip DBow3-master.zip
cd DBow3-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.12 安装pcl库
#apt命令安装pcl库
sudo apt install libpcl-dev
# 或者git clone获取pcl最新源码
git clone https://github.com/PointCloudLibrary/pcl.git
cd pcl-master
#或者wget下载pcl最新版本源码
wget https://github.com/PointCloudLibrary/pcl/archive/refs/heads/master.zip
unzip pcl-master.zip
cd pcl-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
2.2.13 安装gtsam库
# 或者git clone获取gtsam最新源码
git clone Bitbucket
#或者
git clone https://github.com/borglab/gtsam.git
cd gtsam
#或者wget下载gtsam最新版本源码
wget https://github.com/borglab/gtsam/archive/refs/heads/master.zip
unzip gtsam-master.zip
cd gtsam-master
mkdir build && cd build && cmake .. && make -j6 && sudo make install
3.下载SLAM开发相关源码
#《视觉SLAM十四讲》第一版源码
git clone https://github.com/gaoxiang12/slambook.git
或者
wget https://github.com/gaoxiang12/slambook/archive/refs/heads/master.zip
unzip slambook-master.zip
#《视觉SLAM十四讲》第二版源码
git clone https://github.com/gaoxiang12/slambook2.git
或者
wget https://github.com/gaoxiang12/slambook2/archive/refs/heads/master.zip
unzip slambook2-master.zip
#ORB-SLAM3源码
git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git
或者
wget https://github.com/UZ-SLAMLab/ORB_SLAM3/archive/refs/heads/master.zip
unzip ORB_SLAM3-master.zip
#其他典型的SLAM方案源码地址如下表所示
方案名称 | 传感器形式 | 地址 |
MonoSLAM | 单目 | https://github.com/hanmekim/SceneLib2 |
PTAM | 单目 | http://www.robots.ox.ac.uk/~gk/PTAM/ |
ORB-SLAM | 单目为主 | http://webdiis.unizar.es/~raulmur/orbslam/ |
LSD-SLAM | 单目为主 | http://vision.in.tum.de/research/vslam/lsdslam |
SVO | 单目 | https://github.com/uzh-rpg/rpg_svo |
DTAM | RGB-D | https://github.com/anuranbaka/OpenDTAM |
DVO | RGB-D | https://github.com/tum-vision/dvo_slam |
DSO | 单目 | https://github.com/JakobEngel/dso |
RTAB-MAP | 双目/RGB-D | https://github.com/introlab/rtabmap |
RGBD-SLAM-V2 | RGB-D | https://github.com/felixendres/rgbdslam_v2 |
Elastic Fusion | RGB-D | https://github.com/mp3guy/ElasticFusion |
Hector SLAM | 激光 | http://wiki.ros.org/hector_slam |
GMapping | 激光 | http://wiki.ros.org/gmapping |
OKVIS | 多目+IMU | https://github.com/ethz-asl/okvis |
ROVIO | 单目+IMU | https://github.com/ethz-asl/rovio |
4.SLAM依赖库编译问题
0.SLAM依赖库编译顺序和编译快慢的问题
由于有些SLAM依赖库编译有相互依赖关系,所以是有编译顺序的。比如eigen,VTK和opencv+opencv_contrib编译的顺序应该是:eigen,VTK和opencv+opencv_contrib。SLAM依赖库推荐编译顺序为:cmake eigen DBow3 Pangolin Sophus ceres-solver g2o vtk opencv+opencv_contrib octomap pcl gtsam。此外有些库编译比较慢最好下班后编译:Sophus,VTK(超过5个小时),pcl.
1.cmake编译报错
由于编译某些依赖库报错说编译器版本太低,所以升级gcc/g++和cmake版本。
官网下载cmake-3.22.1.tar.gz,将压缩文件解压在/mnt/d/slam14/wsl_libs/目录下:
cd cmake-3.22.1 && ./bootstrap安装cmake报错“The C++ compiler does not support C++11 (e.g. std::unique_ptr).”
这个错误的原因是cmake的根目录被放在一个mounted directory之下,因此解決方法就是把cmake根目录移到其它非mounted directory下(比如wsl根目录下),然后重新執行./bootstrap即可。
2.opencv+opencv_contrib编译报错
由于编译opencv+opencv_contrib需要先编译eigen和VTK,故eigen和VTK版本要和opencv+opencv_contrib版本匹配。(编译命令:sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH= ../../opencv_contrib/modules/ -D WITH_VTK=ON -D BUILD_EXAMPLES=OFF -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_IPP=ON -D WITH_OPENGL=ON -D OPENCV_ENABLE_NONFREE=ON -D WITH_EIGEN=ON ..)
由于eigen版本不匹配编译报错如下:“
[ 38%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o
In file included from /usr/local/include/eigen3/Eigen/Core:19,
from /mnt/d/slam14/wsl_libs/opencv-4.x/modules/core/include/opencv2/core/private.hpp:70,
from /mnt/d/slam14/wsl_libs/opencv-4.x/modules/core/src/precomp.hpp:59,
from /mnt/d/slam14/wsl_libs/opencv-4.x/modules/core/src/alloc.cpp:43:
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:667:2: error: #error This compiler appears to be too old to be supported by Eigen
667 | #error This compiler appears to be too old to be supported by Eigen
// The macros EIGEN_HAS_CXX?? defines a rough estimate of available c++ features
// but in practice we should not rely on them but rather on the availability of
// individual features as defined later.
// This is why there is no EIGEN_HAS_CXX17.
#if EIGEN_MAX_CPP_VER<14 || EIGEN_COMP_CXXVER<14 || (EIGEN_COMP_MSVC && EIGEN_COMP_MSVC < 1900) || \
(EIGEN_COMP_ICC && EIGEN_COMP_ICC < 1500) || (EIGEN_COMP_NVCC && EIGEN_COMP_NVCC < 80000) || \
(EIGEN_COMP_CLANG && ((EIGEN_COMP_CLANG<309) || (defined(__apple_build_version__) && (__apple_build_version__ < 9000000)))) || \
(EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<51)
#error This compiler appears to be too old to be supported by Eigen
#endif“
解决的方法是将eigen3.4.9最新版本卸载掉,回退安装eigen3.4.0稳定版本,然后再编译opencv+opencv_contrib即可。(此问题比较麻烦,研究了两周才解决)