Overview
TheOptimizer class provides various optimization methods for pose estimation and bundle adjustment in ORB-SLAM3. It uses the g2o (General Graph Optimization) framework with Levenberg-Marquardt and Gauss-Newton solvers.
Header: include/Optimizer.h
Bundle Adjustment
BundleAdjustment
vpKF- Vector of keyframes to optimizevpMP- Vector of map points to optimizenIterations- Number of optimization iterations (default: 5)pbStopFlag- Optional flag to stop optimization earlynLoopKF- Loop closure keyframe ID (default: 0)bRobust- Whether to use robust kernel (default: true)
- Optimizes camera poses and 3D point positions jointly
- Uses robust Huber kernel to handle outliers
- Can be interrupted via stop flag
GlobalBundleAdjustemnt
pMap- Map containing all keyframes and map pointsnIterations- Number of optimization iterations (default: 5)pbStopFlag- Optional flag to stop optimization earlynLoopKF- Loop closure keyframe ID (default: 0)bRobust- Whether to use robust kernel (default: true)
LocalBundleAdjustment
pKF- Central keyframe for local optimizationpbStopFlag- Optional flag to stop optimization earlypMap- Current mapnum_fixedKF- Output: number of fixed keyframesnum_OptKF- Output: number of optimized keyframesnum_MPs- Output: number of map pointsnum_edges- Output: number of edges in graph
- Optimizes local window of keyframes
- Fixes distant keyframes as constraints
- Runs in local mapping thread
- More efficient than global BA
Pose Optimization
PoseOptimization
pFrame- Frame to optimize
- Fixes 3D map points
- Optimizes only the 6-DOF camera pose
- Uses reprojection error
- Fast optimization for tracking
PoseInertialOptimizationLastKeyFrame
pFrame- Frame to optimizebRecInit- Whether recovering from initialization (default: false)
PoseInertialOptimizationLastFrame
pFrame- Frame to optimizebRecInit- Whether recovering from initialization (default: false)
Essential Graph Optimization
OptimizeEssentialGraph
pMap- Current mappLoopKF- Loop closure keyframepCurKF- Current keyframeNonCorrectedSim3- Sim3 poses before correctionCorrectedSim3- Sim3 poses after correctionLoopConnections- Loop closure connectionsbFixScale- Whether to fix scale (true for stereo/RGB-D, false for mono)
- Uses Sim3 (7-DOF) for monocular
- Uses SE3 (6-DOF) for stereo/RGB-D
- Distributes loop closure error across covisibility graph
OptimizeEssentialGraph4DoF
- Same as
OptimizeEssentialGraphbut withoutbFixScale
Sim3 Optimization
OptimizeSim3
pKF1- First keyframepKF2- Second keyframevpMatches1- Matched map points from KF1g2oS12- Input/output Sim3 transformationth2- Chi-squared threshold for outlier rejectionbFixScale- Whether to fix scale (true for stereo/RGB-D)mAcumHessian- Output accumulated Hessian matrixbAllPoints- Whether to use all points (default: false)
Inertial Optimization
FullInertialBA
pMap- Map to optimizeits- Number of iterationsbFixLocal- Whether to fix local keyframes (default: false)nLoopKF- Loop closure keyframe ID (default: 0)pbStopFlag- Optional stop flagbInit- Whether in initialization phase (default: false)priorG- Prior weight for gravity (default: 100)priorA- Prior weight for acceleration (default: 1e6)vSingVal- Output singular valuesbHess- Output Hessian flag
- Optimizes poses, velocities, and IMU biases
- Includes IMU preintegration constraints
- Uses prior constraints on gravity and biases
LocalInertialBA
pKF- Central keyframepbStopFlag- Optional stop flagpMap- Current mapnum_fixedKF- Output: number of fixed keyframesnum_OptKF- Output: number of optimized keyframesnum_MPs- Output: number of map pointsnum_edges- Output: number of edgesbLarge- Whether using large window (default: false)bRecInit- Whether recovering from initialization (default: false)
InertialOptimization
pMap- Map to optimizeRwg- Output: rotation from world to gravity-aligned framescale- Output: scale factor (monocular)bg- Output: gyroscope biasba- Output: accelerometer biasbMono- Whether monocular modecovInertial- Output: inertial covariancebFixedVel- Whether to fix velocities (default: false)bGauss- Whether to use Gaussian constraints (default: false)priorG- Prior weight for gravity (default: 100)priorA- Prior weight for acceleration (default: 1e6)
Utility Functions
Marginalize
H- Input Hessian matrixstart- Start index of block to marginalizeend- End index of block to marginalize
- Used for removing variables from optimization
- Preserves information through Schur complement
- Marginalized elements filled with zeros
g2o Integration
The Optimizer class uses g2o framework components:- Sparse Block Matrix - Efficient sparse matrix storage
- Block Solver - Specialized solver for SLAM problems
- Levenberg-Marquardt - Non-linear optimization algorithm
- Gauss-Newton - Alternative optimization algorithm
- Eigen Solver - Linear system solver
- Robust Kernels - Huber kernel for outlier rejection
Usage Example
Optimization Types
Pose-Only
- Optimizes camera pose only
- Fixes 3D map points
- Fast optimization for tracking
- Runs every frame
Local Bundle Adjustment
- Optimizes local window of keyframes
- Optimizes observed map points
- Fixes distant keyframes
- Runs in local mapping thread
Global Bundle Adjustment
- Optimizes entire map
- All keyframes and map points
- Computationally expensive
- Runs after loop closure
Essential Graph
- Optimizes only keyframe poses
- Uses covisibility graph edges
- Faster than full BA
- Distributes loop closure error
See Also
- Tracking - Uses pose optimization
- LocalMapping - Uses local BA
- LoopClosing - Uses global BA and essential graph
- Frame - Frame pose optimization
- KeyFrame - Keyframe in bundle adjustment