欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu 16.04配置ORB_SLAM过程及问题记录

程序员文章站 2022-06-11 21:44:12
...

ORB_SLAM环境配置及运行

配置时间:2019.7.5
源码链接:https://github.com/raulmur/ORB_SLAM
教程链接:https://blog.csdn.net/u011392872/article/details/78816746

编译g2o和DBoW2均很顺利:
问题1:
编译ORB_SLAM时报错:

aaa@qq.com:~/ORB_SLAM$ mkdir build
aaa@qq.com:~/ORB_SLAM$ cd build
aaa@qq.com:~/ORB_SLAM/build$ cmake .. -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python (found version "2.7.12") 
[rosbuild] Building package ORB_SLAM
Failed to invoke /opt/ros/kinetic/bin/rospack deps-manifests ORB_SLAM
[rospack] Error: the rosdep view is empty: call 'sudo rosdep init' and '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/nuc/ORB_SLAM/build/CMakeFiles/CMakeOutput.log".

原因如下:官方给出的编译教程里说明了如果ROS版本是Indigo的话,需要将ORB_SLAM根目录下的manifest.xml文件中的opencv2依赖一行的代码去掉!但是这台电脑明明是Ubuntu 16.04,对应的ROS版本当然是Kinect,但是还是要去掉此行代码后才能编译成功。
Ubuntu 16.04配置ORB_SLAM过程及问题记录
Ubuntu 16.04配置ORB_SLAM过程及问题记录
然后编译就可以了。
然后cmake 没问题

问题2:
再然后make又出问题了。

