orbslam2 安装与运行

目录

一、更新apt库,更新软件列表

二、安装git,用于从Github上克隆项目到本地

三、下载orbslam2源码

四、安装C++11编译器 cmake

五、安装Pangolin

六、安装Eigen3

七、安装opencv

 八、安装运行ORB-SLAM2

九、ROS环境下运行ORB_SLAM

9.1 添加环境变量

9.2 检验 ROS path 是否被识别

十、官方数据集跑ORB_SLAM2


一、更新apt库,更新软件列表

sudo apt-get update

二、安装git,用于从Github上克隆项目到本地

sudo apt-get install git

三、下载orbslam2源码

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

下载orbslam2之后,我们来看看这个文件夹里面有什么:

orbslam2 安装与运行_第1张图片

四、安装C++11编译器 cmake

sudo apt-get install cmake

五、安装Pangolin

Pangolin是对OpenGL进行封装的轻量级的OpenGL输入/输出和视频显示的库。可以用于3D视觉和3D导航的视觉图,可以输入各种类型的视频、并且可以保留视频和输入数据用于debug。

在安装pangolin之前,先安装依赖项

 sudo apt-get install libglew-dev
 
 sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
 
 sudo apt-get install libpython2.7-dev

Pangolin下载链接:https://github.com/stevenlovegrove/Pangolin

使用版本建议为V0.5,这样可以避免Eigen3报错。

cd Pangolin
mkdir build
cd build
cmake ..
make –j
sudo make install
  • cmake .. 的作用: ../CMakeLists.txt 文件作为起始点在当前目录中生成makefile
  • make 命令,在此之后执行,使用生成的makefile作为输入构建程序
  • make install:将程序安装至系统中。如果原始码编译无误,且执行结果正确,便可以把程序安装至系统预设的可执行文件存放路径。默认/usr/local/bin

报错解决:

ORB-SLAM2的安装与运行_ydongy的博客-CSDN博客_orbslam2安装运行

orbslam2 安装与运行_第2张图片

1、找到FindEigen3.cmake文件,/usr/share/cmake2.8/Modules
2、复制到自己这个的工程下
3、在工程的CMakeLists.txt里面。添加这句话:

 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

