最新的是ORB-SLAM2,https://github.com/raulmur/ORB_SLAM2(支持单目、双目和RGB-D接口,最好参照官网安装)
(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
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 Pangolin
mkdir 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
其实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最后编译遇到的问题
错误信息:
/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
typedef Eigen::Triplet
typedef Eigen::PermutationMatrix
修改为:
template
class LinearSolverEigen: public LinearSolver
{ public:
typedef Eigen::SparseMatrix
typedef Eigen::Triplet
typedef Eigen::PermutationMatrix
错误信息:
/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
(1)官网下载测试数据集
下载内存较大,最好用硬盘下好
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml PATH_TO_SEQUENCE_FOLDER
./Examples/Monocular/mono_kitti Vocabulary/ORBvoc.txt Examples/Monocular/KITTIX.yaml PATH_TO_DATASET_FOLDER/dataset/sequences/SEQUENCE_NUMBER
./Examples/Stereo/stereo_kitti Vocabulary/ORBvoc.txt Examples/Stereo/KITTIX.yaml PATH_TO_DATASET_FOLDER/dataset/sequences/SEQUENCE_NUMBER
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUMX.yaml PATH_TO_SEQUENCE_FOLDER ASSOCIATIONS_FILE
你需要创建一个配置文件来校正你的摄像机。可以参照我们为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.
你可以使用GUI在SLAM 和 Localization 模式下自由切换
这是默认模式. 此模式下,系统有三个线程并行工作: Tracking, Local Mapping and Loop Closing. 系统不断定位相机,构建新的地图然后试图闭合环形路径。
当你有一个比较好的地图的时候,你可以使用此模式。在这种模式下,局部地图构建以及环路闭合将不起作用。 系统在你提供的地图上定位相机 (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 外接摄像头一般是
|
$ cd ~/catkin_ws/src $ roscore //初始化 $ roslaunch usb_cam usb_cam-test.launch //启动usb_cam包下的.launch文件启动摄像头。
此时证明摄像头可以正常使用
~~~使用自定义 launch 文件设置摄像头:
usb_cam 给了我们一个默认的 launch 文件在如下目录
1
|
~/catkin-ws/usb_cam/src/usb_cam/launch/usb_cam-test.launch
|
如果想要自定义一个我们自己的launch文件,我们可以复制这个文件为一个 usb_cam.launch,然后打开这个文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<launch>
<nodename="usb_cam"pkg="usb_cam"type="usb_cam_node"output="screen">
<paramname="video_device"value="/dev/video0"/>
<paramname="image_width"value="640"/>
<paramname="image_height"value="480"/>
<paramname="pixel_format"value="yuyv"/>
<paramname="camera_frame_id"value="usb_cam"/>
<paramname="io_method"value="mmap"/>
</node>
<nodename="image_view"pkg="image_view"type="image_view"respawn="false"output="screen">
<remapfrom="image"to="/usb_cam/image_raw"/>
<paramname="autosize"value="true"/>
</node>
</launch>
|
其中 /div/video0 表示是第一个摄像头,如果你有多个摄像头,可以将此改为 /div/video1 等等。想要查看当前连接设备,使用如下命令即可:
修改好后运行这个文件:
Error1: [rospack] Error: package 'image_view' not found
表明你的 image_view 没有安装,可以执行以下命令安装即可:
$ 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)将标定后的参数替换相机原有的内参,重新跑一遍即可。