Skip to content

Monocular, Stereo, and RGBD Visual SLAM System#4101

Open
QueenofUSSR wants to merge 22 commits into
opencv:4.xfrom
QueenofUSSR:slam
Open

Monocular, Stereo, and RGBD Visual SLAM System#4101
QueenofUSSR wants to merge 22 commits into
opencv:4.xfrom
QueenofUSSR:slam

Conversation

@QueenofUSSR
Copy link
Copy Markdown

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

OpenCV VSLAM Module

Monocular, stereo, and RGBD visual SLAM system for OpenCV.

Features

  • Multiple camera models: Perspective, fisheye, equirectangular
  • Map save/load: Store and reuse pre-built maps
  • Localization mode: Re-localize in pre-built maps
  • Loop closure: Detect and correct drift using place recognition
  • Backend optimization: Sliding window bundle adjustment
  • Modular design: Pluggable feature detectors and matchers

Quick Start

#include <opencv2/slam.hpp>
#include <opencv2/features2d.hpp>

// Create feature detector and matcher
auto orb = cv::ORB::create(1000);
auto matcher = cv::BFMatcher::create(cv::NORM_HAMMING);

// Configure SLAM
cv::vo::VOConfig config;
config.camera_config_file = "camera.yaml";
config.vocab_file = "orb_vocab.fbow";
config.enable_backend = true;
config.enable_loop_closure = true;

// Create SLAM system
auto slam = cv::vo::VisualOdometry::create(config, orb, matcher);

// Process frames
for (const auto& frame : frames) {
    auto pose = slam->processFrame(frame.image, frame.timestamp);
    if (pose.has_value()) {
        // Use pose
    }
}

// Save map
slam->saveMap("map.msgpack");

// Cleanup
slam->release();

Examples

See samples/cpp/ directory for complete examples:

  • full_slam.cpp - Complete SLAM pipeline
  • localization_mode.cpp - Localization with pre-built map
  • map_save_load.cpp - Map save/load demonstration

Build

cd opencv_contrib_slam/modules/slam/build
cmake -DBUILD_SAMPLES=ON ..
make -j4

Documentation

License

BSD-2-Clause license

Based on stella_vslam (BSD-2-Clause)

QueenofUSSR and others added 4 commits April 2, 2026 03:21
5 bug fixes verified by ablation experiments (EuRoC MH01):

1. set_enable_backend(false) now propagates to mapper_->set_enable_local_BA(false)
   - Previously only set a flag but local BA ran unconditionally
2. Added enable_local_BA_ flag and skip guard in mapping_module::mapping_with_new_keyframe()
3. Fixed VO default values: backend_enabled_ and loop_closure_enabled_ default to true
   - Was inconsistent with system class (both true there)
4. Removed dead code should_skip_backend() and should_skip_loop_closure()
   - Declared/defined but never called anywhere
5. set_ba_window_size() now propagates to mapper_->set_ba_window_size()

Results after fix (vs before):
- Pure_VO tracking: 42.6% (was 30.5%) - local BA correctly disabled now
- Full_SLAM tracking: 99.73% (was 99.54%) - consistent with local version
- ATE RMSE matches local version within stochastic variance
44-99 and others added 2 commits April 23, 2026 19:03
- Rewrite slam.hpp: English Doxygen docs, @name groups, pure virtual
  getFeatureDetector()/getMatcher(), remove getCamera() and protected
  members, add CV_EXPORTS_W_SIMPLE to VOConfig, use OPENCV_SLAM_HPP guard
- Add impl overrides in visual_odometry_impl for new pure virtual
  getters, add private config_ member (moved from base)
- Replace 5 TODO markers with FIXME/NOTE across keyframe.cpp,
  relocalizer.cpp, projection_factor.hpp, local_bundle_adjuster_gtsam.cpp
- Add 14 unit tests (test_slam.cpp, test_precomp.hpp, test_main.cpp)
- Rewrite test/CMakeLists.txt to OpenCV standard (ocv_add_accuracy_tests)
- Add ocv_add_accuracy_tests() to module CMakeLists.txt
- loop_detector: fix premature return (return false -> continue)
- relocalizer: set ref_keyfrm_ after successful relocation
- projection_factor.hpp: add missing g_log_tag definition
- local_bundle_adjuster_gtsam.cpp:
  - Use chi-square threshold (5.991) instead of huber_k for outlier rejection
  - Implement second-phase optimization (outlier rejection + re-optimization)
  - Fix log message using wrong landmark id
QueenofUSSR and others added 16 commits May 13, 2026 15:00
- yaml-cpp → cv::FileStorage + cv::FileNode (config.hpp/cpp, util/yaml.hpp, 30+ files)
- OpenMP → cv::parallel_for_ (orb_extractor.cpp, mapping_module.cpp, stereo.cpp)
- msgpack binary → JSON text format (map_database_io_msgpack.cpp)
- Removed cmake/FindYamlCpp.cmake, USE_OPENMP block from CMakeLists.txt
- Added YAML pre-processor for cv::FileStorage compatibility
- Fixed samples to create output directory before saving
- Fixed missing includes (graph_node.cpp, orb_extractor.hpp)
- Move samples from samples/cpp/ to samples/
- Rename samples to follow OpenCV naming convention: example_slam_<name>.cpp
- Move testdata from testdata/ to samples/data/
- Update INSTALL.md with BUILD_EXAMPLES=ON instruction
- Update RUNNING_EXAMPLES.md with new paths and binary names
- Changed find_package(SQLite3 REQUIRED) -> QUIET
- Added USE_SQLITE3 compile definition and CMake source filtering
- Guarded #include <sqlite3.h> and sqlite3 method decls/impls
  across all data classes (keyframe, landmark, marker, map_database,
  camera_database) and I/O factory
- Module builds and runs with or without SQLite3
- JSON map I/O backend always available as fallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants