安装依赖(可以在g2o/build下面打开终端安装依赖):
sudo apt-get install libeigen3-dev libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev
进入到g2o/build下面,打开终端:
cmake ..
make -j4
sudo make install
然后在g2o/bin文件夹下面会有可执行文件 g2o_viewer,输入g2o_viewer
,就可以打开g2o Viewer。
点击Optimize:
优化结果:
loaded sphere.g2o with 2500 vertices and 9799 measurements
graph is fixed by node 2499
# Using CHOLMOD poseDim -1 landMarkDim -1 blockordering 1
Preparing (no marginalization of Landmarks)
iteration= 0 chi2= 2080902195.842481 time= 0.358062 cumTime= 0.358062 edges= 9799 schur= 0
iteration= 1 chi2= 18794279.189352 time= 0.329363 cumTime= 0.687425 edges= 9799 schur= 0
iteration= 2 chi2= 59504.776500 time= 0.337096 cumTime= 1.02452 edges= 9799 schur= 0
iteration= 3 chi2= 44360.707890 time= 0.332766 cumTime= 1.35729 edges= 9799 schur= 0
iteration= 4 chi2= 44360.644572 time= 0.327731 cumTime= 1.68502 edges= 9799 schur= 0
iteration= 5 chi2= 44360.644572 time= 0.320315 cumTime= 2.00533 edges= 9799 schur= 0
iteration= 6 chi2= 44360.644572 time= 0.315437 cumTime= 2.32077 edges= 9799 schur= 0
iteration= 7 chi2= 44360.644572 time= 0.315717 cumTime= 2.63649 edges= 9799 schur= 0
iteration= 8 chi2= 44360.644572 time= 0.313432 cumTime= 2.94992 edges= 9799 schur= 0
iteration= 9 chi2= 44360.644572 time= 0.3132 cumTime= 3.26312 edges= 9799 schur= 0
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(pose_graph)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++17 -O2")
set(FMT_LIBRARIES fmt::fmt)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
# Eigen
include_directories("/usr/include/eigen3")
# sophus
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})
# g2o
find_package(G2O REQUIRED)
include_directories(${G2O_INCLUDE_DIRS})
add_executable(pose_graph_g2o_SE3 pose_graph_g2o_SE3.cpp)
target_link_libraries(pose_graph_g2o_SE3
g2o_core g2o_stuff g2o_types_slam3d ${CHOLMOD_LIBRARIES}fmt
)
add_executable(pose_graph_g2o_lie pose_graph_g2o_lie_algebra.cpp)
target_link_libraries(pose_graph_g2o_lie
g2o_core g2o_stuff
${CHOLMOD_LIBRARIES}
${Sophus_LIBRARIES}fmt
)
执行:
./pose_graph_g2o_SE3 ../sphere.g2o
结果:
read total 2500 vertices, 9799 edges.
optimizing ...
iteration= 0 chi2= 1023011093.967642 time= 0.373476 cumTime= 0.373476 edges= 9799 schur= 0 lambda= 805.622433 levenbergIter= 1
iteration= 1 chi2= 385118688.233188 time= 0.357608 cumTime= 0.731084 edges= 9799 schur= 0 lambda= 537.081622 levenbergIter= 1
iteration= 2 chi2= 166223726.693658 time= 0.345097 cumTime= 1.07618 edges= 9799 schur= 0 lambda= 358.054415 levenbergIter= 1
iteration= 3 chi2= 86610874.269316 time= 0.345358 cumTime= 1.42154 edges= 9799 schur= 0 lambda= 238.702943 levenbergIter= 1
iteration= 4 chi2= 40582782.710190 time= 0.359467 cumTime= 1.78101 edges= 9799 schur= 0 lambda= 159.135295 levenbergIter= 1
iteration= 5 chi2= 15055383.753040 time= 0.364629 cumTime= 2.14564 edges= 9799 schur= 0 lambda= 101.425210 levenbergIter= 1
iteration= 6 chi2= 6715193.487654 time= 0.346831 cumTime= 2.49247 edges= 9799 schur= 0 lambda= 37.664667 levenbergIter= 1
iteration= 7 chi2= 2171949.168383 time= 0.343555 cumTime= 2.83602 edges= 9799 schur= 0 lambda= 12.554889 levenbergIter= 1
iteration= 8 chi2= 740566.827049 time= 0.349763 cumTime= 3.18578 edges= 9799 schur= 0 lambda= 4.184963 levenbergIter= 1
iteration= 9 chi2= 313641.802464 time= 0.344068 cumTime= 3.52985 edges= 9799 schur= 0 lambda= 2.583432 levenbergIter= 1
iteration= 10 chi2= 82659.743578 time= 0.337424 cumTime= 3.86728 edges= 9799 schur= 0 lambda= 0.861144 levenbergIter= 1
iteration= 11 chi2= 58220.369189 time= 0.341309 cumTime= 4.20858 edges= 9799 schur= 0 lambda= 0.287048 levenbergIter= 1
iteration= 12 chi2= 52214.188561 time= 0.342066 cumTime= 4.55065 edges= 9799 schur= 0 lambda= 0.095683 levenbergIter= 1
iteration= 13 chi2= 50948.580336 time= 0.347687 cumTime= 4.89834 edges= 9799 schur= 0 lambda= 0.031894 levenbergIter= 1
iteration= 14 chi2= 50587.776729 time= 0.350755 cumTime= 5.24909 edges= 9799 schur= 0 lambda= 0.016436 levenbergIter= 1
iteration= 15 chi2= 50233.038802 time= 0.34194 cumTime= 5.59103 edges= 9799 schur= 0 lambda= 0.010957 levenbergIter= 1
iteration= 16 chi2= 49995.082836 time= 0.339664 cumTime= 5.9307 edges= 9799 schur= 0 lambda= 0.007305 levenbergIter= 1
iteration= 17 chi2= 48876.738968 time= 0.667126 cumTime= 6.59782 edges= 9799 schur= 0 lambda= 0.009298 levenbergIter= 2
iteration= 18 chi2= 48806.625520 time= 0.339358 cumTime= 6.93718 edges= 9799 schur= 0 lambda= 0.006199 levenbergIter= 1
iteration= 19 chi2= 47790.891374 time= 0.667675 cumTime= 7.60485 edges= 9799 schur= 0 lambda= 0.008265 levenbergIter= 2
iteration= 20 chi2= 47713.626578 time= 0.341985 cumTime= 7.94684 edges= 9799 schur= 0 lambda= 0.005510 levenbergIter= 1
iteration= 21 chi2= 46869.323691 time= 0.666084 cumTime= 8.61292 edges= 9799 schur= 0 lambda= 0.007347 levenbergIter= 2
iteration= 22 chi2= 46802.585509 time= 0.343051 cumTime= 8.95597 edges= 9799 schur= 0 lambda= 0.004898 levenbergIter= 1
iteration= 23 chi2= 46128.758046 time= 0.669868 cumTime= 9.62584 edges= 9799 schur= 0 lambda= 0.006489 levenbergIter= 2
iteration= 24 chi2= 46069.133544 time= 0.400483 cumTime= 10.0263 edges= 9799 schur= 0 lambda= 0.004326 levenbergIter= 1
iteration= 25 chi2= 45553.862168 time= 0.776975 cumTime= 10.8033 edges= 9799 schur= 0 lambda= 0.005595 levenbergIter= 2
iteration= 26 chi2= 45511.762622 time= 0.364835 cumTime= 11.1681 edges= 9799 schur= 0 lambda= 0.003730 levenbergIter= 1
iteration= 27 chi2= 45122.763002 time= 0.710622 cumTime= 11.8788 edges= 9799 schur= 0 lambda= 0.004690 levenbergIter= 2
iteration= 28 chi2= 45095.174401 time= 0.355943 cumTime= 12.2347 edges= 9799 schur= 0 lambda= 0.003127 levenbergIter= 1
iteration= 29 chi2= 44811.248507 time= 0.74212 cumTime= 12.9768 edges= 9799 schur= 0 lambda= 0.003785 levenbergIter= 2
saving optimization results ...
点击Optimize进行优化后的结果:
可以看出变化不大,说明优化效果好。
loaded result.g2o with 2500 vertices and 9799 measurements
graph is fixed by priors or nodes are already fixed
# Using CHOLMOD poseDim -1 landMarkDim -1 blockordering 1
Preparing (no marginalization of Landmarks)
iteration= 0 chi2= 229876.466744 time= 0.474341 cumTime= 0.474341 edges= 9799 schur= 0
iteration= 1 chi2= 44360.633423 time= 0.43548 cumTime= 0.909821 edges= 9799 schur= 0
iteration= 2 chi2= 44360.584347 time= 0.35304 cumTime= 1.26286 edges= 9799 schur= 0
iteration= 3 chi2= 44360.584347 time= 0.364927 cumTime= 1.62779 edges= 9799 schur= 0
iteration= 4 chi2= 44360.584347 time= 0.424738 cumTime= 2.05253 edges= 9799 schur= 0
iteration= 5 chi2= 44360.584347 time= 0.43064 cumTime= 2.48317 edges= 9799 schur= 0
iteration= 6 chi2= 44360.584347 time= 0.429685 cumTime= 2.91285 edges= 9799 schur= 0
iteration= 7 chi2= 44360.584347 time= 0.424979 cumTime= 3.33783 edges= 9799 schur= 0
iteration= 8 chi2= 44360.584347 time= 0.454355 cumTime= 3.79219 edges= 9799 schur= 0
iteration= 9 chi2= 44360.584347 time= 0.445448 cumTime= 4.23763 edges= 9799 schur= 0
CMakeLists.txt同上:
执行:
./pose_graph_g2o_lie ../sphere.g2o
结果:
read total 2500 vertices, 9799 edges.
optimizing ...
iteration= 0 chi2= 674837160.579970 time= 0.382965 cumTime= 0.382965 edges= 9799 schur= 0 lambda= 6658.554263 levenbergIter= 1
iteration= 1 chi2= 234706314.970484 time= 0.352348 cumTime= 0.735313 edges= 9799 schur= 0 lambda= 2219.518088 levenbergIter= 1
iteration= 2 chi2= 142146174.348537 time= 0.350267 cumTime= 1.08558 edges= 9799 schur= 0 lambda= 739.839363 levenbergIter= 1
iteration= 3 chi2= 83834595.145595 time= 0.355482 cumTime= 1.44106 edges= 9799 schur= 0 lambda= 246.613121 levenbergIter= 1
iteration= 4 chi2= 41878079.903257 time= 0.383174 cumTime= 1.82424 edges= 9799 schur= 0 lambda= 82.204374 levenbergIter= 1
iteration= 5 chi2= 16598628.119947 time= 0.36563 cumTime= 2.18987 edges= 9799 schur= 0 lambda= 27.401458 levenbergIter= 1
iteration= 6 chi2= 6137666.739405 time= 0.355356 cumTime= 2.54522 edges= 9799 schur= 0 lambda= 9.133819 levenbergIter= 1
iteration= 7 chi2= 2182986.250593 time= 0.397902 cumTime= 2.94312 edges= 9799 schur= 0 lambda= 3.044606 levenbergIter= 1
iteration= 8 chi2= 732676.668220 time= 0.362175 cumTime= 3.3053 edges= 9799 schur= 0 lambda= 1.014869 levenbergIter= 1
iteration= 9 chi2= 284457.115176 time= 0.345032 cumTime= 3.65033 edges= 9799 schur= 0 lambda= 0.338290 levenbergIter= 1
iteration= 10 chi2= 170796.109734 time= 0.358427 cumTime= 4.00876 edges= 9799 schur= 0 lambda= 0.181974 levenbergIter= 1
iteration= 11 chi2= 145466.315841 time= 0.349317 cumTime= 4.35807 edges= 9799 schur= 0 lambda= 0.060658 levenbergIter= 1
iteration= 12 chi2= 142373.179500 time= 0.345053 cumTime= 4.70313 edges= 9799 schur= 0 lambda= 0.020219 levenbergIter= 1
iteration= 13 chi2= 137485.756901 time= 0.354804 cumTime= 5.05793 edges= 9799 schur= 0 lambda= 0.006740 levenbergIter= 1
iteration= 14 chi2= 131202.175668 time= 0.353366 cumTime= 5.4113 edges= 9799 schur= 0 lambda= 0.002247 levenbergIter= 1
iteration= 15 chi2= 128006.202530 time= 0.352907 cumTime= 5.76421 edges= 9799 schur= 0 lambda= 0.000749 levenbergIter= 1
iteration= 16 chi2= 127587.860945 time= 0.383258 cumTime= 6.14746 edges= 9799 schur= 0 lambda= 0.000250 levenbergIter= 1
iteration= 17 chi2= 127578.599359 time= 0.355292 cumTime= 6.50276 edges= 9799 schur= 0 lambda= 0.000083 levenbergIter= 1
iteration= 18 chi2= 127578.573853 time= 0.374547 cumTime= 6.8773 edges= 9799 schur= 0 lambda= 0.000028 levenbergIter= 1
iteration= 19 chi2= 127578.573840 time= 0.369051 cumTime= 7.24635 edges= 9799 schur= 0 lambda= 0.000018 levenbergIter= 1
iteration= 20 chi2= 127578.573840 time= 0.403888 cumTime= 7.65024 edges= 9799 schur= 0 lambda= 0.000012 levenbergIter= 1
iteration= 21 chi2= 127578.573840 time= 0.389508 cumTime= 8.03975 edges= 9799 schur= 0 lambda= 0.000008 levenbergIter= 1
iteration= 22 chi2= 127578.573840 time= 1.02991 cumTime= 9.06966 edges= 9799 schur= 0 lambda= 0.000044 levenbergIter= 3
iteration= 23 chi2= 127578.573840 time= 1.09604 cumTime= 10.1657 edges= 9799 schur= 0 lambda= 0.000234 levenbergIter= 3
iteration= 24 chi2= 127578.573840 time= 3.48813 cumTime= 13.6538 edges= 9799 schur= 0 lambda= 5483030743.383683 levenbergIter= 10
saving optimization results ...
loaded result_lie.g2o with 2500 vertices and 9799 measurements
graph is fixed by node 2499
# Using CHOLMOD poseDim -1 landMarkDim -1 blockordering 1
Preparing (no marginalization of Landmarks)
iteration= 0 chi2= 44360.504602 time= 0.346272 cumTime= 0.346272 edges= 9799 schur= 0
iteration= 1 chi2= 44360.466873 time= 0.338344 cumTime= 0.684616 edges= 9799 schur= 0
iteration= 2 chi2= 44360.466872 time= 0.327914 cumTime= 1.01253 edges= 9799 schur= 0
iteration= 3 chi2= 44360.466872 time= 0.320692 cumTime= 1.33322 edges= 9799 schur= 0
iteration= 4 chi2= 44360.466872 time= 0.328325 cumTime= 1.66155 edges= 9799 schur= 0
iteration= 5 chi2= 44360.466872 time= 0.327864 cumTime= 1.98941 edges= 9799 schur= 0
iteration= 6 chi2= 44360.466872 time= 0.320299 cumTime= 2.30971 edges= 9799 schur= 0
iteration= 7 chi2= 44360.466872 time= 0.309914 cumTime= 2.61962 edges= 9799 schur= 0
iteration= 8 chi2= 44360.466872 time= 0.304971 cumTime= 2.9246 edges= 9799 schur= 0
iteration= 9 chi2= 44360.466872 time= 0.303961 cumTime= 3.22856 edges= 9799 schur= 0