ORB-SLAM3 安装运行

ORB-SLAM3安装运行

运行环境:Ubuntu18.04

安装依赖

下载ORB-SLAM3源码

git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git  ORB_SLAM3

Pangolin安装

git clone https://github.com/stevenlovegrove/Pangolin.git

根据github上说明,安装Pangolin所需要的依赖

  • C++11
  • OpenGL (Desktop / ES / ES2)
    • (lin) sudo apt install libgl1-mesa-dev
  • Glew
    • (deb) sudo apt install libglew-dev
  • CMake (for build environment)
    • (deb) sudo apt install cmake

Recommended Dependencies

  • Python2 / Python3, for drop-down interactive console
    • (deb) sudo apt install libpython2.7-dev
  • Wayland
    • pkg-config: sudo apt install pkg-config
    • Wayland and EGL:sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols

sudo apt-get install cmake libeigen3-dev libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev //g2o的依赖项
sudo apt-get install libboost-dev //DBoW2的依赖项

编译安装Pangolin

cd Pangolin
mkdir build
cd build
cmake ..
cmake --build .

OpenCV(要求>3.0) 安装步骤省略

安装boost库

官方网站为https://www.boost.org/ ,下载后并解压,执行 sudo ./bootstrap.shsudo ./b2 install

安装libssl-dev sudo apt-get install libssl-dev

ORB-SLAM3编译和安装

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

直接执行编译脚本可能比较吃内存,过程缓慢,也可以逐条执行build.sh中的指令

# build.sh中的内容如下
echo "Configuring and building Thirdparty/DBoW2 ..."

cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

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 ..

echo "Configuring and building ORB_SLAM3 ..."

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

编译错误问题

  • Eigen版本问题

    修改ORB_SLAM3/Thirdparty/g2o/CMakeLists.txt 中版本号

    将第72行 FIND_PACKAGE(Eigen3 3.1.0 REQUIRED)

    改为 FIND_PACKAGE(Eigen3 REQUIRED)

  • make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:89:CMakeFiles/ORB_SLAM3.dir/src/LocalMapping.cc.o] 错误 1
    
    make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:349:CMakeFiles/ORB_SLAM3.dir/src/CameraModels/KannalaBrandt8.cpp.o] 错误 1
    

    在报错的文件里,如KannalaBrandt8.cpp,LocalMapping.cc

    在include之后加上如下代码

    namespace cv
    {
    	template<typename _Tp, int m, int n> static inline
    	Matx<_Tp, m, n> operator / (const Matx<_Tp, m, n> &a, float alpha)
    	{
    		return Matx<_Tp, m, n>(a, 1.f / alpha, Matx_ScaleOp());
    	}
    }
    

数据集测试

使用TUM数据集,https://vision.in.tum.de/data/datasets/rgbd-dataset/download

单目

./Examples/Monocular/mono_tum_vi Vocabulary/ORBvoc.txt Examples/Monocular/TUM_512.yaml ./data/dataset-corridor5_512_16/mav0/cam0/data Examples/Monocular/TUM_TimeStamps/dataset-corridor5_512.txt  dataset-corridor5_512_mono# 其中数据集路径随便指定,这里将数据集放在当前路径下data文件夹里

RGB-D

./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml ./data/rgbd_dataset_freiburg1_desk

运行截图如下
ORB-SLAM3 安装运行

在线测试

在线测试需要安装ROS,请自行百度安装```

首先编译

  1. 将源码中的 Examples/ROS/ORB_SLAM3 路径添加到ROS_PACKAGE_PATH环境变量中

    # 打开 .bashrc file:gedit ~/.bashrc# 添加路径 , 
    # 其中PATH是本机的具体路径export
     ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:“PATH”/ORB_SLAM3/Examples/ROS
    
  2. 执行build_ros.sh文件

    chmod +x build_ros.sh./build_ros.sh
    

如果编译报错,大概就是 /ros/noetic/share 这个路径没有ORB_SLAM3的软连接,执行如下命令即可解决

sudo ln -s "PATH"/ORB_SLAM3/Examples/ROS/ORB_SLAM3 /opt/ros/noetic/share/ORB_SLAM3

在线运行需要安装usb_cam软件包

sudo apt-get install ros-noetic-usb-cam

使用笔记本摄像头运行ORB-SLAM3

首先修改源码,进入目录/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src,修改ros_mono.cc文件

// 其中/usb_cam/image_raw为本机摄像头的topic,
// 使用roslaunch usb_cam usb_cam-test.launch测试摄像头时,
// 可用rostopic list查看所有topic
ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);

分别打开三个终端依次运行如下命令

roscore
roslaunch usb_cam usb_cam-test.launch
# 以单目摄像头运行ORB-SLAM3
rosrun ORB_SLAM3 Mono /home/jxf/ORB_SLAM3/Vocabulary/ORBvoc.txt /home/jxf/ORB_SLAM3/Examples/ROS/ORB_SLAM3/Asus.yaml

使用外接鱼眼摄像头运行ORB-SLAM3

本次实验中,使用210度鱼眼摄像头(购于某宝,100多rmb)

电脑连接usb摄像头后,首先进入目录 /opt/ros/melodic/share/usb_cam/launch 修改usb_cam-test.launch 文件,将其中/dev/video1(笔记本自带摄像头)修改为/dev/video2,

然后进入目录/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src,修改ros_mono.cc文件

//其中/usb_cam/image_raw为本机摄像头的topic,
//使用roslaunch usb_cam usb_cam-test.launch测试摄像头时,
//可用rostopic list查看所有topic
ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);

然后就可以运行了,分别打开三个终端依次运行如下命令

roscore
roslaunch usb_cam usb_cam-test.launch
# 以单目摄像头运行ORB-SLAM3
rosrun ORB_SLAM3 Mono /home/jxf/ORB_SLAM3/Vocabulary/ORBvoc.txt /home/jxf/ORB_SLAM3/Examples/ROS/ORB_SLAM3/Asus.yaml

运行截图如下
ORB-SLAM3 安装运行

如果ROS运行ORB-SLAM3报错Segmentation fault (core dumped),则可能是因为

ORB_SLAM3/Thirdparty/DBoW2/CMakeLists.txt 和ORB_SLAM3/CMakeLists.txt指定的是opencv 4. 但是ORB_SLAM3/Examples/ROS/ORB_SLAM3/CMakeLists.txt中指定的却是opencv 3,修改前者CMakeLists.txt指定opencv版本为3,

set(OpenCV_DIR "/usr/local/opencv/3.4.11/share/OpenCV") ,最好修改所有的CMakeList,这样会使OpenCV版本保持一致

上一篇:log4j 日志限制大小 拆分成30个 不按日期分日志 按大小拆分 按日期产生


下一篇:微信小程序日常开发中常遇到的错误代码