SLAM系列——第二讲 初识SLAM\[2022.12\]

系列文章目录

SLAM系列——第一讲 预备知识[2022.12]
SLAM系列——第二讲 初识SLAM[2022.12]
SLAM系列——第三讲 三维空间刚体运动[2022.12]
SLAM系列——第四讲 李群李代数[2022.12]
SLAM系列——第五讲 相机与图像[2022.12]
SLAM系列——第六讲 非线性优化[2022.12]
SLAM系列——第七讲 视觉里程计1[2022.12]
SLAM系列——第八讲 视觉里程计2[2022.12]
SLAM系列——第九讲 后端1[2022.12]
SLAM系列——第十讲 后端2[2022.12]
SLAM系列——第十一讲 回环检测[2022.12]
SLAM系列——第十二讲 建图[2022.12]
SLAM系列——第十三讲 实践:设计SLAM系统[2022.12]
SLAM系列——第十四讲 SLAM:现在与未来[2022.12]



2.1 引子:小萝卜的例子

详见。

2.2 经典视觉SLAM框架

2.2.1 视觉里程计

详见。

2.2.2 后端优化

详见。

2.2.3 回环检测

详见。

2.2.4 建图

详见。

2.3 SLAM问题的数学表述

详见。

2.4 实践:编程基础

2.4.1 安装Linux操作系统

详见。

2.4.2 Hello SLAM

详见。

2.4.3 使用cmake

详见。

2.4.4 使用库

详见。

Eigen3 编译安装

sudo apt install libeigen3-dev

opencv 编译安装

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

cd opencv_contrib
git checkout 3.4.16
cd ..
cd opencv
git checkout 3.4.16

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE  -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib/modules -D WITH_IPP=OFF -D WITH_LIBV4L=ON -D WITH_V4L=OFF -D WITH_LAPACK=OFF -D OPENCV_GENERATE_PKGCONFIG=YES ../

sudo make -j16

sudo make install

注意:加上 -D WITH_LAPACK=OFF 以防编译错误:

~/Downloads/opencv/modules/core/src/hal_internal.cpp: In function ‘int lapack_Cholesky(fptype*, size_t, int, fptype*, size_t, int, bool*)’:
~/Downloads/opencv/modules/core/src/hal_internal.cpp:166:23: error: too few arguments to function ‘void sposv_(const char*, const int*, const int*, float*, const int*, float*, const int*, int*, size_t)166 |                 sposv_(L, &m, &n, (float*)a, &lda, (float*)b, &m, &lapackStatus);
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/lapack.h:11,
                 from /usr/include/lapacke.h:36,
                 from ~/Downloads/opencv/build/opencv_lapack.h:12,
                 from ~/Downloads/opencv/modules/core/src/hal_internal.cpp:51:
/usr/include/lapack.h:13002:41: note: declared here
13002 | #define LAPACK_sposv_base LAPACK_GLOBAL(sposv,SPOSV)
      |                                         ^~~~~
/usr/include/lapacke_mangling.h:12:39: note: in definition of macro ‘LAPACK_GLOBAL’
   12 | #define LAPACK_GLOBAL(lcname,UCNAME)  lcname##_
      |                                       ^~~~~~