aaa@qq.com:~/ORB_SLAM/build$ make -j8
Scanning dependencies of target rospack_genmsg_libexe
[  0%] Built target rospack_genmsg_libexe
Scanning dependencies of target rosbuild_precompile
[  0%] Built target rosbuild_precompile
Scanning dependencies of target ORB_SLAM
[  5%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/main.cc.o
[ 10%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Tracking.cc.o
[ 15%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/LocalMapping.cc.o
[ 21%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/LoopClosing.cc.o
[ 26%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/ORBextractor.cc.o
[ 31%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Converter.cc.o
[ 36%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/ORBmatcher.cc.o
[ 42%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/FramePublisher.cc.o
/home/nuc/ORB_SLAM/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::ComputeKeyPoints(std::vector<std::vector<cv::KeyPoint> >&):
/home/nuc/ORB_SLAM/src/ORBextractor.cc:607:63: error: ‘FAST’ was not declared in this scope
                 FAST(cellImage,cellKeyPoints[i][j],fastTh,true);
                                                               ^
/home/nuc/ORB_SLAM/src/ORBextractor.cc:616:34: error: ‘ORB’ has not been declared
                 if( scoreType == ORB::HARRIS_SCORE )
                                  ^
/home/nuc/ORB_SLAM/src/ORBextractor.cc:683:17: error: ‘KeyPointsFilter’ has not been declared
                 KeyPointsFilter::retainBest(keysCell,nToRetain[i][j]);
                 ^
/home/nuc/ORB_SLAM/src/ORBextractor.cc:699:13: error: ‘KeyPointsFilter’ has not been declared
             KeyPointsFilter::retainBest(keypoints,nDesiredFeatures);
             ^
/home/nuc/ORB_SLAM/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::operator()(cv::InputArray, cv::InputArray, std::vector<cv::KeyPoint>&, cv::OutputArray):
/home/nuc/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/nuc/ORB_SLAM/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::ComputePyramid(cv::Mat, cv::Mat):
/home/nuc/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/nuc/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/nuc/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]: *** 正在等待未完成的任务....
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过程中,移除manifest.xml中的opencv2的依赖以后,出现类或者函数未声明的问题,
解决:参考https://blog.csdn.net/weixin_42056625/article/details/88050474
解决方法:在src/ORBextractor.cc中添加

#include <opencv2/opencv.hpp>

然后重新编译,结果如下:

问题3:Eigen3 的bug

aaa@qq.com:~/ORB_SLAM/build$ cmake .. -DROS_BUILD_TYPE=Release
[rosbuild] Building package ORB_SLAM
[rosbuild] using multiarch 'x86_64-linux-gnu' for finding Boost
-- Using CATKIN_DEVEL_PREFIX: /home/nuc/ORB_SLAM/build/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Skip enable_testing() for dry packages
-- Using CATKIN_TEST_RESULTS_DIR: /home/nuc/ORB_SLAM/build/test_results
-- Found gmock sources under '/usr/src/gmock': gmock will be built
-- Found gtest sources under '/usr/src/gmock': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.18
-- BUILD_SHARED_LIBS is on
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
[rosbuild] Including /opt/ros/kinetic/share/roslisp/rosbuild/roslisp.cmake
[rosbuild] Including /opt/ros/kinetic/share/roscpp/rosbuild/roscpp.cmake
[rosbuild] Including /opt/ros/kinetic/share/rospy/rosbuild/rospy.cmake
Build type: Release
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nuc/ORB_SLAM/build
aaa@qq.com:~/ORB_SLAM/build$ make -j8
[  0%] Built target rospack_genmsg_libexe
[  0%] Built target rosbuild_precompile
Scanning dependencies of target ORB_SLAM
[  5%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Map.cc.o
[ 10%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/MapPoint.cc.o
[ 15%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/ORBextractor.cc.o
[ 21%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/KeyFrame.cc.o
[ 26%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/MapPublisher.cc.o
[ 31%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Optimizer.cc.o
[ 36%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/PnPsolver.cc.o
[ 42%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Frame.cc.o
[ 47%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/KeyFrameDatabase.cc.o
[ 52%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Sim3Solver.cc.o
[ 57%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Initializer.cc.o
In file included from /usr/include/eigen3/Eigen/Core:297:0,
                 from /home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/types/../core/jacobian_workspace.h:30,
                 from /home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/types/../core/optimizable_graph.h:41,
                 from /home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/types/../core/base_vertex.h:30,
                 from /home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h:34,
                 from /home/nuc/ORB_SLAM/include/LoopClosing.h:33,
                 from /home/nuc/ORB_SLAM/include/Optimizer.h:27,
                 from /home/nuc/ORB_SLAM/src/Optimizer.cc:21:
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Matrix<int, -1, 1>; Src = Eigen::Matrix<long int, -1, 1, 0, -1, 1>; Func = Eigen::internal::assign_op<int>]:
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:712:27:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type) [with Dst = Eigen::Matrix<int, -1, 1>; Src = Eigen::Matrix<long int, -1, 1, 0, -1, 1>; Func = Eigen::internal::assign_op<int>; typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type = void*]/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:693:18:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Matrix<int, -1, 1>; Src = Eigen::Matrix<long int, -1, 1, 0, -1, 1>]/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:682:32:   required from ‘Derived& Eigen::PlainObjectBase<Derived>::_set(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<long int, -1, 1, 0, -1, 1>; Derived = Eigen::Matrix<int, -1, 1>]/usr/include/eigen3/Eigen/src/Core/Matrix.h:225:24:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<long int, -1, 1, 0, -1, 1>; _Scalar = int; int _Rows = -1; int _Cols = 1; int _Options = 0; int _MaxRows = -1; int _MaxCols = 1]/usr/include/eigen3/Eigen/src/Core/PermutationMatrix.h:367:17:   required from ‘Eigen::PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>& Eigen::PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>::operator=(const Eigen::PermutationBase<OtherDerived>&) [with Other = Eigen::PermutationMatrix<-1, -1, long int>; int SizeAtCompileTime = -1; int MaxSizeAtCompileTime = -1; _StorageIndex = int]/home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/solvers/linear_solver_eigen.h:68:18:   required from ‘void g2o::LinearSolverEigen<MatrixType>::CholeskyDecomposition::analyzePatternWithPermutation(g2o::LinearSolverEigen<MatrixType>::SparseMatrix&, const PermutationMatrix&) [with MatrixType = Eigen::Matrix<double, 7, 7, 0, 7, 7>; g2o::LinearSolverEigen<MatrixType>::SparseMatrix = Eigen::SparseMatrix<double, 0>; g2o::LinearSolverEigen<MatrixType>::PermutationMatrix = Eigen::PermutationMatrix<-1, -1, long int>]/home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/solvers/linear_solver_eigen.h:195:9:   required from ‘void g2o::LinearSolverEigen<MatrixType>::computeSymbolicDecomposition(const g2o::SparseBlockMatrix<MatrixType>&) [with MatrixType = Eigen::Matrix<double, 7, 7, 0, 7, 7>]/home/nuc/ORB_SLAM/Thirdparty/g2o/g2o/solvers/linear_solver_eigen.h:100:37:   required from ‘bool g2o::LinearSolverEigen<MatrixType>::solve(const g2o::SparseBlockMatrix<MatrixType>&, double*, double*) [with MatrixType = Eigen::Matrix<double, 7, 7, 0, 7, 7>]/home/nuc/ORB_SLAM/src/Optimizer.cc:989:1:   required from here
/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:119: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<false>if (Eigen::internal::static_assertion<static_cast<bool>(CONDITION)>::MSG) {}
         ^
/usr/include/eigen3/Eigen/src/Core/util/XprHelper.h:707:3: note: in expansion of macro ‘EIGEN_STATIC_ASSERT’
   EIGEN_STATIC_ASSERT((internal::functor_is_product_like<BINOP>::ret \
   ^
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:745:3: note: in expansion of macro ‘EIGEN_CHECK_BINARY_COMPATIBILIY’
   EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);
   ^
CMakeFiles/ORB_SLAM.dir/build.make:1091: recipe for target 'CMakeFiles/ORB_SLAM.dir/src/Optimizer.cc.o' failed
make[2]: *** [CMakeFiles/ORB_SLAM.dir/src/Optimizer.cc.o] Error 1
make[2]: *** 正在等待未完成的任务....
CMakeFiles/Makefile2:324: 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

问题原因:Eigen3的bug
解决方法:(https://www.cnblogs.com/shishiteng/p/5799406.html)
打开Thirdparty/g2o/g2o/solvers/linear_solver_eigen.h,将以下代码

template <typename MatrixType>
class LinearSolverEigen: public LinearSolver<MatrixType>
{
  public:
    typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;
    typedef Eigen::Triplet<double> Triplet;
    typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, SparseMatrix::Index> PermutationMatrix;

改为

template <typename MatrixType>
class LinearSolverEigen: public LinearSolver<MatrixType>
{
  public:
    typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;
    typedef Eigen::Triplet<double> Triplet;
    typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> PermutationMatrix;

就是将最后一行的SparseMatrix::Index改为int,然后再重新make,

aaa@qq.com:~/ORB_SLAM/build$ make -j8
[  0%] Built target rospack_genmsg_libexe
[  0%] Built target rosbuild_precompile
Scanning dependencies of target ORB_SLAM
[  5%] Building CXX object CMakeFiles/ORB_SLAM.dir/src/Optimizer.cc.o
[ 10%] Linking CXX executable ../bin/ORB_SLAM
/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:127: recipe for target 'all' failed
make: *** [all] Error 2

继续执行make命令后,

问题4:出现libboost_system.so共享库的问题:
解决方法:(https://blog.csdn.net/weixin_42056625/article/details/88050474)

在CmakeLists.txt 的 include_directories 中添加${Boost_INCLUDE_DIRS}

include_directories(
${PROJECT_SOURCE_DIR}
${EIGEN3_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
)

添加${Boost_LIBRARIES}如下:

target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Boost_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
)

添加find_package(Boost COMPONENTS system)如下:

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Boost COMPONENTS system)

编译通过。

问题5:
然后测试ORB-SLAM,在运行.launch文件的时候,出现找不到image节点的错误,

aaa@qq.com:~/SLAM/src/ORB_SLAM$ roslaunch ExampleGroovyOrNewer.launch 
... logging to /home/acl/.ros/log/9939aefe-b287-11e9-9f78-000c2904c99b/roslaunch-ubuntu-6160.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ubuntu:40387/

SUMMARY
========

PARAMETERS
 * /image_view/autosize: True
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES
  /
    ORB_SLAM (ORB_SLAM/ORB_SLAM)
    image_view (image_view/image_view)
    rviz (rviz/rviz)

auto-starting new master
process[master]: started with pid [6170]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 9939aefe-b287-11e9-9f78-000c2904c99b
process[rosout-1]: started with pid [6183]
started core service [/rosout]
ERROR: cannot launch node of type [image_view/image_view]: image_view
ROS path [0]=/opt/ros/kinetic/share/ros
ROS path [1]=/home/acl/SLAM/src
ROS path [2]=/opt/ros/kinetic/share
process[rviz-3]: started with pid [6200]
process[ORB_SLAM-4]: started with pid [6201]

ORB-SLAM Copyright (C) 2014 Raul Mur-Artal
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.

Loading ORB Vocabulary. This could take a while.
Vocabulary loaded!

Camera Parameters: 
- fx: 609.286
- fy: 609.342
- cx: 351.427
- cy: 237.732
- k1: -0.3492
- k2: 0.1363
- p1: 0
- p2: 0
- fps: 30
- color order: RGB (ignored if grayscale)

ORB Extractor Parameters: 
- Number of Features: 1000
- Scale Levels: 8
- Scale Factor: 1.2
- Fast Threshold: 20
- Score: FAST

Motion Model: Enabled

如下图所示:
Ubuntu 16.04配置ORB_SLAM过程及问题记录
解决: sudo apt-get install ros-kinetic-image-view

2、在ros工作空间下运行ORB SLAM
参考网址:(https://blog.csdn.net/lixujie666/article/details/80475451)
注意:在配置ORB SLAM1时,     把博主的ORBSLAM1文件夹的名称改为ORBSLAM,否则在运行.launch 文件时找不到文件夹