Photogrammetry is the process of creating 3D models from 2D images. By taking multiple photographs from different angles, we can reconstruct the 3D geometry of an object or scene. This method extracts 3D information from photographs by determining their spatial relationships. Photogrammetry is widely used in various fields, such as architecture, archaeology, surveying, gaming, and real estate.
In this tutorial, you will learn to set up a photogrammetry pipeline using COLMAP, a photogrammetry tool, on an Ubuntu 24.04 GPU Droplet. You will process the famous South Building dataset to generate a 3D model using Structure from Motion (SfM) and dense reconstruction, and finally view the model using an 3D viewer.
GPU Droplet speeds up photogrammetry by quickly handling tasks like dense reconstruction and stereo fusion. This makes the process more efficient and reduces the time it takes to complete.
To follow this tutorial, you will need:
1.Create a New Project - You will need to create a new project from the cloud control panel and tie it to a GPU Droplet.
2.Create a GPU Droplet - Log into your DigitalOcean account, create a new GPU Droplet, and choose Ubuntu 24.04 as the OS. You can refer to our official documentation on how to create a GPU Droplet.
3.Add an SSH Key for authentication - An SSH key is required to authenticate with the GPU Droplet and by adding the SSH key, you can login to the GPU Droplet from your terminal.
4.Finalize and Create the GPU Droplet - Once all of the above steps are completed, finalize and create a new GPU Droplet.
In this step, login to your GPU Droplet either from the web console or from your terminal via SSH.
First, let’s update the package repository and install prerequisites:
Now, add the NVIDIA package repository:
Next, let’s install the NVIDIA drivers:
Now, let’s install the CUDA toolkit:
You will need to reboot the GPU Droplet, after the installation of NVIDIA drivers and the CUDA toolkit:
Once the system is rebooted, you can verify the installation of the NVIDIA driver and CUDA version with:
This command should display the details of your NVIDIA GPU and the driver version.
Verify the installation of CUDA:
You should see information about the installed version of CUDA.
Note: From the above outputs, please make sure that the CUDA version from the output of the command nvidia-smi
and the command nvcc -v
matches.
COLMAP is a general-purpose Structure-from-Motion (SfM) and Multi-View Stereo (MVS) pipeline with a graphical and command-line interface. It offers a wide range of features for reconstruction of ordered and unordered image collections.
By default, COLMAP runs one feature extraction/matching thread per CUDA-enabled GPU and this usually gives the best performance as compared to running multiple threads on the same GPU.
First, install the dependencies for COLMAP:
Now, let’s clone the COLMAP repository from GitHub to configure and compile COLMAP:
Verify that COLMAP is installed by running:
You should see the COLMAP help information.
You will use the South Building dataset from the COLMAP datasets page.
Let’s create a directory for the dataset:
Now, download the South Building dataset (0.42GB):
Note: This dataset already has some necessary files present which are generated during the Photogrammetry process as you will perform below. You can remove them proactively to avoid any issues during the below steps:
This will extract the images inside the directory /root/datasets/south-building
.
You can now start processing the images using COLMAP’s command line executables and functions. The COLMAP pipeline consists of several key steps. In this step you learn each of these steps and what they do.
First and foremost let’s set the path to the image dataset as an environment variable as you will need this in the following steps:
Verify the value of the DATASET_PATH
variable:
The first step in the COLMAP pipeline is feature extraction. During this step, COLMAP detects keypoints in each image using the SIFT (Scale-Invariant Feature Transform) algorithm.
Use the following command:
This step detects keypoints in each image and stores them in the features.db
file, which this command will automatically generate after completion of the process.
In the above command:
--database_path
: Specifies where the features and matches will be stored (a SQLite database).--image_path
: The path to the folder containing the South Building dataset images.You should observe the following output:
The next step is to match the features of the images.
In this step you will perform image matching, where COLMAP matches features between pairs of images.
In the above command:
--database_path
: is the path to the database created during the previous feature extraction step. This database contains the features extracted from each image.The exhaustive matcher compares each image with every other image to find matching points between them, which is crucial for the 3D reconstruction process.
You should observe the following output:
Once the image matching is complete, you will perform Structure from Motion (SfM) to generate a sparse 3D point cloud. This step computes the camera poses and reconstructs a sparse point cloud based on the matched features.
Structure from motion (SfM) is the process of estimating the 3-D structure of a scene from a set of 2-D images. SfM is used in many applications, such as 3-D scanning, augmented reality, and visual simultaneous localization and mapping (vSLAM).
In the above command:
--database_path
: Path to the database containing the feature matches.--image_path
: Path to the dataset images.--output_path
: Directory where the sparse 3D reconstruction will be saved.This step generates a sparse point cloud and stores it in the sparse/
directory. It also outputs the estimated camera poses and scene structure.
You should observe the following output:
Before proceeding to dense reconstruction, the images must be undistorted to remove any camera lens distortions.
This step prepares the images for dense reconstruction by undistorting them and saving them inside the dense/
directory.
In the above command:
--image_path
: Path to the original images.--input_path
: Path to the sparse reconstruction output.--output_path
: Directory where the undistorted images will be stored.--output_type COLMAP
: Specifies that the output format should be compatible with COLMAP.--max_image_size 2000
: This option sets the maximum size (in pixels) for the largest dimension (either width or height) of the images during the undistortion process.You should observe the following output:
Next, we perform dense reconstruction, which generates a dense 3D point cloud from the images.
The below command computes a dense point cloud using the PatchMatch Stereo algorithm.
You should observe the following output:
Note: This step will take some time to complete, as computing a dense point cloud of every 128 images is computationally intensive.
In the above command:
--workspace_path
: Path to the undistorted images and sparse reconstruction.--workspace_format COLMAP
: Specifies the workspace format for dense reconstruction.--PatchMatchStereo.geom_consistency true
: It enables geometric consistency checking during the dense reconstruction process. It enforces multi-view consistency by verifying that the computed depth maps are consistent when viewed from different perspectives.Finally, you will generate a 3D mesh from the dense point cloud using stereo fusion.
You should observe the following output:
In the above command:
--workspace_path
: Path to the dense reconstruction results.--workspace_format COLMAP
: Specifies the format of the workspace.--output_path
: Path to save the final .ply
file containing the fused 3D mesh.The final 3D model will be saved as fused.ply
in the /root/datasets/south-building/dense
directory.
Once the process is complete, you can visualize the 3D model using a 3D viewer such as MeshLab or CloudCompare. You can download the fused.ply
file to your local machine using scp
:
Open the .ply
file in MeshLab or CloudCompare to view the 3D model.
In this tutorial, you learned how to use COLMAP to create a photogrammetry pipeline for the South Building dataset. This includes feature extraction, image matching, sparse and dense reconstruction, and mesh generation using COLMAP’s CLI.
Running the photogrammetry pipeline on a GPU Droplet accelerates tasks like dense reconstruction and stereo fusion, reducing processing time and improving efficiency. This is valuable for industries such as architecture, archaeology, gaming, surveying, and real estate, as it allows for quick and accurate 3D model creation from 2D images.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!