Ubuntu18.04配置视觉SLAM十四讲代码运行环境

1.安装Pangolin:参考教程 https://blog.csdn.net/l243225530/article/details/105900272 第6步;

2.安装engine3:参考上述教程第7步;

3.安装g2o:https://github.com/RainerKuemmerle/g2o 下载源码,安装步骤安装即可;

4.安装boost依赖:sudo apt-get install libboost-all-dev

5.安装Sophus

git clone https://github.com/strasdat/Sophus.git 
cd Sophus/ 
git checkout a621ff #若不执行该步骤,则安装的版本为最新的模板版本;若执行,则为非模板版本
mkdir build 
cd build 
cmake .. 
make
sudo make install

若出现该错误:

/Sophus/sophus/so2.cpp:32:26: error: lvalue required as left operand of assignment 
unit_complex_.real() = 1.;
/Sophus/sophus/so2.cpp:33:26: error: lvalue required as left operand of assignment 
unit_complex_.imag() = 0.;
该错误可以定位到so2.cpp源码文件下:
原代码为:
SO2::SO2()
{
  unit_complex_.real() = 1.;
  unit_complex_.imag() = 0.;
}
修改为:
SO2::SO2()
{
  //unit_complex_.real() = 1.;
  //unit_complex_.imag() = 0.;
  unit_complex_.real(1.);
  unit_complex_.imag(0.);
}

6.安装opencv3.2
下载opencv3.2.0和opencv_contrib-3.2.0
参考教程 https://blog.csdn.net/l243225530/article/details/105900272 第9步安装相关依赖(2.4.11和3.2.0需要的依赖几乎一致)
额外再安装viz模块

sudo apt-get isntall libvtk5-dev

将opencv3.2.0和opencv_contrib-3.2.0解压在一个文件夹内

cd opencv3.2.0
mkdir build
cd build
cmake -DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_VTK=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local/opencv3.2 -DWITH_CUDA=OFF -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF ..
make
sudo make install

注:可提前下载好ippicv_linux_20151201.tar文件,安装过程中可能会出现无法下载该文件的错误。若出现,则把下载好的文件替换到opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e文件下

7.开始编译视觉SLAM十四讲代码
下载源码:https://github.com/gaoxiang12/slambook (这是第一版的代码,现在也有第二版的代码了)
选择slambook-master/project/04项目进行编译

cd slambook-master/project/04
mkdir build
cd build
cmake ..
make

若出现visual_odometry.cpp代码编译错误,

error: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<6, 3> >::BlockSolver(g2o::BlockSolver<g2o::BlockSolverTraits<6, 3> >::LinearSolverType*&)’
     Block* solver_ptr = new Block ( linearSolver );

等等,则打开该文件,修改代码。
原代码为:

typedef g2o::BlockSolver< g2o::BlockSolverTraits<6,3> > Block;  // pose 维度为 6, landmark 维度为 3

Block::LinearSolverType* linearSolver = new g2o::LinearSolverCSparse<Block::PoseMatrixType>(); // 线性方程求解器

Block* solver_ptr = new Block ( linearSolver );     // 矩阵块求解器

g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg ( solver_ptr );

g2o::SparseOptimizer optimizer;

optimizer.setAlgorithm ( solver );

修改为:

typedef g2o::BlockSolver< g2o::BlockSolverTraits<6,3> > Block;  // pose 维度为 6, landmark 维度为 3
Block::LinearSolverType* linearSolver = new g2o::LinearSolverCSparse<Block::PoseMatrixType>(); // 线性方程求解器
Block* solver_ptr = new Block ( std::unique_ptr<Block::LinearSolverType>(linearSolver) );     // 矩阵块求解器
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg ( std::unique_ptr<Block>(solver_ptr) );
g2o::SparseOptimizer optimizer;
optimizer.setAlgorithm ( solver );

若出现Sophus相关未定义错误,则在CMakeLists.txt中有关Sophus的内容中添加代码。
原代码为:

# Sophus 
find_package( Sophus REQUIRED )
include_directories( ${Sophus_INCLUDE_DIRS} )

改为:

# Sophus 
find_package( Sophus REQUIRED )
include_directories( ${Sophus_INCLUDE_DIRS} )
set(Sophus_LIBRARIES libSophus.so)

你可能感兴趣的:(视觉SLAM开源项目学习)