参考链接:https://blog.51cto.com/u_15127644/3362825

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})*******就是这句,加上就行了。这样cmake就会到你自己工程目录下去找FindEigen3.cmake了。
find_package(Eigen3)
if(NOT EIGEN3_FOUND)
  # Fallback to cmake_modules
  find_package(cmake_modules REQUIRED)
  find_package(Eigen REQUIRED)
  set(EIGEN3_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
  set(EIGEN3_LIBRARIES ${EIGEN_LIBRARIES})  # Not strictly necessary as Eigen is head only
  # Possibly map additional variables to the EIGEN3_ prefix.
else()
  set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif()
-----------------------------------
CMake Error: not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH
https://blog.51cto.com/u_15127644/3362825

使用低版本的Pangolin库出现的问题:

orbslam2 安装与运行_第3张图片

make -j  出现终端闪退问题  

解决办法: make -j4 ,4是自己电脑cpu线程数

make -j4后报错:

orbslam2 安装与运行_第4张图片

在Pangolin文件夹CMakeLists.txt中添加设置 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-pthread")

orbslam2 安装与运行_第5张图片

orbslam2 安装与运行_第6张图片

成功!!

orbslam2 安装与运行_第7张图片

orbslam2 安装与运行_第8张图片

orbslam2 安装与运行_第9张图片

六、安装Eigen3

sudo apt-get install libeigen3-dev

七、安装opencv

opencv官方下载地址:Releases - OpenCV

选择版本3.4.0,下载并解压

安装opencv之前必须安装libgtk2.0-dev and pkg-config后安装或者没有安装都会报错

sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release –D CMAKE_INSTALL_PREFIX=/usr/local ..
make 
sudo make install

在安装opencv的时候,会用:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
这这句话什么意思!
在build文件中输入:cmake -D CMAKE_BUILD_TYPE=RELEASE 
这样产生的makefile文件make生成的可执行文件就带有调试信息,供gdb和gdbserver使用了。CMAKE_BUILD_TYPE的值可以为Release或者Debug。

CMAKE_INSTALL_PREFIX=/usr/local ..
INSTALL 指令用于定义安装规则,安装的内容可以包括目标二进制、动态库、静态库以及
文件、目录、脚本等。 这里就是提前设置好编译到的路径!

 八、安装运行ORB-SLAM2

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

报错1:

orbslam2 安装与运行_第10张图片根据报错信息, 在 gapi_async_tesr.cpp 中添加:

#include

报错2:

orbslam2 安装与运行_第11张图片

参考:

https://blog.csdn.net/u014717398/article/details/110356066?ops_request_misc=&request_id=&biz_id=102&utm_term=OpenCV%20%3E%202.4.3%20not%20found.&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-3-110356066.142%5Ev47%5Epc_rank_34_default_2,201%5Ev3%5Eadd_ask&spm=1018.2226.3001.4187

orbslam2 安装与运行_第12张图片

orbslam2 安装与运行_第13张图片

报错3:

darren@PTY:~/ORB_SLAM2/build$ make -j4
[  6%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LocalMapping.cc.o
[  6%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/System.cc.o
[  9%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Tracking.cc.o
[ 12%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o
In file included from /home/darren/ORB_SLAM2/include/Frame.h:31,
                 from /home/darren/ORB_SLAM2/include/MapPoint.h:25,
                 from /home/darren/ORB_SLAM2/include/KeyFrame.h:24,
                 from /home/darren/ORB_SLAM2/include/LoopClosing.h:24,
                 from /home/darren/ORB_SLAM2/src/LoopClosing.cc:21:
/home/darren/ORB_SLAM2/include/ORBextractor.h:26:10: fatal error: opencv/cv.h: 没有那个文件或目录
   26 | #include 
      |          ^~~~~~~~~~~~~
In file included from /home/darren/ORB_SLAM2/include/Frame.h:31,
                 from /home/darren/ORB_SLAM2/include/MapPoint.h:25,
                 from /home/darren/ORB_SLAM2/include/KeyFrame.h:24,
                 from /home/darren/ORB_SLAM2/include/LocalMapping.h:24,
                 from /home/darren/ORB_SLAM2/src/LocalMapping.cc:21:
/home/darren/ORB_SLAM2/include/ORBextractor.h:26:10: fatal error: opencv/cv.h: 没有那个文件或目录
   26 | #include 
      |          ^~~~~~~~~~~~~
compilation terminated.
compilation terminated.
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/build.make:104:CMakeFiles/ORB_SLAM2.dir/src/LocalMapping.cc.o] 错误 1
make[2]: *** 正在等待未完成的任务....
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/build.make:118:CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o] 错误 1
In file included from /home/darren/ORB_SLAM2/include/KeyFrame.h:28,
                 from /home/darren/ORB_SLAM2/include/MapPoint.h:24,
                 from /home/darren/ORB_SLAM2/include/FrameDrawer.h:25,
                 from /home/darren/ORB_SLAM2/include/Viewer.h:25,
                 from /home/darren/ORB_SLAM2/include/Tracking.h:28,
                 from /home/darren/ORB_SLAM2/src/Tracking.cc:22:
/home/darren/ORB_SLAM2/include/ORBextractor.h:26:10: fatal error: opencv/cv.h: 没有那个文件或目录
   26 | #include 
      |          ^~~~~~~~~~~~~
compilation terminated.
In file included from /home/darren/ORB_SLAM2/include/KeyFrame.h:28,
                 from /home/darren/ORB_SLAM2/include/MapPoint.h:24,
                 from /home/darren/ORB_SLAM2/include/FrameDrawer.h:25,
                 from /home/darren/ORB_SLAM2/include/Viewer.h:25,
                 from /home/darren/ORB_SLAM2/include/Tracking.h:28,
                 from /home/darren/ORB_SLAM2/include/System.h:29,
                 from /home/darren/ORB_SLAM2/src/System.cc:23:
/home/darren/ORB_SLAM2/include/ORBextractor.h:26:10: fatal error: opencv/cv.h: 没有那个文件或目录
   26 | #include 
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/build.make:90:CMakeFiles/ORB_SLAM2.dir/src/Tracking.cc.o] 错误 1
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/build.make:76:CMakeFiles/ORB_SLAM2.dir/src/System.cc.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:95:CMakeFiles/ORB_SLAM2.dir/all] 错误 2
make: *** [Makefile:91:all] 错误 2
darren@PTY:~/ORB_SLAM2/build$ 

orbslam2 安装与运行_第14张图片

 参考: 

https://blog.csdn.net/u014717398/article/details/110356066?ops_request_misc=&request_id=&biz_id=102&utm_term=OpenCV%20%3E%202.4.3%20not%20found.&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-3-110356066.142%5Ev47%5Epc_rank_34_default_2,201%5Ev3%5Eadd_ask&spm=1018.2226.3001.4187

报错4:

orbslam2 安装与运行_第15张图片

在出错程序的头文件中加入

 #include 

报错5:

orbslam2 安装与运行_第16张图片

ORB-SLAM2编译错误_嵙杰的博客-CSDN博客

报错6:

orbslam2 安装与运行_第17张图片

这是由于opencv高版本弃用CV_LOAD_IMAGE_UNCHANGED这一参数导致的
解决方法:
CV_LOAD_IMAGE_UNCHANGED换成IMREAD_UNCHANGED
并在代码头文件下面添加命名空间using namespace cv;

九、ROS环境下运行ORB_SLAM

9.1 添加环境变量

sudo gedit ~/.bashrc   //查看bashrc文件

在bashrc文件后后面加这句:

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/darren/ORB_SLAM2/Examples/ROS/ORB_SLAM2

source ~/.bashrc   //使环境变量生效

9.2 检验 ROS path 是否被识别

echo $ROS_PACKAGE_PATH

 然后执行下列三条命令:

chmod +x build_ros.sh
./build_ros.sh

报错1:

/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv' /usr/lib/x86_64-linux-gnu/libboost_system.so: 无法添加符号: DSO missing from command line collect2: error: ld returned 1 exit status CM

解决办法:

/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol ‘_ZN5boost6system1_人生不过一闭一睁的博客-CSDN博客

十、官方数据集跑ORB_SLAM2

数据集:Computer Vision Group - Dataset Download

下载rgbd_dataset_freiburg1_xyz即可,解压

./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml PATH_TO_SEQUENCE_FOLDER

问题1: 

orbslam2 安装与运行_第18张图片

解决方法:

https://blog.csdn.net/hy13684802853/article/details/83343093

https://blog.csdn.net/weixin_38493195/article/details/117454809


 

问题2:画面出来之后2s左右突然闪退

New Map created with 86 points
double free or corruption (out)
已放弃 (核心已转储)

解决方法:

高翔slam14 project 出现double free or corruption (out)问题解决 - 走看看
Ubuntu18.04下运行ORB-SLAM2踩坑记_梧桐雪的博客-CSDN博客

orbslam2 安装与运行_第19张图片

删除掉ORBSLAM的cmakelists中的 -march=native 以及 g2o 的cmakelists中的-march=native重新执行ORBSLAM目录下的./build.sh 后就可以正常跑了。

运行成功:

orbslam2 安装与运行_第20张图片

如果运行rgbd模式,需要用 associate.py 脚本手动对齐depth和rgbd时间戳

python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt

你可能感兴趣的:(SLAM,orbslam2)