ORB SLAM2在Ubuntu 16.04上的运行配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ORB SLAM2在Ubuntu 16.04上的运行配置相关的知识,希望对你有一定的参考价值。

安装依赖

安装OpenGL

1. 安装opengl Library
$sudo apt-get install libgl1-mesa-dev
2. 安装opengl utility
$sudo apt-get install libglu1-mesa-dev
3. 安装opengl utility toolkit
$sudo apt-get install freeglut3-dev

安装GLEW

$sudo apt-get install libglew-dev

安装boost

$sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev

安装编译基础库

$sudo apt-get install build-essential

安装Pangolin

1. 下载链接:https://github.com/stevenlovegrove/Pangolin
注:可以使用git进行clone,也可以直接download zip

2. 编译安装步骤
$cd Pangolin
$mkdir build
$cd build
$cmake ..
$make
$sudo make install
$make doc (生成文档)

安装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 libjasper-dev libdc1394-22-dev
源码下载链接:http://opencv.org/downloads.html (选择2.4.xx,3.x.xx版本都可以,新版本的ORBSLAM2已经支持OpenCV3.xx.xx)
编译安装步骤(以OpenCV2.4.xx为例):
$cd opencv-2.4.xx
$mkdir build
$cd build
$cmake ..
$make
$sudo make install

安装Eigen3

源码下载地址:http://eigen.tuxfamily.org/index.php?title=Main_Page
安装依赖:sudo apt-get install libxmu-dev libxi-dev
编译安装步骤:
$cd eigen
$mkdir build
$cd build
$cmake ..
$make
$sudo make install

安装BLAS and LAPACK库

sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev

编译ORB SLAM2

1. 下载源码

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

2. 编译

$cd ORB_SLAM2
$chmod +x build.sh
$./build.sh

3. 16.04上编译错误解决

1) OpenCV找不到

错误信息:

Configuring and building Thirdparty/DBoW2 ...
mkdir: cannot create directory ‘build’: File exists
-- OpenCV ARCH:
-- OpenCV RUNTIME:
-- OpenCV STATIC: OFF
CMake Warning at /home/melanie/tools/opencv-2.4.13/cmake/OpenCVConfig.cmake:163 (message):
Found OpenCV Windows Pack but it has not binaries compatible with your
configuration.

You should manually point CMake variable OpenCV_DIR to your build of OpenCV
library.
Call Stack (most recent call first):
CMakeLists.txt:27 (find_package)


CMake Error at CMakeLists.txt:27 (find_package):
Found package configuration file:

/home/melanie/tools/opencv-2.4.13/cmake/OpenCVConfig.cmake

but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
NOT FOUND.


-- Configuring incomplete, errors occurred!
See also "/home/melanie/source/SmartCar/ORM_SLAM2/ORB_SLAM2/Thirdparty/DBoW2/build/CMakeFiles/CMakeOutput.log".
make: *** No targets specified and no makefile found. Stop.

解决方案:
因为我的OpenCV用源码编译安装的路径默认是/usr/local/share/OpenCV/,所以在这里手动给cmake指定OpenCV的路径
修改build.sh如下:
cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOpenCV_DIR=/usr/local/share/OpenCV/
make

2)强制类型转换问题

错误信息:

/home/melanie/tools/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 <typename MatrixType>
class LinearSolverEigen: public LinearSolver<MatrixType>
{
public:
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;
typedef Eigen::Triplet<double> Triplet;
typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, SparseMatrix::Index> PermutationMatrix;

修改为:

template <typename MatrixType>
class LinearSolverEigen: public LinearSolver<MatrixType>
{
public:
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;
typedef Eigen::Triplet<double> Triplet;
typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> PermutationMatrix;

3)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

解决方案:

在source文件的开头增加include
#include <unistd.h>

需要增加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

4) CUDA错误

安装了CUDA的机器编译的时候会出现CUDA相关错误,修改build.sh如下:
cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOpenCV_DIR=/usr/local/share/OpenCV/ -DCUDA_USE_STATIC_CUDA_RUNTIME=OFF
make -j
......
echo "Configuring and building ORB_SLAM2 ..."

mkdir build
cd build
-cmake .. -DCMAKE_BUILD_TYPE=Release
+cmake .. -DCMAKE_BUILD_TYPE=Release -DCUDA_USE_STATIC_CUDA_RUNTIME=OFF
make -j

以上是关于ORB SLAM2在Ubuntu 16.04上的运行配置的主要内容,如果未能解决你的问题,请参考以下文章

ORB SLAM2运行中出现(ORB-SLAM2: Current Frame:14370): GLib-GIO-CRITICAL...的n问题

Ubuntu14.04 使用本地摄像头跑ORB SLAM2

ORB SLAM2 双目稀疏立体匹配学习

ORB SLAM2 双目稀疏立体匹配学习

ORB SLAM2运行步骤/怎样跑通orbslam2

ORB SLAM2运行步骤/怎样跑通orbslam2