Convert Figma logo to code with AI

borglab logogtsam

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.

3,635
978
3,635
19

Top Related Projects

A large scale non-linear optimization library

3,458

g2o: A General Framework for Graph Optimization

2,455

C++ implementation of Lie Groups using Eigen.

5,725

The Kalibr visual-inertial calibration toolbox

Quick Overview

GTSAM is an open-source C++ library that implements smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm. It provides a set of nonlinear factor types and inference algorithms to solve simultaneous localization and mapping (SLAM) and structure from motion (SFM) problems.

Pros

  • High performance and efficiency due to its C++ implementation
  • Flexible and extensible architecture allowing for custom factors and noise models
  • Comprehensive documentation and examples for various use cases
  • Active community and ongoing development

Cons

  • Steep learning curve for beginners due to its complex mathematical foundations
  • Limited support for real-time applications compared to some alternatives
  • Primarily focused on C++, with limited bindings for other languages
  • Can be computationally intensive for large-scale problems

Code Examples

  1. Creating a simple 2D pose graph:
#include <gtsam/slam/PriorFactor.h>
#include <gtsam/slam/BetweenFactor.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/nonlinear/LevenbergMarquardtOptimizer.h>
#include <gtsam/nonlinear/Values.h>

using namespace gtsam;

int main() {
    NonlinearFactorGraph graph;
    Values initialEstimate;

    // Add a prior on the first pose, setting it to the origin
    Pose2 priorMean(0.0, 0.0, 0.0);
    noiseModel::Diagonal::shared_ptr priorNoise = noiseModel::Diagonal::Sigmas(Vector3(0.3, 0.3, 0.1));
    graph.add(PriorFactor<Pose2>(1, priorMean, priorNoise));

    // Add odometry factors
    Pose2 odometry(2.0, 0.0, 0.0);
    noiseModel::Diagonal::shared_ptr odometryNoise = noiseModel::Diagonal::Sigmas(Vector3(0.2, 0.2, 0.1));
    graph.add(BetweenFactor<Pose2>(1, 2, odometry, odometryNoise));

    // Initialize the first pose at the origin
    initialEstimate.insert(1, Pose2(0.0, 0.0, 0.0));
    initialEstimate.insert(2, Pose2(2.0, 0.0, 0.0));

    // Optimize using Levenberg-Marquardt optimization
    LevenbergMarquardtOptimizer optimizer(graph, initialEstimate);
    Values result = optimizer.optimize();

    return 0;
}
  1. Adding a landmark to a 2D SLAM problem:
#include <gtsam/slam/BearingRangeFactor.h>

// ... (previous includes and setup)

int main() {
    // ... (previous graph and initial estimate setup)

    // Add a landmark
    Point2 landmark(5.0, 1.0);
    initialEstimate.insert(L1, landmark);

    // Add a measurement to the landmark
    Rot2 bearing = Rot2::fromDegrees(45);
    double range = 5.0;
    graph.add(BearingRangeFactor<Pose2, Point2>(1, L1, bearing, range, measurementNoise));

    // ... (optimization and result handling)
}
  1. Using ISAM2 for incremental SLAM:
#include <gtsam/nonlinear/ISAM2.h>

// ... (previous includes and setup)

int main() {
    ISAM2Params parameters;
    parameters.relinearizeThreshold = 0.01;
    parameters.relinearizeSkip = 1;
    ISAM2 isam(parameters);

    for (int i = 0; i < numPoses; ++i) {
        NonlinearFactorGraph newFactors

Competitor Comparisons

A large scale non-linear optimization library

Pros of Ceres Solver

  • More flexible problem formulation, allowing for a wider range of optimization problems
  • Better performance for large-scale problems with sparse structure
  • More extensive documentation and examples

Cons of Ceres Solver

  • Steeper learning curve, especially for users new to optimization
  • Less intuitive API for factor graph problems compared to GTSAM
  • Requires more manual setup for certain types of problems

Code Comparison

GTSAM example (factor graph):

NonlinearFactorGraph graph;
graph.add(PriorFactor<Pose3>(X(1), pose_prior, prior_noise));
graph.add(BetweenFactor<Pose3>(X(1), X(2), odom, odom_noise));

Ceres Solver example (general optimization):

ceres::Problem problem;
problem.AddResidualBlock(
    new ceres::AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor),
    nullptr,
    &x);

Both libraries are powerful optimization tools, but GTSAM is more specialized for factor graphs and SLAM problems, while Ceres Solver offers more flexibility for general optimization tasks.

3,458

g2o: A General Framework for Graph Optimization

Pros of g2o

  • More flexible and extensible architecture, allowing easier implementation of custom graph optimization problems
  • Generally faster execution times for large-scale optimization problems
  • Better support for 3D vision and robotics applications

Cons of g2o

  • Steeper learning curve and more complex API compared to GTSAM
  • Less comprehensive documentation and tutorials
  • Smaller community and fewer maintained examples

Code Comparison

g2o:

g2o::SparseOptimizer optimizer;
g2o::BlockSolver_6_3::LinearSolverType* linearSolver;
linearSolver = new g2o::LinearSolverEigen<g2o::BlockSolver_6_3::PoseMatrixType>();
g2o::BlockSolver_6_3* solver_ptr = new g2o::BlockSolver_6_3(linearSolver);
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr);

