ORB-SLAM是一种多功能且精确的单目SLAM解决方案,能够实时计算摄像机轨迹,并在各种环境下稀疏地重建场景,从小型手持序列到在几个城市街区行驶的汽车。它能够关闭大的循环,并从宽基线实时执行全局重新定位。
项目主页:链接
1.boost库开始多线程
sudo apt-get install libboost-all-dev
2.安装ROS
参考链接:1.博客 2.官方文档
3.安装opencv
4.g2o (included in Thirdparty)
源码链接:链接
这个源码里就有,不用额外下载,不过为了顺利安装成功,需要提前运行如下程序
sudo apt-get install libeigen3-dev//版本最低3.1.0
5. DBoW2 (included in Thirdparty)
源码链接:链接,同样不需要额外下载,看一下就好。
1.确认已经安装好所有的依赖:ROS,boost, eigen3, opencv, blas, lapack
2.克隆ORB-SLAM源码
git clone https://github.com/raulmur/ORB_SLAM.git ORB_SLAM
3.将当前ORB-SLAM的路径添加到bashrc中.获取ORB-SLAM文件夹的路径
sudo gedit ~/.bashrc //打开bashrc文件
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/ning/1.software/ORB_SLAM //加入ORB-SLAM文件夹的路径,注:这里应替换成自己电脑上的ORB-SLAM文件夹的路径
source ~/.bashrc
4.Build g2o。cd Thirdparty/g2o/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
5.Build DBoW2. Go into Thirdparty/DBoW2/ and execute:
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
6.Build ORB_SLAM. In the ORB_SLAM root execute:
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make
ning@ning:~/1.software/ORB_SLAM/build$ cmake .. -DCMAKE_BUILD_TYPE=Release
[rosbuild] Building package ORB_SLAM
Failed to invoke /opt/ros/kinetic/bin/rospack deps-manifests ORB_SLAM
[rospack] Error: package 'ORB_SLAM' depends on non-existent package 'opencv2' and rosdep claims that it is not a system dependency. Check the ROS_PACKAGE_PATH or try calling 'rosdep update'
CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:129 (message):
Failed to invoke rospack to get compile flags for package 'ORB_SLAM'. Look
above for errors from rospack itself. Aborting. Please fix the broken
dependency!
Call Stack (most recent call first):
/opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:207 (rosbuild_invoke_rospack)
CMakeLists.txt:4 (rosbuild_init)
-- Configuring incomplete, errors occurred!
See also "/home/ning/1.software/ORB_SLAM/build/CMakeFiles/CMakeOutput.log".
打开/ORB-SLAM/manifest.xml文件,注释掉
,最终的manifest.xml文件如下:
ORB_SLAM
Raul Mur-Artal
GPLv3
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::ComputeKeyPoints(std::vector >&)’:
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:607:63: error: ‘FAST’ was not declared in this scope
FAST(cellImage,cellKeyPoints[i][j],fastTh,true);
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:616:34: error: ‘ORB’ has not been declared
if( scoreType == ORB::HARRIS_SCORE )
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:683:17: error: ‘KeyPointsFilter’ has not been declared
KeyPointsFilter::retainBest(keysCell,nToRetain[i][j]);
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:699:13: error: ‘KeyPointsFilter’ has not been declared
KeyPointsFilter::retainBest(keypoints,nDesiredFeatures);
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::operator()(cv::InputArray, cv::InputArray, std::vector&, cv::OutputArray)’:
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:760:82: error: ‘GaussianBlur’ was not declared in this scope
GaussianBlur(workingMat, workingMat, Size(7, 7), 2, 2, BORDER_REFLECT_101);
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::ComputePyramid(cv::Mat, cv::Mat)’:
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:800:78: error: ‘INTER_LINEAR’ was not declared in this scope
resize(mvImagePyramid[level-1], mvImagePyramid[level], sz, 0, 0, INTER_LINEAR);
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:800:90: error: ‘resize’ was not declared in this scope
resize(mvImagePyramid[level-1], mvImagePyramid[level], sz, 0, 0, INTER_LINEAR);
^
/home/ning/1.software/ORB_SLAM/src/ORBextractor.cc:803:80: error: ‘INTER_NEAREST’ was not declared in this scope
resize(mvMaskPyramid[level-1], mvMaskPyramid[level], sz, 0, 0, INTER_NEAREST);
^
CMakeFiles/ORB_SLAM.dir/build.make:443: recipe for target 'CMakeFiles/ORB_SLAM.dir/src/ORBextractor.cc.o' failed
make[2]: *** [CMakeFiles/ORB_SLAM.dir/src/ORBextractor.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:227: recipe for target 'CMakeFiles/ORB_SLAM.dir/all' failed
make[1]: *** [CMakeFiles/ORB_SLAM.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
打开/ORB_SLAM/include/ORBextractor.h文件,添加以下两个头文件
#include
#include
/usr/local/include/eigen3/Eigen/src/Core/util/StaticAssert.h:125:9: error: ‘YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY’ is not a member of ‘Eigen::internal::static_assertion’
if (Eigen::internal::static_assertion(CONDITION)>::MSG) {}
是eigen库版本的问题,更换eigen版本之前需要先清理一下电脑上原本的eigen3库(查看eigen版本:打开/usr/include/eigen3/Eigen/src/Core/util/Macros.h 文件即可看到定义)
sudo mv /usr/include/eigen3 /temp/usr_include/eigen3
sudo mv /usr/local/include/eigen3 /temp/usr_local_include/eigen3//后面的路径可以自己随便定义
访问网站,
下载libeigen3-dev_3.2.0-8_all.deb文件,执行
sudo dpkg -i libeigen3-dev_3.2.0-8_all.deb
/usr/bin/ld: CMakeFiles/ORB_SLAM.dir/src/main.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/ORB_SLAM.dir/build.make:1609: recipe for target '../bin/ORB_SLAM' failed
make[2]: *** [../bin/ORB_SLAM] Error 1
CMakeFiles/Makefile2:324: recipe for target 'CMakeFiles/ORB_SLAM.dir/all' failed
make[1]: *** [CMakeFiles/ORB_SLAM.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2
是因为程序在编译时没找到boost依赖的库,打开终端定位boost_filesystem与boost_system两个库的位置
ning@ning:~/1.software/ORB_SLAM/build$ locate boost_filesystem
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
ning@ning:~/1.software/ORB_SLAM/build$ locate boost_system
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
打开/ORB_SLAM/CMakeList.txt文件,在最底部target_link_libraries中加入上面两个库的路径,变成
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
)
1.解压ORBvoc.txt文件
cd /ORB_SLAM
tar -xzvf ORBvoc.txt.tar.gz //解压
二、ubuntu16安装ORB-SLAM2