# raulmur/orb_slam2 architecture

> Architecture diagram of the GitHub repository raulmur/orb_slam2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raulmur/orb_slam2
- Repository: https://github.com/raulmur/orb_slam2

## Overview

##### Main Components
- System: The central controller that initializes and manages the SLAM process.
- Tracking: Responsible for tracking the camera’s pose with each frame.
- Local Mapping: Builds and optimizes the local map using keyframes.
- Loop Closing: Detects when the system revisits an area and adjusts the map accordingly.
- KeyFrame, KeyFrameDatabase, Map, MapPoint, Frame, FrameDrawer, Viewer: These form the data structures and visualization components.
- Initializer, ORBextractor, ORBmatcher, Optimizer, PnPsolver, Sim3Solver: Essential algorithms for feature extraction, matching, optimization, and pose estimation.
- Examples and Modes: Represent the various front-end executables for monocular, stereo, and RGB-D modalities (as seen in the Examples directory), and indicate that there is also a ROS interface.
- DBoW2: For place recognition via bag-of-words.
- g2o: For graph optimization.

##### Relationships and Data Flow
- Input Camera Streams (from Monocular, Stereo, or RGB-D sensors) feed images into the Tracking module.
- Tracking passes keyframes and feature data to Local Mapping and Loop Closing.
- The Viewer component reads data from the Map and Tracking outputs to provide a real-time GUI.
- Clearly label interactions between the main modules (e.g., “Feature Extraction” between the raw image input and Tracking through ORBextractor; “Graph Optimization” between Loop Closing and the Optimizer using g2o).
- That the System class orchestrates calls among these modules.

