Skip to content

About

CoconutSLAM is a SLAM written in bad C++ code. It is bad and the code is terrible, but it is a SLAM. Come and contribute!

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

CoconutSLAM

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.

CoconutSLAM running on a KITTI driving sequence

Running on a KITTI raw driving sequence (2011_09_26) with the dataset's camera intrinsics.

Pipeline

For each new frame:

  1. Feature detection: Shi-Tomasi corners (goodFeaturesToTrack), with optional grid-based detection to spread features across the image.
  2. 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.
  3. Pose estimation: the essential matrix from the matched points (RANSAC), then the relative rotation and translation recovered with recoverPose.
  4. Triangulation: matched points are undistorted and triangulated from consecutive poses into 3D map points. Each point records which frames observed it.
  5. Visualisation: a separate render thread uses Pangolin to draw the camera trajectory and point cloud while the main thread processes video.

Building and running

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.mp4

To 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.

Limitations

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.

Possible next steps

  • 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/ and src/, and store map points in a structure better suited to lookups.

License

See LICENSE.

About

CoconutSLAM is a SLAM written in bad C++ code. It is bad and the code is terrible, but it is a SLAM. Come and contribute!

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Contributors

Languages