怎么在ubuntu下装ORB-SLAM2,并用单目摄像头实时跑起来

最新的是ORB-SLAM2,https://github.com/raulmur/ORB_SLAM2(支持单目、双目和RGB-D接口,最好参照官网安装)

安装必备软件:为了方便.最好先把要下载的库先在windows下下载好(注意下载的版

本).不装在系统盘



(1)更新apt库

sudo apt-get update

(2)安装Git

sudo apt-get install git

(3)安装cmake

sudo apt-get install cmake


(4)安装Pangolin (for visualization and user interface:可视化与用户界面)

Pangolin网址:https://github.com/stevenlovegrove/Pangolin


安装依赖
a、opengl: 
b、GLEW:
sudo apt-get install libglew-dev

c、Boost:

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

d、Python2/Python3:

sudo apt-get install libpython2.7-dev

e、编译基础库

sudo apt-get install build-essential

终端里输入

cd Pangolinmkdir build
cd build
cmake -DCPP11_NO_BOOST=1 ..
make -j 
(建议不要使用make -j,使用make。如果用make -j是使用多处理器编译,可能造成死机)


(5)安装OpenCV (manipulate images and features: 操纵图像和特征点)

安装依赖:

 

a、编译器相关:
sudo apt-get install build-essential

b、必须依赖:

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev
libavformat-dev libswscale-dev

c、可选安装:

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

安装OpenCV: 

a、官网下载OpenCV 2.4.11 for Linux下载地址,解压到Ubuntu中 

b、进入OpenCV文件夹,配置工程
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

c、编译

make
sudo make install

(6)安装Eigen We use modified versions of theDBoW2 library to perform place recognition--进行位置识别 and g2o library to perform non-linear optimizations--进行非线性优化. Both modified libraries (which are BSD) are included in theThirdparty folder.
Eigen下载地址,进入到在解压后的Eigen文件夹(例如eigen-eigen-07105f7124f9)下

mkdir build
cd build
cmake ..
make
sudo make install

(7)安装BLAS and LAPACK库

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

ROS (optional)

We provide some examples to process the live input of a monocular, stereo or RGB-D camera using ROS. Building these examples is optional. In case you want to use ROS, a version Hydro or newer is needed.


其实build.sh就是前面第三方库的编译+ORB_SLAM2的编译,以后可以自己写一个 类似的终端命令脚本,就不需要每次编译都手敲一遍。如果发现编译出错,尽量从github或者官网上面git clone源码,里面有很多issus可供参考。


3.安装ORB_SLAM: 
(1)Clone the repository:

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

(2)编译:我们提供一个脚本build.sh建立第三方库和orb-slam2。请确保您已安装所有所需的依赖项

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


  • ORB-SLAM2最后编译遇到的问题

1)强制类型转换问题

错误信息:

/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' failedmake[2]: *** [CMakeFiles/ORB_SLAM2.dir/src/Optimizer.cc.o] Error 1CMakeFiles/Makefile2:178: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failedmake[1]: *** [CMakeFiles/ORB_SLAM2.dir/all] Error 2Makefile:83: recipe for target 'all' failedmake: *** [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 SparseMatrix::Index> PermutationMatrix;

修改为:

template

class LinearSolverEigen: public LinearSolver

{ public:

typedef Eigen::SparseMatrix SparseMatrix;

typedef Eigen::Triplet Triplet;

typedef Eigen::PermutationMatrix int> PermutationMatrix;

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' failedmake[2]:

*** [CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o]

Error 1CMakeFiles/Makefile2:178: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failedmake[1]: *** [CMakeFiles/ORB_SLAM2.dir/all]

Error 2Makefile:83: recipe for target 'all' failed

make: *** [all] Error 2

解决方案:

在source文件的开头增加include#include

需要增加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.测试ORB_SLAM2

(1)官网下载测试数据集

 下载内存较大,最好用硬盘下好

Monocular 实例

TUM 数据集

  1. Download a sequence from http://vision.in.tum.de/data/datasets/rgbd-dataset/download and uncompress it.
  2. Execute the following command. Change TUMX.yaml to TUM1.yaml,TUM2.yaml or TUM3.yaml for freiburg1, freiburg2 and freiburg3 sequences respectively. Change PATH_TO_SEQUENCE_FOLDERto the uncompressed sequence folder.
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml PATH_TO_SEQUENCE_FOLDER

KITTI 数据集

  1. Execute download the dataset (grayscale images) from  http://www.cvlibs.net/datasets/kitti/eval_odometry.php
  2. e the following command. Change KITTIX.yaml by KITTI00-02.yaml, KITTI03.yaml or KITTI04-12.yaml for sequence 0 to 2, 3, and 4 to 12 respectively. Change PATH_TO_DATASET_FOLDER to the uncompressed dataset folder. Change SEQUENCE_NUMBER to 00, 01, 02,.., 11.
./Examples/Monocular/mono_kitti Vocabulary/ORBvoc.txt Examples/Monocular/KITTIX.yaml PATH_TO_DATASET_FOLDER/dataset/sequences/SEQUENCE_NUMBER

Stereo 实例

KITTI 数据集

