This is a simple implementation of the Structure from Motion (SfM) algorithm using OpenCV in C++. The following steps are used in the algorithm:
- Feature detection and matching using AKAZE
- Essential matrix estimation
- Camera pose estimation
- Triangulation
- Bundle adjustment (yet to be implemented)
The dataset used in this implementation is the South Building dataset from COLMAP. The dataset can be found at COLMAP Datasets. The camera intrinsic parameters are provided with the dataset.
The reconstructed point cloud is visualized using the Open3D library in Python.
-
Clone the repository
-
Download and Unzip the dataset
south-building.zipin the same directory. I have used a subset of the dataset. -
Run the following commands (Don't forget to add "/" at the end of the path):
mkdir build cd build cmake .. make ./sfm "path_to_dataset/"
-
Run
pcd_vis.pyto visualize the point cloud
The following gif shows the point cloud generated from the dataset:
- Most of the code is taken from the SfM implementation by nghiaho12. The original code can be found at nghiaho12/SFM_example.
- The dataset is taken from the COLMAP dataset. The original dataset can be found at COLMAP Datasets.
