Ubuntu14.04+ROS indigo+ORB-SLAM2

环境:Ubuntu 14.04 + ROS indigo

1.创建ROS的一个工作空间

$ mkdir -p ~/orbslam2_catkin_ws/src
$ cd ~/orbslam2_catkin_ws/src
$ catkin_init_workspace
$ cd ..
$ catkin_make
$ source devel/setup.bash

运行以下命令确认你的当前目录是否在环境变量中

$ echo $ROS_PACKAGE_PATH  
如果终端输出

/home/zhuquan/orbslam2_catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks  

则说明ROS工作空间已经搭建好了。

2.Prerequisites

2.1 C++11 or C++0x Compiler

We use the new thread and chrono functionalities of C++11.

所以需要安装C++11编译器,运行:

$ sudo apt-get install gcc g++

2.2 Pangolin

We use [Pangolin](https://github.com/stevenlovegrove/Pangolin) for visualization and user interface. Dowload and install instructions can be found at: https://github.com/stevenlovegrove/Pangolin.

$ sudo apt-get install libglew-dev   #安装Glew    
$ sudo apt-get install cmake         #安装CMake    
    #安装Boost    
$ sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev    
$ sudo apt-get install libpython2.7-dev  #安装Python2 / Python3    
   #下载、编译、安装Pangolin:    
$ git clone https://github.com/stevenlovegrove/Pangolin.git    
$ cd Pangolin    
$ mkdir build    
$ cd build    
$ cmake -DCPP11_NO_BOOST=1 ..    
$ make    
$ sudo make install 

2.3 OpenCV(2.4.13)

We use [OpenCV](http://opencv.org) to manipulate images and features. Dowload and install instructions can be found at: http://opencv.org. **Required at leat 2.4.3. Tested with OpenCV 2.4.11 and OpenCV 3.2**.

$ sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev 
libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev    
$ unzip  opencv-2.4.13.zip      
$ cd opencv-2.4.13;mkdir build;cd build;     
$ 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 -DINSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -DBUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DCUDA_GENERATION=Kepler ..        
$ make    
$ sudo make install

#在其中写入: /usr/local/lib    
$ sudo gedit /etc/ld.so.conf.d/opencv.conf     
   
#在文件末尾写入:      
#PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig     
#export PKG_CONFIG_PATH    
$ sudo ldconfig sudo gedit/etc/bash.bashrc    
   
#source此脚本    
$ source /etc/bash.bashrc

2.4 Eigen3

Required by g2o (see below). Download and install instructions can be found at: http://eigen.tuxfamily.org. **Required at least 3.1.0**.
注意:Opencv2.4.13编译时依赖此模块,最好在OpenCV2.4.13编译前安装

它能提供以下功能模块:
   1) 密集矩阵和数组操作
   2) 解密集线性方程组和矩阵分解
        -求解线性最小二乘系统
        -密集矩阵分解 (Cholesky, LU, QR, SVD, 特征值分解)
   3) 解稀疏线性方程组和矩阵分解
        -稀疏矩阵操作
        -求解稀疏线性最小二乘系统
        -稀疏矩阵分解(SpareCore, OrderingMethods, SpareCholesky, SpareLU, SparseQR,迭代线性求解)
   4) 空间变换
        - 2D旋转(角度)
        - 3D旋转(角度+轴)
        - 3D旋转(四元组: quaternion)
        - N维缩放
        - N维平移
        - N维仿射变换
        - N维线性变换(旋转、平移、缩放)
运行:

$ sudo apt-get install libeigen3-dev

2.5 BLAS and LAPACK

   g2o需要BLAS和LAPACK

(1) BLAS: Basic Linear Algebra Subprograms

     提供了基本的向量和矩阵操作:
     - Level-1 BLAS: 支持 标量、向量、向量-向量 操作
     - Level-2 BLAS: 支持 矩阵-向量 操作
     - Level-3 BLAS: 支持 矩阵-矩阵 操作

