slambook2(ch6)—— Ubuntu18.04安装Ceres库 + g2o库 + 例程演示

slambook2(ch6)—— Ubuntu18.04安装Ceres库 + g2o库 + 例程演示

  • 一、安装 Ceres
    • 1.安装依赖项
    • 2.下载——编译——安装
    • 3.安装结果
    • 4.安装错误
  • 二、安装g2o
    • 1.安装依赖项:
    • 2.下载——编译——安装:
    • 3.可能的错误
  • 三、例程结果

一、安装 Ceres

1.安装依赖项

首先安装 Ceres,安装依赖项(如果缺少依赖项,在 cmake 时会有提示,补上重新 cmake 即可):

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

2.下载——编译——安装

git clone https://github.com/ceres-solver/ceres-solver.git
cd ceres-solver
mkdir build
cd build
cmake ..
make -j4
sudo make install

3.安装结果

-- Installing: /usr/local/lib/cmake/Ceres/CeresConfigVersion.cmake
-- Installing: /usr/local/lib/cmake/Ceres/FindGlog.cmake
-- Installing: /usr/local/lib/libceres.a

4.安装错误

libcxsparse3.1.2 //我装的是libcxsparse3

出现找不到package的错误:

正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
E: 无法定位软件包 libcxsparse3.1.2
E: 无法按照 glob ‘libcxsparse3.1.2’ 找到任何软件包
E: 无法按照正则表达式 libcxsparse3.1.2 找到任何软件包

解决办法:

添加源,用下面命令打开source.list
sudo gedit /etc/apt/sources.list
在第一行添加:
deb http://cz.archive.ubuntu.com/ubuntu trusty main universe
然后更新一下:
sudo apt-get update

二、安装g2o

1.安装依赖项:

sudo apt-get install qt5-qmake qt5-default libqglviewer-dev-qt5 libsuitesparse-dev libcxsparse3 libcholmod3

2.下载——编译——安装:

git clone https://github.com/RainerKuemmerle/g2o   # 克隆最新版本g2o
cd g2o
mkdir build
cd build
cmake ..
make -j6      # 注意,这里尽量使用更多的j,否则g2o安装很慢(-j4  -j6等等)
sudo make install

3.可能的错误

大量template的扩展需要足够的内存,报错的原因是(虚拟机)运行内存不足。

