This repository contains code to reconstruct a scene using structure from motion (SfM). SfM is a technique to recover 3D structure of a scene by making use of a sequence of 2D images. In the process, the technique also recovers the relative pose of a particular view (an image taken by a camera) with respect to the first view in the sequence. This is a personal project.
The process consists of a series of steps:
The code has been run on openMVG's benchmark images. The images come with the intrinsic matrix of the camera as a txt file in the images folder. This code has not been tested on images taken on my camera. Users choosing to do so need to calibrate their camera to obtain the intrinsic matrix required for this code. Follow this tutorial to calibrate your camera.
The entry point of the module is the main.py
file. This file requires three arguments -
--root_dir
: specifies the path of the folder containing the image folder--feat_type
: specifies the kind of features to be extracted from the images (sift/surf/orb), default is sift--image_format
: specifies the extension of the images present inside the images/
folder of the root_dir
, default is jpgFor example, if you have downloaded the benchmark images inside the repository root, then the command would be -
python main.py --root_dir ./SfM_quality_evaluation/Benchmarking_Camera_Calibration_2008/entry-P10 --feat_type surf
Or:
python main.py --root_dir ./SfM_quality_evaluation/Benchmarking_Camera_Calibration_2008/fountain-P11 --feat_type sift
Each of the above mentioned folders have an images/
folder that contains the images, along with a txt file called K.txt
which contains the intrinsic matrix. If you are experimenting on a new dataset, use the same folder structure. The code stores the computed features and matches in respective pkl files inside the root directory to speed up repeated computations. The results are stored as ply files inside a points/
folder inside the root directory. For visualizing the point clouds inside the ply files, use suitable software such as MeshLab.
From the fountain-P11
image-set:
3, Reconstruction after 6 images
0003.jpg
is taken before 0004.jpg
, and the baseline views are 0000.jpg
and 0001.jpg
. The images are sorted based on their names before reconstruction. View selection and filtering is currently not implemented here