Ubuntu16.04(ROS-kinetic)上编译ORB-SLAM2

1、前言

1. 网上有很多ORB-SLAM的编译安装教程,在我编译的过程中给我很大的帮助,但是我觉得我可能是遇到问题最多的人之一了,当完成ORB-SLAM2的编译之后,我觉得我编译的过程可以帮助初学者顺利的将ORB-SLAM2编译完成,希望对你有所帮助

2.这里需要说明一下,我默认你已经将所有的库文件都已安装成功

2、我的编译过程

2.1 Step1 下载源码

ORB-SLAM2源码地址

git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2

2.2 Step1 开始编译

2.2.1 g20与DBoW2的问题

$ cd ~/SLAM/src/ORB_SLAM2/Thirdparty/DBoW2/
$ mkdir build
$ cd build
$ cmake ..
$ make

$ cd ~/SLAM/src/ORB_SLAM2/Thirdparty/g2o/
$ mkdir build
$ cd build
$ cmake .. 
$ make

如果这里不进行安装的话,make的时候会显示
g20未进行编译,会显示错误如下
Ubuntu16.04(ROS-kinetic)上编译ORB-SLAM2_第1张图片DBoW2未进行编译,会显示错误如下
Ubuntu16.04(ROS-kinetic)上编译ORB-SLAM2_第2张图片
2.2.2 usleep未定义:

错误信息:

/home/melanie/source/SmartCar/ORM_SLAM2/ORB_SLAM2/src/Viewer.cc:159:28: error: ‘usleep’ was not declared in this scope
usleep(3000);
^
CMakeFiles/ORB_SLAM2.dir/build.make:494: recipe for target ‘CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o‘ failed
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o] Error 1
CMakeFiles/Makefile2:178: recipe for target ‘CMakeFiles/ORB_SLAM2.dir/all‘ failed
make[1]: *** [CMakeFiles/ORB_SLAM2.dir/all] Error 2
Makefile:83: recipe for target ‘all‘ failed
make: *** [all] Error 2

需要增加unistd.h的文件有:
Examples/Monocular/mono_euroc.cc
Examples/Monocular/mono_kitti.cc
Examples/Monocular/mono_tum.cc
Examples/RGB-D/rgbd_tum.cc
Examples/Stereo/stereo_euroc.cc
Examples/Stereo/stereo_kitti.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/System.cc
src/Tracking.cc
src/Viewer.cc

2.2.3 强制类型转换问题

错误信息:

/home/zp/catkin_ws_fusion/src/eigen/Eigen/src/Core/AssignEvaluator.h:817:3: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);
^
CMakeFiles/ORB_SLAM2.dir/build.make:350: recipe for target ‘CMakeFiles/ORB_SLAM2.dir/src/Optimizer.cc.o‘ failed
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/src/Optimizer.cc.o] Error 1
CMakeFiles/Makefile2:178: recipe for target ‘CMakeFiles/ORB_SLAM2.dir/all‘ failed
make[1]: *** [CMakeFiles/ORB_SLAM2.dir/all] Error 2
Makefile:83: recipe for target ‘all‘ failed
make: *** [all] Error 2

解决方案:

打开Thirdparty/g2o/g2o/solvers/linear_solver_eigen.h,将以下代码

template 
class LinearSolverEigen: public LinearSolver
{
  public:
    typedef Eigen::SparseMatrix SparseMatrix;
    typedef Eigen::Triplet Triplet;
    typedef Eigen::PermutationMatrix PermutationMatrix;
    /**

更改为

template 
class LinearSolverEigen: public LinearSolver
{
  public:
    typedef Eigen::SparseMatrix SparseMatrix;
    typedef Eigen::Triplet Triplet;
    typedef Eigen::PermutationMatrix PermutationMatrix;
    /**

3 欢迎交流

以上是我在编译ORB-SLAM2时候所遇到的问题,如果还有不尽之处,希望大家告知,不胜感激,互相帮助,一起探索SLAM

你可能感兴趣的:(SLAM)