OPEN SOURCE DEEP DIVE
RigVis: Stereo-Inertial SLAM with Dense 3D Mapping
RigVis combines stereo vision and IMU measurements for localization and dense 3D mapping, with keyframe clouds that follow loop-closure pose corrections.
RigVis is a stereo visual-inertial SLAM system implemented from first principles in C++17. It uses rectified stereo images, inertial measurements, and camera calibration only. There is no LiDAR and no general-purpose visual localization framework underneath. The project connects sparse tracking, Ceres bundle adjustment, pose-graph loop closure, an error-state Kalman filter, and dense stereo mapping in one pipeline, then evaluates the full 4,544-frame KITTI 00 sequence.
The useful story is not just that the repository contains several standard SLAM components. The interesting part is how those components exchange constraints and where their boundaries remain. The sections below follow the real data flow from stereo observations to pose estimation, map maintenance, loop correction, inertial fusion, dense reconstruction, and quantitative evaluation.
The problem: make a useful 3D map without LiDAR
Stereo visual odometry recovers metric scale, but its trajectory still accumulates drift. A sparse landmark map can support localization without providing a direct picture of nearby surfaces. RigVis keeps both representations. Sparse features provide fast tracking and geometric validation, keyframes support local optimization and map maintenance, semi-global stereo matching produces near-field dense geometry, and loop closure corrects global drift.
The inertial sensor adds another source of short-horizon motion information. RigVis fuses it through a loosely coupled filter: the visual frontend still estimates each camera-to-camera motion independently, and the filter uses that motion to update an inertial propagation step. This is not a tightly coupled visual-inertial optimizer. The distinction matters because the system can improve short-term stability and estimate sensor biases without claiming that inertial factors participate in bundle adjustment.
Pipeline: from a stereo pair to maps and trajectories
The data loader returns synchronized stereo images, an optional color image, camera projection matrices, the stereo baseline, and the transform from the inertial frame to the rectified left camera. The frontend extracts oriented corner features and distributes them across an image grid so that a highly textured region cannot consume the entire feature budget. It then searches for left-right correspondences near the same rectified image row and converts valid disparities into metric stereo points.
Pose estimation starts from a constant-velocity prediction. Current-frame observations are matched against a local map built from covisible keyframes, and a perspective-n-point RANSAC solve estimates the camera pose. If the local-map path fails, a fallback tracker matches the previous frame's stereo points against the current image. A frame becomes a keyframe only when tracked-point ratios, elapsed frames, and minimum observation counts satisfy the configured rules. Mapping, local optimization, and dense reconstruction are therefore concentrated on selected keyframes rather than repeated on every image.
| Stage | Input | Core operation | Output |
|---|---|---|---|
| Stereo frontend | Rectified left and right images | Grid-distributed features, row-band matching, projection search, PnP RANSAC | Camera pose, stereo observations, tracking status |
| Local mapping | Keyframes and covisible landmarks | Covisibility maintenance, point fusion, outlier removal, two-pass local BA | Locally consistent keyframes and sparse landmarks |
| Loop closure and pose graph | Historical keyframes, descriptor matches, geometric verification | Candidate gating, consistency test, SE(3) pose-graph optimization, global BA | Corrected keyframe poses and map points |
| Visual-inertial fusion | Approximately 100 Hz inertial data and visual relative motion | Robocentric error-state propagation, visual update, chi-square gating | Fused trajectory and sensor-bias estimates |
| Dense mapping and export | Keyframe stereo pairs, optional color images, optimized poses | Semi-global matching, depth back-projection, voxel merge, color projection | Dense cloud, camera path, evaluation files |
Stereo frontend: sparse but deliberately distributed constraints
Feature distribution is the first practical issue. Ranking all corners by response alone often places most observations on foliage, signs, or road markings. RigVis buckets the image into cells and selects features across those cells, giving the pose problem observations from a broader area. Stereo matching exploits rectified epipolar geometry and checks only a row band and valid disparity interval. That restriction is faster than a general two-dimensional search and makes incorrect correspondences easier to reject.
The primary pose path uses the local map. The fallback path uses the previous frame's triangulated stereo points and searches for their projections in the current image. A pose is accepted only when the number of tracked observations, the number of PnP inliers, and the motion consistency check are all plausible. Repeated failures trigger reinitialization rather than allowing an invalid pose to enter the map.
There is no bag-of-words database and no learned keypoint or descriptor. This makes the pipeline easier to inspect, but it also creates an appearance boundary. Repetitive texture, severe illumination change, and large viewpoint shifts are harder than they would be for a modern learned frontend. Loop candidates are selected by position, heading, and local descriptor matching rather than global image retrieval, so a long return path can fail if accumulated drift exceeds the candidate-search radius.
Local bundle adjustment: combine stereo, mono, and noise models
When a keyframe is created, RigVis performs bundle adjustment over its local covisibility neighborhood. Ceres receives stereo and monocular residuals. A stereo observation contributes three residual components, while a monocular observation contributes two. The code does not invent a depth value for the monocular case; it reduces the constraint dimension instead. A Huber loss limits the influence of large residuals, chi-square tests reject outliers, and the observation sigma is scaled by feature-pyramid level so weak high-level observations do not carry the same weight as strong low-level corners.
The solve has two passes. The first removes gross errors and improves the linearization point. The second runs on the cleaner association set. Schur complement removes landmark variables from the dense system and solves only for camera pose blocks, which keeps the local problem manageable. Map points and dense keyframe clouds are anchored to keyframe poses. When optimization or loop closure moves a keyframe, the attached geometry moves with it instead of requiring a second world-coordinate copy.
The source also contains an optional point-to-plane dense registration edge. It is disabled by default. When enabled, it adds a relative-pose constraint between neighboring dense clouds only for a keyframe whose PnP inlier count falls below a gate, and it limits how far the dense measurement may correct the tracker. The authors label this path experimental, which is an appropriate boundary: dense ICP is available for study, but it is not presented as the primary localization source.
Loop closure: prove revisiting before changing history
Loop detection searches older keyframes by nearby position and similar viewing direction. A candidate must be separated by at least one hundred keyframes, preventing ordinary local overlap from being treated as a loop. Descriptor matches are followed by PnP RANSAC. The loop must reach at least sixty inliers and an inlier ratio above 0.3. The system additionally requires two consecutive keyframes to verify links to nearly the same historical place, so one lucky match cannot rewrite the map.
Once verified, the loop supplies an SE(3) pose-graph edge. Pose-graph optimization redistributes error through the trajectory, duplicate map points are fused, and a global bundle adjustment follows. The final trajectory rebuilds every frame from corrected keyframes and the frame-to-keyframe relative motion. As a result, frames processed long before the loop are also corrected, not just the two endpoints.
This loop strategy explicitly assumes that the drift has not pushed the camera outside the local search radius. It works well when the system still knows approximately where it is, and a strict geometric verification reduces false positives. It is not a global place-recognition solution. The roadmap lists bag-of-words detection as future work, which confirms that large-drift recovery remains outside the current design.
Visual-inertial fusion: a robocentric error-state filter
The inertial fusion uses an 18-error-state filter containing rotation, position, velocity, gyroscope bias, accelerometer bias, and gravity direction. The state is expressed relative to the inertial frame at the previous camera frame. This robocentric representation keeps unobservable absolute position and heading out of the state and avoids the observability inconsistency common in conventional error-state-filter visual-inertial systems.
Inertial measurements propagate the state, and the visual frontend supplies a relative camera-motion measurement. A chi-square gate screens the visual residual before each update. Initialization has separate moving and static branches. The moving branch estimates initial velocity and gravity direction by least squares over approximately two seconds. If inertial samples are missing, the covariance is inflated according to the duration of the gap so that stale propagation is not treated as high-confidence motion.
The KITTI configuration also exposes a camera-to-inertial time offset. For sequence 00, a value of negative 0.05 seconds improves agreement between gyroscope angular velocity and visual rotation. This is not a minor implementation detail: high-rate inertial propagation is sensitive to timing error, and a few tens of milliseconds can bias a turn. The project does not use inertial preintegration factors, so the current fusion should be understood as robust visual odometry plus an inertial filter rather than a tightly coupled visual-inertial estimator.
Dense mapping: keyframe stereo matching and voxel consolidation
The sparse map supports tracking; the dense map supports spatial inspection. OpenCV semi-global block matching runs on each selected keyframe at half resolution for speed. Valid disparities are converted back into metric depth using the calibration. The default range is one to twenty meters. Beyond twenty meters, stereo depth uncertainty grows quickly and far points add noise faster than useful structure.
Valid pixels are back-projected into the camera frame and transformed into the map with the optimized keyframe pose. Adjacent keyframes produce heavily overlapping clouds, so points are merged on a ten-centimeter voxel grid. The exporter can color points by height or project them into a KITTI color image when one is available. Because each cloud is attached to its keyframe, loop-closure corrections move the geometry together with the corrected camera pose.
KITTI 00 evaluation: reproducible, but not a claim of state of the art
The evaluation uses KITTI raw drive 2011_10_03_drive_0027, which corresponds to odometry sequence 00. The complete run contains 4,544 frames over 3.7 kilometers. Ground truth comes from the vehicle's GPS and inertial navigation system. Absolute trajectory error is computed after rigid alignment without scale, while relative translation and rotation errors follow the official KITTI sub-path protocol from one hundred to eight hundred meters.
| System | Relative translation | Relative rotation | Absolute trajectory RMSE | Per-frame RPE |
|---|---|---|---|---|
| RigVis | 1.20% | 0.50 degrees / 100 m | 2.81 m | 0.057 m, 0.100 degrees |
| ORB-SLAM2 stereo reference | 0.70% | 0.25 degrees / 100 m | 1.3 m | Not reported with the same per-frame convention |
The result shows a complete long-sequence run that closes loops without trajectory divergence and produces a dense map covering the main road geometry. It does not beat the published ORB-SLAM2 reference. Relative translation error is roughly 1.7 times larger, and absolute trajectory error is roughly 2.2 times larger. That gap is useful context: RigVis favors a transparent implementation and dense mapping path over maximum benchmark accuracy.
Engineering boundary: a readable research stack, not a turnkey robot product
The data loader expects KITTI's raw directory layout, synchronized stereo images, date-level calibration files, and optional extracted inertial data. It does not include a general camera driver, a ROS interface, or an online sensor synchronization layer. A new robot platform requires rectification, stereo extrinsics, inertial-to-camera transforms, time-offset calibration, and buffering around the frontend. Support for one KITTI sequence is not the same as out-of-the-box support for arbitrary stereo-inertial hardware.
Dense reconstruction uses a classical semi-global matcher, so quality depends on texture, exposure, and rectification. Glass, sky, blank walls, and repeated structures can create incorrect correspondences. Ten-centimeter voxels reduce overlap, but long-sequence clouds still require substantial storage. Dense registration is retained as an experimental option rather than a fully validated replacement for feature tracking.
The loop detector lacks global image retrieval, the inertial component is loosely coupled and does not use preintegration factors in local BA, and the frontend relies on hand-designed features. These are concrete limits for high-speed motion, severe lighting change, and very large environments. They do not prevent RigVis from being a useful implementation study. The source is organized so that tracking failures, map updates, loop decisions, filter residuals, and bias estimates can be inspected frame by frame.
The project is MIT licensed and builds with C++17, Eigen, OpenCV, and Ceres. It exports sparse and dense PLY clouds, camera trajectories, keyframe poses, evaluation results, and per-frame diagnostic CSV files. That level of observability is the strongest reason to read the repository: it exposes the full visual-inertial mapping chain in a form that can be modified and tested, rather than hiding every design choice behind a monolithic framework.
Original repository: https://github.com/ekrrems/stereo-inertial-slam
SOURCE LINKS