/usr/include/lapack.h:13003:6: note: in expansion of macro ‘LAPACK_sposv_base’
13003 | void LAPACK_sposv_base(
      |      ^~~~~~~~~~~~~~~~~
...

Pangolin 编译安装

cd 3rdparty/Pangolin
mkdir build
cd build
cmake ..
sudo make -j16
sudo make install

if warning:

CMake Warning (dev) at /usr/share/cmake-3.22/Modules/FindOpenGL.cmake:315 (message):
  Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
  available.  Run "cmake --help-policy CMP0072" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  FindOpenGL found both a legacy GL library:

    OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so

  and GLVND libraries for OpenGL and GLX:

    OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
    OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so

  OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
  compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
  src/CMakeLists.txt:155 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

recompile:

cmake -DOpenGL_GL_PREFERENCE=LEGACY ..

if error:

...Pangolin/include/pangolin/gl/colour.h:57:18: error: ‘numeric_limits’ is not a member of ‘std’
   57 |             std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN(),
      |                  ^~~~~~~~~~~~~~

解决办法是打开报错的文件,即colour.h
在include部分加上

#include <limits>

DBoW3 编译 (ORB-SLAM2中脚本)

cd 3rdparty/DBoW3
mkdir build
cd build
cmake ..
sudo make -j16
sudo make install

注意:编译过程中如出现以下报错信息,在 src/BowVector.h 头文件中添加 “#include ”即可。

In file included from ~/Downloads/slambook2/3rdparty/DBoW3/src/FeatureVector.h:13,
                 from ~/Downloads/slambook2/3rdparty/DBoW3/src/FeatureVector.cpp:10:
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:99:21: error: ‘ostream’ in namespace ‘std’ does not name a type
   99 |         friend std::ostream& operator<<(std::ostream &out, const BowVector &v);
      |                     ^~~~~~~
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:16:1: note: ‘std::ostream’ is defined in header ‘<ostream>; did you forget to ‘#include <ostream>’?
   15 | #include "exports.h"
  +++ |+#include <ostream>
   16 | #if _WIN32
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:106:31: error: ‘string’ in namespace ‘std’ does not name a type
  106 |         void saveM(const std::string &filename, size_t W) const;
      |                               ^~~~~~
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:16:1: note: ‘std::string’ is defined in header ‘<string>; did you forget to ‘#include <string>’?
   15 | #include "exports.h"
  +++ |+#include <string>
   16 | #if _WIN32
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:106:49: error: ‘size_t’ has not been declared
  106 |         void saveM(const std::string &filename, size_t W) const;
      |                                                 ^~~~~~
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:109:5: error: ‘uint64_t’ does not name a type
  109 |     uint64_t getSignature()const;
      |     ^~~~~~~~
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:16:1: note: ‘uint64_t’ is defined in header ‘<cstdint>; did you forget to ‘#include <cstdint>’?
   15 | #include "exports.h"
  +++ |+#include <cstdint>
   16 | #if _WIN32
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:111:24: error: ‘std::ostream’ has not been declared
  111 |     void toStream(std::ostream &str)const;
      |                        ^~~~~~~
~/Downloads/slambook2/3rdparty/DBoW3/src/BowVector.h:112:26: error: ‘std::istream’ has not been declared
  112 |     void fromStream(std::istream &str);
      |                          ^~~~~~~
In file included from ~/Downloads/slambook2/3rdparty/DBoW3/src/FeatureVector.cpp:10:
~/Downloads/slambook2/3rdparty/DBoW3/src/FeatureVector.h:48:15: error: ‘ostream’ in namespace ‘std’ does not name a type
   48 |   friend std::ostream& operator<<(std::ostream &out, const FeatureVector &v);
      |               ^~~~~~~
~/Downloads/slambook2/3rdparty/DBoW3/src/FeatureVector.h:14:1: note: ‘std::ostream’ is defined in header ‘<ostream>; did you forget to ‘#include <ostream>’?
   13 | #include "BowVector.h"
  +++ |+#include <ostream>
   14 | #include <map>
make[2]: *** [src/CMakeFiles/DBoW3.dir/build.make:118: src/CMakeFiles/DBoW3.dir/FeatureVector.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

g2o 编译 (ORB-SLAM2中脚本)

cd 3rdparty/g2o
mkdir build
cd build
cmake ..
sudo make -j16
sudo make install

ceres 编译安装

安装依赖项:

sudo apt-get install  liblapack-dev libsuitesparse-dev libcxsparse3 libgflags-dev libgoogle-glog-dev libgtest-dev

编译:

cd 3rdparty/ceres-solver
mkdir build
cd build
cmake ..
sudo make -j16
sudo make install

Sophus 编译安装

cd 3rdparty/Sophus
mkdir build
cd build
cmake ..
sudo make -j16
sudo make install

if errors:

...Sophus/test/core/test_so2.cpp:99:25: error: implicitly-declared ‘Eigen::Map<Sophus::SO2<double> >::Map(const Eigen::Map<Sophus::SO2<double> >&)’ is deprecated [-Werror=deprecated-copy]
   99 |     Eigen::Map<SO2Type> shallow_copy = map_of_so2;
      |                         ^~~~~~~~~~~~

在cmakelist那加一句set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")就行了(article):

# Set compiler specific settings (FixMe: Should not cmake do this for us automatically?)
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
   SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
   SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wno-deprecated-register -Wno-deprecated-register -Qunused-arguments -fcolor-diagnostics")
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
   SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
   SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -std=c++11 -Wno-deprecated-declarations -ftemplate-backtrace-limit=0")
   SET(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage -fno-inline -fno-inline-small-functions -fno-default-inline")
   SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
   SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "^MSVC$")
   ADD_DEFINITIONS("-D _USE_MATH_DEFINES /bigobj /wd4305 /wd4244 /MP")
ENDIF()

set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")

ORB-SLAM2 编译

如遇报错:

~/Downloads/ORB_SLAM2/src/Optimizer.cc:818:37:   required from here
/usr/include/c++/11/bits/stl_map.h:123:71: error: static assertion failed: std::map must have the same value_type as its allocator
  123 |       static_assert(is_same<typename _Alloc::value_type, value_type>::value,
      |                                                                       ^~~~~
/usr/include/c++/11/bits/stl_map.h:123:71: note: ‘std::integral_constant<bool, false>::value’ evaluates to false
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/build.make:118: CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....

将include/LoopClosing.h第50行改为:

        Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;
        Eigen::aligned_allocator<std::pair<KeyFrame* const, g2o::Sim3> > > KeyFrameAndPose;

注意:编译过程中如出现以下报错信息,在 include/System.h 头文件中添加 “#include<unistd.h> ”即可。受影响文件有:src/LocalMapping.cc, src/LoopClosing.cc, src/System.cc, src/Tracking.cc, src/Viewer.cc。

~/Downloads/ORB_SLAM2/src/LocalMapping.cc: In member function ‘void ORB_SLAM2::LocalMapping::Run()’:
~/Downloads/ORB_SLAM2/src/LocalMapping.cc:94:17: error: ‘usleep’ was not declared in this scope
   94 |                 usleep(3000);
      |                 ^~~~~~
~/Downloads/ORB_SLAM2/src/LocalMapping.cc:108:9: error: ‘usleep’ was not declared in this scope
  108 |         usleep(3000);
      |         ^~~~~~
~/Downloads/ORB_SLAM2/src/LocalMapping.cc: In member function ‘void ORB_SLAM2::LocalMapping::RequestReset()’:
~/Downloads/ORB_SLAM2/src/LocalMapping.cc:719:9: error: ‘usleep’ was not declared in this scope
  719 |         usleep(3000);
      |         ^~~~~~
In file included from /usr/include/c++/11/map:61,
                 from ~/Downloads/ORB_SLAM2/Thirdparty/DBoW2/DBoW2/BowVector.h:14,
                 from ~/Downloads/ORB_SLAM2/include/KeyFrame.h:25,
                 from ~/Downloads/ORB_SLAM2/include/MapPoint.h:24,
                 from ~/Downloads/ORB_SLAM2/include/Map.h:24,
                 from ~/Downloads/ORB_SLAM2/include/Optimizer.h:24,
                 from ~/Downloads/ORB_SLAM2/src/Optimizer.cc:21:
/usr/include/c++/11/bits/stl_map.h: In instantiation of ‘class std::map<ORB_SLAM2::KeyFrame*, g2o::Sim3, std::less<ORB_SLAM2::KeyFrame*>, Eigen::aligned_allocator<std::pair<const ORB_SLAM2::KeyFrame*, g2o::Sim3> > >’:
~/Downloads/ORB_SLAM2/src/Optimizer.cc:818:37:   required from here
/usr/include/c++/11/bits/stl_map.h:123:71: error: static assertion failed: std::map must have the same value_type as its allocator
  123 |       static_assert(is_same<typename _Alloc::value_type, value_type>::value,
      |                                                                       ^~~~~
/usr/include/c++/11/bits/stl_map.h:123:71: note: ‘std::integral_constant<bool, false>::value’ evaluates to false
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/build.make:76: CMakeFiles/ORB_SLAM2.dir/src/System.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....

2.4.5 使用IDE

详见。

习题

详见。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喜乐boy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值