[ 27%] Building CXX object g2o/types/slam2d/CMakeFiles/types_slam2d.dir/parameter_se2_offset.cpp.o
c++: internal compiler error: 已杀死 (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
g2o/solvers/pcg/CMakeFiles/solver_pcg.dir/build.make:81: recipe for target 'g2o/solvers/pcg/CMakeFiles/solver_pcg.dir/solver_pcg.cpp.o' failed
make[2]: *** [g2o/solvers/pcg/CMakeFiles/solver_pcg.dir/solver_pcg.cpp.o] Error 4
CMakeFiles/Makefile2:1942: recipe for target 'g2o/solvers/pcg/CMakeFiles/solver_pcg.dir/all' failed
make[1]: *** [g2o/solvers/pcg/CMakeFiles/solver_pcg.dir/all] Error 2

解决办法:
减少make使用到的核数:本次安装直接make(就是时间长点!!)

三、例程结果

$ ./gaussNewton 
total cost: 3.19575e+06, 		update: 0.0455771  0.078164 -0.985329		estimated params: 2.04558,-0.921836,4.01467
total cost: 376785, 		update:  0.065762  0.224972 -0.962521		estimated params: 2.11134,-0.696864,3.05215
total cost: 35673.6, 		update: -0.0670241   0.617616  -0.907497		estimated params: 2.04432,-0.0792484,2.14465
total cost: 2195.01, 		update: -0.522767   1.19192 -0.756452		estimated params: 1.52155,1.11267,1.3882
total cost: 174.853, 		update: -0.537502  0.909933 -0.386395		estimated params: 0.984045,2.0226,1.00181
total cost: 102.78, 		update: -0.0919666   0.147331 -0.0573675		estimated params: 0.892079,2.16994,0.944438
total cost: 101.937, 		update: -0.00117081  0.00196749 -0.00081055		estimated params: 0.890908,2.1719,0.943628
total cost: 101.937, 		update:   3.4312e-06 -4.28555e-06  1.08348e-06		estimated params: 0.890912,2.1719,0.943629
total cost: 101.937, 		update: -2.01204e-08  2.68928e-08 -7.86602e-09		estimated params: 0.890912,2.1719,0.943629
cost: 101.937>= last cost: 101.937, break.
solve time cost = 0.000324167 seconds. 
estimated abc = 0.890912, 2.1719, 0.943629
$ ./ceresCurveFitting 
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  1.597873e+06    0.00e+00    3.52e+06   0.00e+00   0.00e+00  1.00e+04        0    2.10e-05    5.70e-05
   1  1.884440e+05    1.41e+06    4.86e+05   9.88e-01   8.82e-01  1.81e+04        1    8.01e-05    1.24e-03
   2  1.784821e+04    1.71e+05    6.78e+04   9.89e-01   9.06e-01  3.87e+04        1    2.38e-05    1.28e-03
   3  1.099631e+03    1.67e+04    8.58e+03   1.10e+00   9.41e-01  1.16e+05        1    2.00e-05    1.32e-03
   4  8.784938e+01    1.01e+03    6.53e+02   1.51e+00   9.67e-01  3.48e+05        1    1.91e-05    1.36e-03
   5  5.141230e+01    3.64e+01    2.72e+01   1.13e+00   9.90e-01  1.05e+06        1    1.79e-05    1.39e-03
   6  5.096862e+01    4.44e-01    4.27e-01   1.89e-01   9.98e-01  3.14e+06        1    1.91e-05    1.42e-03
   7  5.096851e+01    1.10e-04    9.53e-04   2.84e-03   9.99e-01  9.41e+06        1    1.69e-05    1.44e-03
solve time cost = 0.00148036 seconds. 
Ceres Solver Report: Iterations: 8, Initial cost: 1.597873e+06, Final cost: 5.096851e+01, Termination: CONVERGENCE
estimated a,b,c = 0.890908 2.1719 0.943628 
$ ./g2oCurveFitting 
start optimization
iteration= 0	 chi2= 376785.128234	 time= 1.5027e-05	 cumTime= 1.5027e-05	 edges= 100	 schur= 0
iteration= 1	 chi2= 35673.566018	 time= 7.077e-06	 cumTime= 2.2104e-05	 edges= 100	 schur= 0
iteration= 2	 chi2= 2195.012304	 time= 6.434e-06	 cumTime= 2.8538e-05	 edges= 100	 schur= 0
iteration= 3	 chi2= 174.853126	 time= 6.058e-06	 cumTime= 3.4596e-05	 edges= 100	 schur= 0
iteration= 4	 chi2= 102.779695	 time= 6.567e-06	 cumTime= 4.1163e-05	 edges= 100	 schur= 0
iteration= 5	 chi2= 101.937194	 time= 6.282e-06	 cumTime= 4.7445e-05	 edges= 100	 schur= 0
iteration= 6	 chi2= 101.937020	 time= 6.171e-06	 cumTime= 5.3616e-05	 edges= 100	 schur= 0
iteration= 7	 chi2= 101.937020	 time= 6.32e-06	 cumTime= 5.9936e-05	 edges= 100	 schur= 0
iteration= 8	 chi2= 101.937020	 time= 6.219e-06	 cumTime= 6.6155e-05	 edges= 100	 schur= 0
iteration= 9	 chi2= 101.937020	 time= 6.234e-06	 cumTime= 7.2389e-05	 edges= 100	 schur= 0
solve time cost = 0.000582221 seconds. 
estimated model: 0.890912   2.1719 0.943629

你可能感兴趣的:(slambook2,实践复现,ubuntu,linux,slam)