(2) LAPACK:Linear Algebra PACKage

    它调用BLAS来实现更高级的功能,支持以下操作:

    - 解线性方程组
    - 线性方程组的最小二乘解
    - 特征值问题和奇异值问题
    - 矩阵分解 (LU, Cholesky, QR, SVD, Schur, generalized Schur)
    - 支持密集和带状矩阵,但不支持一般的稀疏矩阵
    - 支持单精度和双精度

运行:

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

2.6 DBoW2 and g2o (Included in Thirdparty folder)

We use modified versions of the [DBoW2](https://github.com/dorian3d/DBoW2) library to perform place recognition and [g2o](https://github.com/RainerKuemmerle/g2o) library to perform non-linear optimizations. Both modified libraries (which are BSD) are included in the *Thirdparty* folder.

3 编译usb_cam 

catkin_ws/src下运行:

$ cd orbslam2_catkin_ws/src
$ git clone https://github.com/bosch-ros-pkg/usb_cam.git

然后运行:

$ cd orbslam2_catkin_ws/src/usb_cam
$ mkdir build
$ cd build
$ cmake ..
$ make

4 编译ORB_SLAM2

运行:

$ cd ..
$ cd ..

$ git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
$ cd ORB_SLAM2
$ chmod +x build.sh
$ ./build.sh
$ chmod +x build_ros.sh
$ ./build_ros.sh

5 配置ORB-SLAM2的环境变量

Add the path including *Examples/ROS/ORB_SLAM2* to the ROS_PACKAGE_PATH environment variable. Open.bashrc file and add at the end the following line. Replace PATH by the folder where you cloned ORB_SLAM2:

execute:
  export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS

例如:

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/zhuquan/orbslam2_catkin_ws/src/ORB_SLAM2/Examples/ROS

利用相机进行实时的操作

6.1 普通单目摄像头(笔记本自带摄像头)实现ORB-SLAM2

  • 修改/usb_cam/launch/usb_cam-test.launch的内容,将其改为:

<launch>

<node name="camera" pkg="usb_cam" type="usb_cam_node" output="screen" >

<param name="video_device" value="/dev/video0" />

<param name="image_width" value="640" />

<param name="image_height" value="480" />

<param name="pixel_format" value="yuyv" />

<param name="camera_frame_id" value="camera" />

<param name="io_method" value="mmap"/>

<remap from="/usb_cam/image_raw" to="/camera/image_raw" /> ##新加的一行

</node>

<node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">

<remap from="image" to="/camera/image_raw"/>

<param name="autosize" value="true" />

</node>

</launch>

  • 实现  
    打开一个终端,执行:
$ roscore
   运行结果如下图所示:


重新打开一个新终端(原终端保留),运行:                                                                                                                        

$ cd ~/orbslam2_catkin_ws
$ source devel/setup.bash
$ roslaunch usb_cam usb_cam-test.launch
运行结果如下图所示:                        这时

这时笔记本的摄像头的灯会亮,并且弹出一个名为/camera/image_raw的窗口:                                      
  • 重新打开 一个终端(原来的两个终端保留),运行  
    $ cd ~/orbslam2_catkin_ws
    $ source devel/setup.bash
    $ rosrun ORB_SLAM2 Mono /home/zhuquan/orbslam2_catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/zhuquan/orbslam2_catkin_ws/src/ORB_SLAM2/Examples/Monocular/TUM1.yaml
    

                            

  • 运行结果如下图所示:                                       6.2 使用深度相机(如Kinect V1)实现ORB-SLAM2  

  • 安装Kinect V1需要的驱动(OpenNI,SensorKinect,NITE并按此顺序安装)      
    $ sudo apt-get install ros-indigo-openni-* ros-indigo-openni2-* ros-indigo-freenect-*
    
    $ rospack profile

  • 运行:      
    $ sudo apt-get install ros-indigo-openni-launch
    实现:    
    $ roscore
    $ roslaunch freenect_launch freenect-registered-xyzrgb.launch
    $ rosrun ORB_SLAM2 RGBD /home/zhuquan/orbslam2_catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/zhuquan/orbslam2_catkin_ws/src/ORB_SLAM2/Examples/RGB-D/TUM1.yaml
    注意:这三条指令的运行方式和上述单目情况类似

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值