Eigen3 是必需依赖,Windows 非 vcpkg 构建需手动设置 EIGEN3_INCLUDE_DIR;g2o_viewer、g2o_incremental 等组件为 GPL3+ 授权,商用需注意;CHOLMOD 若带 GPL 特性会被启用,需规避 GPL 时得自行重编 CHOLMOD;Python 绑定在实验性 pymem 分支,正式包需另装 g2o-python
sudo apt install libeigen3-dev libspdlog-dev libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
mkdir build
cd build
cmake ../
makeREADME 未说明硬件要求,仅要求 C++17 编译器、CMake 与 Eigen3,属纯 CPU 计算库
开源 C++ 图优化框架,用图结构求解 SLAM 与 BA 中的非线性最小二乘问题
C++ 图优化通用框架,把 SLAM 和视觉定位里的位姿估计建模成图,用非线性最小二乘求解,是后端优化的经典基础设施。
核心能力
- 把非线性误差函数建模成图并做最小二乘优化
- 内置多种 SLAM 与 BA 问题的求解实现
- 新问题通常只需几行代码即可扩展定义
- 提供 g2o_viewer 等可视化与增量优化组件
- 支持 Linux、macOS、Windows 与 Android 交叉编译
容易踩的坑
- 20241228_git最新正式版2024-12-28 · 2024-12-28 09:25 UTC
What's Changed
- Unscented test by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/710
- Fix build without OpenGL by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/712
- Make convertSegmentLine independent of the simulator by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/715
- Update linking of tests by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/717
- Change auto diff jacobian storage order when vertex dimension is 1 by @otamachan in https://github.com/RainerKuemmerle/g2o/pull/725
- Add workaround for multiple definitions by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/727
- Improve print in case of failing test by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/726
- Add logging of source location by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/730
- Fix logger singleton by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/736
- Update parser by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/737
- Simplify dl_wrapper by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/738
- Update csparse_extension license in README by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/744
- Drop using PRETTY_FUNCTION by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/747
- Use std::filesystem in filesys_tools by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/748
- Fix initialization of tau by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/761
- Fix
std::seed_seq::generateusage to conform to the Standard by @StephanTLavavej in https://github.com/RainerKuemmerle/g2o/pull/768 - Rainer/export classes by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/770
- Fix building with G2O_USE_OPENGL switched off by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/780
- Check if cmd arg file exist for g2o_viewer by @FelixSchladt in https://github.com/RainerKuemmerle/g2o/pull/785
- Add check for regular file by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/786
- Set CMAKE_OSX_DEPLOYMENT_TARGET to 10.15 by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/795
- Prevent installing gtest by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/808
- Add analytical Jacobian for EdgeSE2PointXYBearing type by @matthew-t-watson in https://github.com/RainerKuemmerle/g2o/pull/818
- Rainer/own join by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/826
- Remove spaces from sim3 type names by @iillyyaa in https://github.com/RainerKuemmerle/g2o/pull/830
- Switch to G2O_REGISTER_TYPE_NAME macro by @iillyyaa in https://github.com/RainerKuemmerle/g2o/pull/832
- Do not EXPORT executable targets by @iillyyaa in https://github.com/RainerKuemmerle/g2o/pull/833
- Use strJoin instead of fmt::join by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/842
- Provide AttributeMacros in .clang-format by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/848
- Rainer/851 by @RainerKuemmerle in https://github.com/RainerKuemmerle/g2o/pull/852
New Contributors
- @otamachan made their first contribution in https://github.com/RainerKuemmerle/g2o/pull/725
- @StephanTLavavej made their first contribution in https://github.com/RainerKuemmerle/g2o/pull/768
- @FelixSchladt made their first contribution in https://github.com/RainerKuemmerle/g2o/pull/785
- @matthew-t-watson made their first contribution in https://github.com/RainerKuemmerle/g2o/pull/818
- @iillyyaa made their first contribution in https://github.com/RainerKuemmerle/g2o/pull/830
Full Changelog: https://github.com/RainerKuemmerle/g2o/compare/20230806_git...20241228_git
- 20230806_git2023-08-06 · 2023-08-06 13:51 UTC
查看更新说明
- Integrate spdlog as logging framework
- Move to C++17, including refactoring fixed sized edges
- Drop broken single precision feature
- Add SO_VERSION and VERSION
- Drop build type suffix and place bin/lib in build folder
- Move g2o_hierarchical into examples
- Implement drawing covariance matrix in examples/slam2d
- Fix Fair and Geman McClure robust kernel
- Fix SSE auto detection
- 20230223_git2023-02-26 · 2023-02-26 11:36 UTC
查看更新说明
- Support dynamically sized vertices
- Use Eigen based solver to provide gn_var, lm_var from the solver factory
- Require C++14 for core module
- Only depend on Cholmod and CSparse at build time
- clang-formatted code base
- 20201223_git2020-12-23 · 2020-12-23 13:57 UTC
查看更新说明
- Add support for dynamically sized vertices
- Switch to Eigen's Sparse Cholesky modules as the standard solver
- Eigen's Sparse Module is included in the Eigen header and available under LGPL2
- Still, cholmod should be preferred if performance is important
- Drop own copy of CSparse (see above)
- Own examples use Eigen or Cholmod (no longer CSparse)
- Add tests
- 20200410_git202004102020-04-10 · 2020-04-10 11:46 UTC
这个版本没有写更新说明。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
g2o - General Graph Optimization
g2o is an open-source C++ framework for optimizing graph-based nonlinear error functions. g2o has been designed to be easily extensible to a wide range of problems and a new problem typically can be specified in a few lines of code. The current implementation provides solutions to several variants of SLAM and BA.
A wide range of problems in robotics as well as in computer-vision involve the minimization of a non-linear error function that can be represented as a graph. Typical instances are simultaneous localization and mapping (SLAM) or bundle adjustment (BA). The overall goal in these problems is to find the configuration of parameters or state variables that maximally explain a set of measurements affected by Gaussian noise. g2o is an open-source C++ framework for such nonlinear least squares problems. g2o has been designed to be easily extensible to a wide range of problems and a new problem typically can be specified in a few lines of code. The current implementation provides solutions to several variants of SLAM and BA. g2o offers a performance comparable to implementations of state-of-the-art approaches for the specific problems (02/2011).
Python and updated memory management
The branch pymem contains a python wrapper and switches to smart pointer instead of RAW pointers. It is currently experimental but PRs and improvements are welcome - as always.
See g2o-python for the pypi release of g2o's python bindings.
Papers Describing the Approach
Rainer Kuemmerle, Giorgio Grisetti, Hauke Strasdat, Kurt Konolige, and Wolfram Burgard g2o: A General Framework for Graph Optimization IEEE International Conference on Robotics and Automation (ICRA), 2011
Documentation
A detailed description of how the library is structured and how to use and extend it can be found in /doc/g2o.pdf The API documentation can be generated as described in doc/doxygen/readme.txt
License
g2o is licensed under the BSD License. However, some libraries are available under different license terms. See below.
The following parts are licensed under LGPL v2.1+:
- csparse_extension
The following parts are licensed under GPL3+:
- g2o_viewer
- g2o_incremental
- slam2d_g2o (example for 2D SLAM with a QGLviewer GUI)
Please note that some features of CHOLMOD (which may be used by g2o, see libsuitesparse below) are licensed under the GPL. To avoid the GPL, you may have to re-compile CHOLMOD without including its GPL features. The CHOLMOD library distributed with, for example, Ubuntu or Debian includes the GPL features. For example, the supernodal factorization that is licensed under GPL is considered by g2o if it is available.
Within sub-folders we include software not written by us to guarantee easy compilation and integration into g2o itself.
-
ceres: BSD (see g2o/autodiff/LICENSE) Extracted headers to perform Automatic Differentiation.
-
freeglut: X-Consortium (see g2o/EXTERNAL/freeglut/COPYING) Copyright (c) 1999-2000 Pawel W. Olszta We use a stripped down version for drawing text in OpenGL.
See the doc folder for the full text of the licenses.
g2o is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the licenses for more details.
Requirements
- C++17 compiler (CI pipeline runs with gcc, clang and MSVC)
- cmake http://www.cmake.org
- Eigen3 http://eigen.tuxfamily.org
On Ubuntu / Debian these dependencies are resolved by installing the following packages.
- cmake
- libeigen3-dev
Optional requirements
- spdlog https://github.com/gabime/spdlog
- suitesparse http://faculty.cse.tamu.edu/davis/suitesparse.html
- Qt5 http://qt-project.org
- libQGLViewer https://gillesdebunne.github.io/libQGLViewer/
On Ubuntu / Debian these dependencies are resolved by installing the following packages.
- libspdlog-dev
- libsuitesparse-dev
- qtdeclarative5-dev
- qt5-qmake
- libqglviewer-dev-qt5
You can install those packages with the following command
sudo apt install libeigen3-dev libspdlog-dev libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
Mac OS X
If using Homebrew, then
brew install g2o
will install g2o together with its required dependencies. In this case no manual compilation is necessary.
Windows
If using vcpkg, then
script\install-deps-windows.bat
or for full dependencies installation
script\install-additional-deps-windows.bat
will build and install the dependencies. The location of vcpkg and required
triplet can be passed as cli arguments respectively. Note that usually vcpkg
will auto detect the triplet. Set it only if your are not using the default
build for your OS.
Compilation
Our primary development platform is Linux. Experimental support for Mac OS X, Android and Windows (MinGW or MSVC). We recommend a so-called out of source build which can be achieved by the following command sequence.
mkdir build
cd build
cmake ../
make
The binaries will be placed in bin and the libraries in lib which are both located underneath cmake's build folder.
On Windows with vcpkg the following commands will generate build scripts (please change the Visual Studio version number in accordance with your system):
mkdir build
cd build
cmake -DG2O_BUILD_APPS=ON -DG2O_BUILD_EXAMPLES=ON-DVCPKG_TARGET_TRIPLET="%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT_DIR%\scripts\buildsystems\vcpkg.cmake" ..`
cmake --build . --target ALL_BUILD
If you are compiling on Windows and you are for some reasons not using vcpkg please download Eigen3 and extract it.
Within cmake-gui set the variable EIGEN3_INCLUDE_DIR to that directory.
mkdir build
cd build
cmake .. -DG2O_BUILD_APPS=ON -DG2O_BUILD_EXAMPLES=ON -DEIGEN3_INCLUDE_DIR="<THE_PATH_WHERE_YOU_PLACED_EIGEN3_AND_THE_EIGEN3_CMakeLists.txt>"
Cross-Compiling for Android
mkdir build`
cd build`
cmake -DCMAKE_TOOLCHAIN_FILE=../script/android.toolchain.cmake -DANDROID_NDK=<YOUR_PATH_TO_ANDROID_NDK_r10d+> -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="armeabi-v7a with NEON" -DEIGEN3_INCLUDE_DIR="<YOUR_PATH_TO_EIGEN>" -DEIGEN3_VERSION_OK=ON ..
cmake --build .
Acknowledgments
We thank the following contributors for providing patches:
- Simon J. Julier: patches to achieve compatibility with Mac OS X and others.
- Michael A. Eriksen for submitting patches to compile with MSVC.
- Mark Pupilli for submitting patches to compile with MSVC.
Projects using g2o
- g2o-python: Python binding which is also installable via
pip - .Net wrapper