##### Architectural Patterns and Design Principles
- Extensibility: Show that the system supports multiple sensor types via configurable input paths/settings (demonstrated by having separate example applications for different datasets).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Sensor Input / Examples"
        MonoExamples["Monocular Examples"]:::sensor
        StereoExamples["Stereo Examples"]:::sensor
        RGBDExamples["RGB-D Examples"]:::sensor
        ROSInterface["ROS Node Interface"]:::sensor
        CAMERA["Camera/Sensor Input"]:::sensor
        MonoExamples --> CAMERA
        StereoExamples --> CAMERA
        RGBDExamples --> CAMERA
        ROSInterface --> CAMERA
    end

    subgraph "Core SLAM Engine"
        SYSTEM["System"]:::core
        TRACKING["Tracking"]:::core
        LOCAL_MAPPING["Local Mapping"]:::core
        LOOP_CLOSING["Loop Closing"]:::core
        MAP["Map"]:::core
        VIEWER["Viewer/MapDrawer"]:::core
        KEYS_FRAME["KeyFrame"]:::core
        KEYFRAME_DB["KeyFrameDatabase"]:::core
        MAPPOINT["MapPoint"]:::core
        FRAME["Frame"]:::core
        FRAME_DRAWER["FrameDrawer"]:::core
        INITIALIZER["Initializer"]:::algo
        ORBEXTRACTOR["ORBextractor"]:::algo
        ORBMATCHER["ORBmatcher"]:::algo
        OPTIMIZER["Optimizer"]:::algo
        PNP_SOLVER["PnPsolver"]:::algo
        SIM3_SOLVER["Sim3Solver"]:::algo
    end

    subgraph "External Dependencies"
        DBoW2["DBoW2"]:::external
        g2o["g2o"]:::external
        OPEN_CV["OpenCV"]:::external
        PANGOLIN["Pangolin"]:::external
        EIGEN["Eigen"]:::external
        CMAKE["CMake Build"]:::external
        VOCAB["VOCABULARY"]:::external
    end

    %% Data Flow Connections
    CAMERA -->|"CameraFrames"| TRACKING
    SYSTEM -->|"orchestrates"| TRACKING
    SYSTEM -->|"orchestrates"| LOCAL_MAPPING
    SYSTEM -->|"orchestrates"| LOOP_CLOSING
    SYSTEM -->|"orchestrates"| VIEWER

    TRACKING -->|"KeyFrames"| LOCAL_MAPPING
    TRACKING -->|"FeatureData"| LOOP_CLOSING
    TRACKING -->|"mapUpdate"| MAP
    LOCAL_MAPPING -->|"mapUpdate"| MAP
    LOOP_CLOSING -->|"triggerOptimization"| OPTIMIZER
    OPTIMIZER -->|"updateMap"| MAP
    MAP -->|"visualData"| VIEWER

    %% Integration of Essential Algorithms
    TRACKING -->|"initializes"| INITIALIZER
    TRACKING -->|"featureExtraction"| ORBEXTRACTOR
    ORBEXTRACTOR -->|"providesFeatures"| ORBMATCHER
    TRACKING -->|"poseEstimation"| PNP_SOLVER
    TRACKING -->|"scaleEstimation"| SIM3_SOLVER
    LOOP_CLOSING -->|"graphOpt"| OPTIMIZER

    %% External Dependencies Integration
    DBoW2 -->|"placeRec"| TRACKING
    g2o -->|"graphOpt"| OPTIMIZER
    OPEN_CV --- TRACKING
    PANGOLIN --- VIEWER
    EIGEN --- SYSTEM
    CMAKE --- SYSTEM
    VOCAB --- SYSTEM

    %% Styling Classes
    classDef sensor fill:#D5F5E3,stroke:#2ECC71,stroke-width:2px;
    classDef core fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef algo fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;

    %% Click Events for Core Components and Algorithms
    click SYSTEM "https://github.com/raulmur/orb_slam2/blob/master/include/System.h"
    click SYSTEM "https://github.com/raulmur/orb_slam2/blob/master/src/System.cc"
    click TRACKING "https://github.com/raulmur/orb_slam2/blob/master/include/Tracking.h"
    click TRACKING "https://github.com/raulmur/orb_slam2/blob/master/src/Tracking.cc"
    click LOCAL_MAPPING "https://github.com/raulmur/orb_slam2/blob/master/include/LocalMapping.h"
    click LOCAL_MAPPING "https://github.com/raulmur/orb_slam2/blob/master/src/LocalMapping.cc"
    click LOOP_CLOSING "https://github.com/raulmur/orb_slam2/blob/master/include/LoopClosing.h"
    click LOOP_CLOSING "https://github.com/raulmur/orb_slam2/blob/master/src/LoopClosing.cc"
    click KEYS_FRAME "https://github.com/raulmur/orb_slam2/blob/master/include/KeyFrame.h"
    click KEYS_FRAME "https://github.com/raulmur/orb_slam2/blob/master/src/KeyFrame.cc"
    click KEYFRAME_DB "https://github.com/raulmur/orb_slam2/blob/master/include/KeyFrameDatabase.h"
    click KEYFRAME_DB "https://github.com/raulmur/orb_slam2/blob/master/src/KeyFrameDatabase.cc"
    click MAP "https://github.com/raulmur/orb_slam2/blob/master/include/Map.h"
    click MAP "https://github.com/raulmur/orb_slam2/blob/master/src/Map.cc"
    click MAPPOINT "https://github.com/raulmur/orb_slam2/blob/master/include/MapPoint.h"
    click MAPPOINT "https://github.com/raulmur/orb_slam2/blob/master/src/MapPoint.cc"
    click FRAME "https://github.com/raulmur/orb_slam2/blob/master/include/Frame.h"
    click FRAME "https://github.com/raulmur/orb_slam2/blob/master/src/Frame.cc"
    click FRAME_DRAWER "https://github.com/raulmur/orb_slam2/blob/master/include/FrameDrawer.h"
    click FRAME_DRAWER "https://github.com/raulmur/orb_slam2/blob/master/src/FrameDrawer.cc"
    click VIEWER "https://github.com/raulmur/orb_slam2/blob/master/include/Viewer.h"
    click VIEWER "https://github.com/raulmur/orb_slam2/blob/master/include/MapDrawer.h"
    click VIEWER "https://github.com/raulmur/orb_slam2/blob/master/src/Viewer.cc"
    click VIEWER "https://github.com/raulmur/orb_slam2/blob/master/src/MapDrawer.cc"
    click INITIALIZER "https://github.com/raulmur/orb_slam2/blob/master/include/Initializer.h"
    click INITIALIZER "https://github.com/raulmur/orb_slam2/blob/master/src/Initializer.cc"
    click ORBEXTRACTOR "https://github.com/raulmur/orb_slam2/blob/master/include/ORBextractor.h"
    click ORBEXTRACTOR "https://github.com/raulmur/orb_slam2/blob/master/src/ORBextractor.cc"
    click ORBMATCHER "https://github.com/raulmur/orb_slam2/blob/master/include/ORBmatcher.h"
    click ORBMATCHER "https://github.com/raulmur/orb_slam2/blob/master/src/ORBmatcher.cc"
    click OPTIMIZER "https://github.com/raulmur/orb_slam2/blob/master/include/Optimizer.h"
    click OPTIMIZER "https://github.com/raulmur/orb_slam2/blob/master/src/Optimizer.cc"
    click PNP_SOLVER "https://github.com/raulmur/orb_slam2/blob/master/include/PnPsolver.h"
    click PNP_SOLVER "https://github.com/raulmur/orb_slam2/blob/master/src/PnPsolver.cc"
    click SIM3_SOLVER "https://github.com/raulmur/orb_slam2/blob/master/include/Sim3Solver.h"
    click SIM3_SOLVER "https://github.com/raulmur/orb_slam2/blob/master/src/Sim3Solver.cc"
    click MonoExamples "https://github.com/raulmur/orb_slam2/tree/master/Examples/Monocular"
    click StereoExamples "https://github.com/raulmur/orb_slam2/tree/master/Examples/Stereo"
    click RGBDExamples "https://github.com/raulmur/orb_slam2/tree/master/Examples/RGB-D"
    click ROSInterface "https://github.com/raulmur/orb_slam2/tree/master/Examples/ROS/ORB_SLAM2"
    click DBoW2 "https://github.com/raulmur/orb_slam2/tree/master/Thirdparty/DBoW2"
    click g2o "https://github.com/raulmur/orb_slam2/tree/master/Thirdparty/g2o"
    click CMAKE "https://github.com/raulmur/orb_slam2/blob/master/CMakeLists.txt"
    click VOCAB "https://github.com/raulmur/orb_slam2/blob/master/Vocabulary/ORBvoc.txt.tar.gz"
```
