ORB_SLAM编译过程记录

文章目录

    • 安装依赖
      • Pangolin
      • OpenCV
      • Eigen
    • 编译
    • 使用IDE——CLion
    • 遇到的问题
        • 编译报错:error: ‘usleep’ was not declared in this scope
        • 编译报错:error: static assertion failed: std::map must have the same value_type as its allocator
        • 运行闪退:GTK+ 2.x

换了台电脑,装上了刚发布的ubuntu 20.04,感觉界面漂亮了许多,也更流畅。不过N卡驱动装的不顺利,暂时用不上先放一边吧。。。

试试跑ORB_SLAM效果如何,顺便整理一下碰到的编译错误。
IDE是CLion

安装依赖

ORB_SLAM需要的依赖有:

  • Pangolin

Pangolin是一个用于管理OpenGL显示/交互和提取视频输入的可移植的轻量级快速开发库。它的核心是一个简单的OpenGl viewport管理器,可以帮助模块化3D可视化而不会增加其复杂性,并提供先进而直观的3D导航处理程序。Pangolin还提供了一种通过配置文件和ui集成来操纵程序变量的机制,并具有灵活的实时plotter,用于可视化图形数据。
Pangolin的理念是减少通常编写的可视化和与系统进行交互(通常基于图像和3D的)的样例代码,而不会影响性能。它还支持为多个平台编写write-once代码,目前包括Windows、Linux、OSX、Android和IOS。
Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input. At its heart is a simple OpenGl viewport manager which can help to modularise 3D visualisation without adding to its complexity, and offers an advanced but intuitive 3D navigation handler. Pangolin also provides a mechanism for manipulating program variables through config files and ui integration, and has a flexible real-time plotter for visualising graphical data.
The ethos of Pangolin is to reduce the boilerplate code that normally gets written to visualise and interact with (typically image and 3D based) systems, without compromising performance. It also enables write-once code for a number of platforms, currently including Windows, Linux, OSX, Android and IOS.

git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
cmake --build .

安装依赖GLEW
sudo apt install libglew-dev

  • OpenCV

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON ..

默认也是安装在/usr/local下,可通过CMAKE_INSTALL_PREFIX参数改变安装路径。
查看安装版本
pkg-config opencv --modversion

  • Eigen

Eigen是只有头文件的矩阵运算库
有两种安装方式

  1. 软件源
  2. 源码

编译

git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
chmod +x build.sh #添加可执行权限
./build.sh #执行编译脚本

看看这个编译脚本

echo "Configuring and building Thirdparty/DBoW2 ..."

# 编译DBoW2库
cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

# 编译g2o库
cd ../../g2o

echo "Configuring and building Thirdparty/g2o ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

cd ../../../

# 解压字典
echo "Uncompress vocabulary ..."

cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
cd ..

#编译ORB_SLAM2
echo "Configuring and building ORB_SLAM2 ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

使用IDE——CLion

使用IDE要注意

  1. IDE是通过CmakeList.txt文件编译项目,不包含上述shell脚本中三方库的安装,如果直接用IDE打开ORB_SLAM项目,运行会报错。也即需要先完成shell脚本中的前几个步骤,或者直接先执行一遍build.sh。
  2. 在写入口参数时注意使用绝对路径

遇到的问题

  1. 编译报错:error: ‘usleep’ was not declared in this scope

    System.h中添加头文件#include
  2. 编译报错:error: static assertion failed: std::map must have the same value_type as its allocator

    LoopClosing.h中修改:
//    typedef map,
//        Eigen::aligned_allocator > > KeyFrameAndPose;
    typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
            Eigen::aligned_allocator<std::pair<KeyFrame* const, g2o::Sim3> > > KeyFrameAndPose;
  1. 运行闪退:GTK+ 2.x

ORB_SLAM编译过程记录_第1张图片
重新编译安装OpenCV库,cmake添加WITH_GTK=ON

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_GTK=ON 
make
sudo make install
sudo apt install libgtk2.0-dev

添加cmake参数重新编译OpenCV时报错,Qt5core
sudo apt-get install qt5-defaul

你可能感兴趣的:(SLAM)