  1. Download the dataset (grayscale images) from http://www.cvlibs.net/datasets/kitti/eval_odometry.php
  2. Execute the following command. Change KITTIX.yamlto KITTI00-02.yaml, KITTI03.yaml or KITTI04-12.yaml for sequence 0 to 2, 3, and 4 to 12 respectively. Change PATH_TO_DATASET_FOLDER to the uncompressed dataset folder. Change SEQUENCE_NUMBER to 00, 01, 02,.., 11.
./Examples/Stereo/stereo_kitti Vocabulary/ORBvoc.txt Examples/Stereo/KITTIX.yaml PATH_TO_DATASET_FOLDER/dataset/sequences/SEQUENCE_NUMBER

RGB-D 实例

TUM 数据集

  1. Associate RGB images and depth images using the python script associate.py. We already provide associations for some of the sequences in Examples/RGB-D/associations download a sequence fromhttp://vision.in.tum.de/data/datasets/rgbd-dataset/download and uncompress it.
  2. /. You can generate your own associations file executing:
  3. python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt
  4. Execute the following command. Change TUMX.yaml to TUM1.yaml,TUM2.yaml or TUM3.yaml for freiburg1, freiburg2 and freiburg3 sequences respectively. Change PATH_TO_SEQUENCE_FOLDERto the uncompressed sequence folder. Change ASSOCIATIONS_FILE to the path to the corresponding associations file.
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUMX.yaml PATH_TO_SEQUENCE_FOLDER ASSOCIATIONS_FILE

ROS 实例

处理你自己的实例

      你需要创建一个配置文件来校正你的摄像机。可以参照我们为TUM 和 KITTI 数据集提供的例子在monocular, stereo and RGB-D cameras情况下. 我们使用OpenCV的摄像机校正模型。 See the examples to learn how to create a program that makes use of the ORB-SLAM2 library and how to pass images to the SLAM system. Stereo input must be synchronized and rectified. RGB-D input must be synchronized and depth registered.

SLAM 和 Localization 模式

你可以使用GUI在SLAM 和 Localization 模式下自由切换

SLAM 模式

      这是默认模式. 此模式下,系统有三个线程并行工作: Tracking, Local Mapping and Loop Closing. 系统不断定位相机,构建新的地图然后试图闭合环形路径

Localization 模式

       当你有一个比较好的地图的时候,你可以使用此模式。在这种模式下,局部地图构建以及环路闭合将不起作用。 系统在你提供的地图上定位相机 (which is no longer updated), using relocalization if needed.


参考博客:http://blog.csdn.net/zhjm07054115/article/details/51706706

             https://github.com/raulmur/ORB_SLAM2


5.实时用摄像头(可笔记本自带或者外加摄像头)跑数据

(1)安装usb_cam package

      
    $ cd ~/catkin_ws/src  
    $ git clone https://github.com/bosch-ros-pkg/usb_cam.git  
    $ cd ~/catkin_ws  
    $ catkin_make  
笔记本自带的摄像头的设备号一般为/dev/video0    外接摄像头一般是
"video_device"value="/dev/video1"/>





(2)把ORB-SLAM2,和 usb_cam放到catkin下src目录下
     $ cd ~/catkin_ws/src  
    $ roscore    //初始化
    $ roslaunch usb_cam usb_cam-test.launch     //启动usb_cam包下的.launch文件启动摄像头


此时证明摄像头可以正常使用

~~~使用自定义 launch 文件设置摄像头:
usb_cam 给了我们一个默认的 launch 文件在如下目录

如果想要自定义一个我们自己的launch文件,我们可以复制这个文件为一个 usb_cam.launch,然后打开这个文件:

其中 /div/video0 表示是第一个摄像头,如果你有多个摄像头,可以将此改为 /div/video1 等等。想要查看当前连接设备,使用如下命令即可:

修改好后运行这个文件:

Error1: [rospack] Error: package 'image_view' not found

表明你的 image_view 没有安装,可以执行以下命令安装即可:

sudo apt-get install ros-indigo-image-view

(3)用ORB-SLAM2实时跑数据 记住:若是用外加摄像头,需要在usb_cam-test.launch和usb_cam_node.cpp把摄像头的设备号改为/dev/video1

  $ cd ~/catkin_ws/src  
  $ rosrun ORB_SLAM2 Mono /home/ubantu/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt 
       /home/ubantu/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml    
       (即 rosrun ORB-SLAN2 Mono    ORBvoc.txt路径    Asus.yaml路径)

6.标定摄像头(为了防止镜头下的图片发生畸变)

1)摄像头标定时所处的平面位置一旦改变,一般会影响相机内参,需重新标定

2)将标定后的参数替换相机原有的内参,重新跑一遍即可。




你可能感兴趣的:(slam,库,ORB-SLAM2,相机标定)