高翔博士slambook2 ch9 编译运行笔记
一、主要内容ch9讲如何把多个相机位姿和大量三维地图点放在一起优化使整体重投影误差最小。Bundle Adjustment简称BA光束法平差 / 捆集调整是视觉SLAM和SFM中非常重要的后端优化方法。在视觉SLAM中通常有多个相机位姿、多个三维地图点、很多图像观测这些数据一开始都是有误差的因此用BA来同时调整相机位姿和三维地图点使它们投影到图像上的位置尽量接近真实观测位置。min Σ || u_observed - u_projected ||²BA 是一个很大的非线性最小二乘问题。二、安装依赖下载 Ceres 2.1.0 Eigen 3.3.7最重要的放在最前面我在编译ch9代码时掉坑里了一直报错Eigen的版本号对不上要求版本3.3.7结果读出来是空值。-- Found required Ceres dependency: absl version 20240116 in /usr/local/lib/cmake/absl CMake Error at CMakeLists.txt:11 (Find_Package): Found package configuration file: /usr/local/lib/cmake/Ceres/CeresConfig.cmake but it set Ceres_FOUND to FALSE so package Ceres is considered to be NOT FOUND. Reason given by package: Found Eigen dependency, but the version of Eigen found () does not exactly match the version of Eigen Ceres was compiled with (3.3.7). This can cause subtle bugs by triggering violations of the One Definition Rule. See the Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule for more details于是我apt重装了Eigenfail。于是我源码重装了Eigen指定版本3.3.7fail。这里已经确定了Eigen版本正确就是3.3.7)cd ~/Desktop rm -rf eigen git clone https://gitlab.com/libeigen/eigen.git cd eigen git checkout 3.3.7 rm -rf build mkdir build cd build cmake .. \ -DCMAKE_BUILD_TYPERelease \ -DCMAKE_INSTALL_PREFIX/usr/local sudo make install #确认eigen版本 grep -R EIGEN_WORLD_VERSION\|EIGEN_MAJOR_VERSION\|EIGEN_MINOR_VERSION /usr/local/include/eigen3/Eigen/src/Core/util/Macros.h报错如下Found package configuration file: /usr/local/lib/cmake/Ceres/CeresConfig.cmake but it set Ceres_FOUND to FALSE so package Ceres is considered to be NOT FOUND. Reason given by package: Found Eigen dependency, but the version of Eigen found () does not exactly match the version of Eigen Ceres was compiled with (3.3.7). This can cause subtle bugs by triggering violations of the One Definition Rule. See the Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule for more details -- Configuring incomplete, errors occurred!找AI看了下是因为Ceres是之前编译的和当前的Eigen版本没有绑定于是我重新编译了2.2.1版本的Ceres。#安装依赖 sudo apt update sudo apt install -y build-essential cmake git sudo apt install -y libsuitesparse-dev sudo apt install -y libgoogle-glog-dev libgflags-dev cd ~/Desktop rm -rf ceres-solver #下载Ceres源码 指定版本2.1.0 git clone https://github.com/ceres-solver/ceres-solver.git cd ceres-solver git checkout 2.1.0 #用eigen3.3.7重新编译 rm -rf build mkdir build cd build cmake .. \ -DCMAKE_BUILD_TYPERelease \ -DEigen3_DIR/usr/local/eigen-3.3.7/share/eigen3/cmake \ -DCMAKE_PREFIX_PATH/usr/local/eigen-3.3.7 \ -DBUILD_TESTINGOFF \ -DBUILD_EXAMPLESOFF \ -DMINIGLOGOFF \ -DCMAKE_INSTALL_PREFIX/usr/local make -j$(nproc) sudo make install sudo ldconfig三、编译代码前面的依赖问题解决了以后就可以开始编译ch9的代码了。cd ~/Desktop/slambook2/ch9 rm -rf build mkdir build cd build cmake .. \ -DEigen3_DIR/usr/local/eigen-3.3.7/share/eigen3/cmake \ -DCeres_DIR/usr/local/lib/cmake/Ceres \ -DSophus_DIR/usr/local/lib/cmake/Sophus \ -DCMAKE_PREFIX_PATH/usr/local/eigen-3.3.7;/usr/local make -j$(nproc)编译结果如图四、运行实例查看生成的exe文件find . -type f -executable结果如图4.1 运行Ceres BAch9程序的运行一般需要输入BAL数据集文件在ch9文件夹下。./bundle_adjustment_ceres ../problem-16-22106-pre.txt运行结果如图4.2 运行g2o BA./bundle_adjustment_g2o ../problem-16-22106-pre.txt运行结果如图五、总结ch9 开始进入SLAM后端优化将前面的位姿、地图点、投影模型、优化方法全部结合起来做全局或局部优化。