A monocular visual SLAM front end written from scratch in C++ with OpenCV, built as a summer project in July–August 2021. It takes a single video stream, tracks features between frames, estimates camera motion and triangulates a sparse 3D point cloud. A live 3D viewer shows the result.
Running on a KITTI raw driving sequence (2011_09_26) with the dataset's camera intrinsics.
For each new frame:
- Feature detection: Shi-Tomasi corners (
goodFeaturesToTrack), with optional grid-based detection to spread features across the image. - Description and matching: ORB descriptors on the detected corners, matched to the previous frame using brute-force k-NN (Hamming distance) with Lowe's ratio test and a distance filter.
- Pose estimation: the essential matrix from the matched points (RANSAC), then the relative rotation and translation recovered with
recoverPose. - Triangulation: matched points are undistorted and triangulated from consecutive poses into 3D map points. Each point records which frames observed it.
- Visualisation: a separate render thread uses Pangolin to draw the camera trajectory and point cloud while the main thread processes video.
Dependencies: OpenCV 3.4, Pangolin 0.4, Eigen3, g2o (linked; see limitations), CMake ≥ 3.16.
mkdir -p build
./build.sh # configures, builds and calls run.sh
./run.sh # runs ./build/slam on videos/2011_09_26.mp4To run on another video: ./build/slam <path-to-video>. The camera intrinsics K in slam.cpp are set for the KITTI camera, so change them for other footage.
This was an early learning project. The front end works, but it is not a complete SLAM system:
- No bundle adjustment or loop closure. A g2o pose-graph optimisation (
graphOptimize) is drafted but not yet wired into the pipeline, so drift accumulates over long sequences. - Monocular scale ambiguity. Translation is only known up to scale between frames.
- Qualitative evaluation only. The results are visual. The trajectory has not been compared with KITTI ground truth (e.g. ATE/RPE).
- Single-file layout. All code is in
slam.cpp.
- Wire in g2o bundle adjustment over a sliding window of keyframes.
- Evaluate trajectory error against KITTI odometry ground truth.
- Keyframe selection, map-point culling and relocalisation, following ORB-SLAM2.
- Split into
include/andsrc/, and store map points in a structure better suited to lookups.
See LICENSE.