GTSAM:

gtsam::NonlinearFactorGraph graph;
gtsam::Values initialEstimate;
gtsam::LevenbergMarquardtOptimizer optimizer(graph, initialEstimate);
gtsam::Values result = optimizer.optimize();

Both libraries offer powerful optimization capabilities, but g2o provides more flexibility at the cost of complexity, while GTSAM offers a more straightforward API with extensive documentation.

2,455

C++ implementation of Lie Groups using Eigen.

Pros of Sophus

  • Lightweight and focused on Lie groups and algebras
  • Easier to integrate into existing projects due to its simplicity
  • Header-only library, simplifying build processes

Cons of Sophus

  • Limited scope compared to GTSAM's comprehensive functionality
  • Fewer optimization and estimation tools
  • Smaller community and less extensive documentation

Code Comparison

Sophus example (rotation matrix to quaternion):

Sophus::SO3d R = Sophus::SO3d::exp(Sophus::Vector3d(0.1, 0.2, 0.3));
Eigen::Quaterniond q = R.unit_quaternion();

GTSAM example (rotation matrix to quaternion):

gtsam::Rot3 R = gtsam::Rot3::Expmap(gtsam::Vector3(0.1, 0.2, 0.3));
gtsam::Quaternion q = R.quaternion();

Both libraries provide similar functionality for basic operations, but GTSAM offers a more extensive set of tools for complex robotics and computer vision tasks. Sophus is more focused on efficient Lie group operations, while GTSAM provides a broader range of probabilistic inference and optimization capabilities.

5,725

The Kalibr visual-inertial calibration toolbox

Pros of Kalibr

  • Specialized for camera-IMU calibration and multi-sensor calibration
  • User-friendly GUI for visualization and parameter tuning
  • Supports various camera models and sensor configurations

Cons of Kalibr

  • More limited in scope compared to GTSAM's general-purpose optimization
  • Less active development and community support
  • Primarily focused on calibration, lacking broader SLAM capabilities

Code Comparison

Kalibr (Python-based calibration):

import kalibr_common as kc
import kalibr_camera_calibration as kcc

cam = kc.CameraGeometry(geometry_type='pinhole-radtan')
imu = kc.ImuParameters()
calib = kcc.CameraImuCalibration(cam, imu)
calib.optimize()

GTSAM (C++ factor graph optimization):

#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/slam/PriorFactor.h>

gtsam::NonlinearFactorGraph graph;
graph.add(gtsam::PriorFactor<gtsam::Pose3>(1, initialPose, noisePrior));
gtsam::Values result = gtsam::LevenbergMarquardtOptimizer(graph, initial).optimize();

Both repositories serve different primary purposes, with Kalibr focusing on sensor calibration and GTSAM offering a broader range of optimization tools for various robotics and computer vision applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

GTSAM: Georgia Tech Smoothing and Mapping Library

C++ API Docs

GTSAM manifold optimization workflow: build a factor graph, linearize and solve in tangent spaces, retract to manifolds, and iterate to convergence.

Development branch

The develop branch contains changes intended for the next GTSAM release and may include API changes. For production use, choose the latest stable version from the GTSAM releases. Current development builds require C++17; Boost support is optional and controlled by CMake options.

What is GTSAM?

GTSAM is a C++ library that implements smoothing and mapping (SAM) in robotics and vision, using Factor Graphs and Bayes Networks as the underlying computing paradigm rather than sparse matrices.

CI StatusPlatformCompiler
Python CIUbuntu 22.04, macOS 15, Windows 2022GCC/Clang/MSVC
vcpkgLatest Windows/Ubuntu/Mac-
Build Wheels for DevelopSee pypi files; no Windows-

On top of the C++ library, GTSAM includes wrappers for MATLAB & Python.

Documentation

Quickstart

In the root library folder execute:

cmake -S . -B build
cmake --build build --target check  # optional, runs all unit tests
cmake --build build --target install

Prerequisites:

  • CMake 3.16 or newer
  • A compiler with C++17 support. The continuously tested toolchains are:
    • Linux: GCC 11, 13, 14, or 15 and Clang 11, 14, or 16
    • macOS: Xcode 16
    • Windows: MSVC toolset 14.40

Older C++17-capable toolchains may work but are not continuously tested.

Optional Boost prerequisite:

Boost is optional. Two CMake flags govern its use:

  • GTSAM_USE_BOOST_FEATURES=ON|OFF controls the remaining Boost-dependent features.
  • GTSAM_ENABLE_BOOST_SERIALIZATION=ON|OFF controls Boost serialization of factor graphs, factors, and related types.

Both options default to ON for ordinary CMake builds and OFF inside ROS 2 colcon builds. If either option is ON, install Boost 1.70 or newer:

  • macOS: brew install boost
  • Ubuntu: sudo apt-get install libboost-all-dev
  • Windows: use vcpkg, or see cmake/HandleBoost.cmake for manual-installation hints.

Optional prerequisites:

  • oneTBB is searched for when GTSAM_WITH_TBB=ON, which is the default. On Ubuntu, install libtbb-dev.
  • Intel oneMKL is used only when GTSAM_WITH_EIGEN_MKL=ON. See INSTALL.md for setup instructions, and benchmark your workload with and without MKL.

GTSAM 4 Compatibility

GTSAM 4 introduced Expressions, a Python toolbox, and traits that allow optimization with non-GTSAM types. Point2 and Point3 are Eigen vector aliases; their default constructors do not initialize their coefficients, so initialize them explicitly before use.

GTSAM_ALLOW_DEPRECATED_SINCE_V43 controls APIs deprecated for the GTSAM 4.3 release and defaults to ON. Disable it while migrating code to identify APIs scheduled for removal after 4.3.

Wrappers

We provide support for MATLAB and Python wrappers for GTSAM. Please refer to the linked documents for more details.

Citation

If you are using GTSAM for academic work, please use the following citation:

@software{gtsam,
  author    = {Frank Dellaert and GTSAM Contributors},
  title     = {GTSAM},
  year      = {2022},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.5794541},
  url       = {https://doi.org/10.5281/zenodo.5794541}
}

To cite the Factor Graphs for Robot Perception book, please use:

@book{factor_graphs_for_robot_perception,
    author={Frank Dellaert and Michael Kaess},
    year={2017},
    title={Factor Graphs for Robot Perception},
    publisher={Foundations and Trends in Robotics, Vol. 6},
    url={http://www.cs.cmu.edu/~kaess/pub/Dellaert17fnt.pdf}
}

If you are using the IMU preintegration scheme, please cite:

@inproceedings{Forster-RSS-15,
    author    = {Christian Forster and Luca Carlone and Frank Dellaert and Davide Scaramuzza},
    title     = {IMU Preintegration on Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation},
    booktitle = {Proceedings of Robotics: Science and Systems},
    year      = {2015},
    address   = {Rome, Italy},
    month     = {July},
    doi       = {10.15607/RSS.2015.XI.006}
}

The Preintegrated IMU Factor

GTSAM includes a state of the art IMU handling scheme based on

  • Todd Lupton and Salah Sukkarieh, "Visual-Inertial-Aided Navigation for High-Dynamic Motion in Built Environments Without Initial Conditions", TRO, 28(1):61-76, 2012. [link]

Our implementation improves on this using integration on the manifold, as detailed in

  • Christian Forster, Luca Carlone, Frank Dellaert, and Davide Scaramuzza, "IMU Preintegration on Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation", Robotics: Science and Systems (RSS), 2015. [link]

If you are using the factor in academic work, please cite the publications above.

In GTSAM 4 a new and more efficient implementation, based on integrating on the NavState tangent space and detailed in this document, is enabled by default. To switch to the RSS 2015 version, set the flag GTSAM_TANGENT_PREINTEGRATION to OFF.

Additional Information

There is a GTSAM users Google group for general discussion.

Read about important GTSAM concepts. A primer on GTSAM Expressions, which support efficient automatic differentiation, is available in doc/expressions.md.

See the INSTALL file for more detailed installation instructions. Our CI/CD process is detailed in workflows.md.

GTSAM is open source under the BSD license, see the LICENSE and LICENSE.BSD files.

Please see the examples/ directory and the USAGE file for examples on how to use GTSAM.

GTSAM was developed in the lab of Frank Dellaert at the Georgia Institute of Technology, with the help of many contributors over the years, see THANKS.