Executes the complete photogrammetric Structure-from-Motion (SfM) pipeline using COLMAP:
Feature extraction with SIFT, ALIKED, or LOMA (
feature_extractor).Geometric two-view feature matching (
exhaustive_matcher,sequential_matcher, orspatial_matcher).Sparse 3D reconstruction and camera orientation (
mapper).Automated model export to plain text format and PLY sparse point cloud (
model_converter).Optional dense Multi-View Stereo (MVS) depth estimation and fusion (
patch_match_stereo,stereo_fusion).
Automatically detects and adapts CLI arguments between COLMAP 4.x (v4.2.1+) and COLMAP 3.x.
Usage
colmap_sfm(
images,
output_dir = NULL,
camera_model = c("OPENCV", "SIMPLE_RADIAL", "RADIAL", "PINHOLE", "SIMPLE_PINHOLE",
"OPENCV_FISHEYE", "FULL_OPENCV"),
single_camera = TRUE,
camera_params = NULL,
matching = c("exhaustive", "sequential", "spatial"),
feature_type = c("SIFT", "ALIKED", "LOMA"),
max_num_features = 8192,
max_image_size = -1,
sequential_overlap = 10,
sequential_quadratic = TRUE,
loop_detection = FALSE,
vocab_tree_path = NULL,
guided_matching = FALSE,
min_num_matches = 15,
multiple_models = TRUE,
extract_colors = TRUE,
ba_refine_focal_length = TRUE,
ba_refine_principal_point = FALSE,
ba_refine_extra_params = TRUE,
dense = FALSE,
dense_geom_consistency = TRUE,
dense_max_image_size = -1,
use_gpu = TRUE,
gpu_index = "-1",
num_threads = -1,
custom_args = NULL,
overwrite = FALSE,
show_colmap_output = FALSE,
colmap_path = NULL,
verbose = TRUE
)Arguments
- images
Path to directory containing photos or a character vector of image file paths.
- output_dir
Target workspace directory for the database and reconstructions. If
NULL, acolmap_workspacefolder will be created inside the image directory.- camera_model
Geometric camera projection model. Defaults to
"OPENCV". Other options:"SIMPLE_RADIAL","RADIAL","PINHOLE","SIMPLE_PINHOLE","OPENCV_FISHEYE","FULL_OPENCV".- single_camera
Logical. If
TRUE(default), assumes all images were captured by the same device/camera, sharing intrinsic calibration parameters.- camera_params
Optional character string specifying known prior intrinsic calibration parameters (e.g.,
"fx,fy,cx,cy"). Defaults toNULL.- matching
Feature matching mode:
"exhaustive"(default, matches all image pairs),"sequential"(recommended for continuous ordered video frames or sequential drone flights), or"spatial"(matches images based on GPS/spatial coordinates).- feature_type
Visual feature extractor type. One of
"SIFT"(default),"ALIKED", or"LOMA". (ALIKED and LOMA are supported in COLMAP 4.x+).- max_num_features
Integer. Maximum number of visual features extracted per image. Defaults to
8192.- max_image_size
Integer. Maximum image dimension (in pixels) during feature extraction.
-1(default) preserves original image resolution.- sequential_overlap
Integer. Number of consecutive images to match in
"sequential"matching mode. Defaults to10.- sequential_quadratic
Logical. If
TRUE(default), uses quadratic overlap for sequential matching, improving long trajectory tracking.- loop_detection
Logical. If
TRUE, attempts visual loop closure detection in sequential matching. Defaults toFALSE.- vocab_tree_path
Optional path to a COLMAP vocabulary tree file for visual loop detection. Defaults to
NULL.- guided_matching
Logical. If
TRUE, uses geometric guided matching to recover additional weak feature correspondences. Defaults toFALSE.- min_num_matches
Integer. Minimum number of mutual feature matches required to verify an image pair. Defaults to
15.- multiple_models
Logical. If
TRUE(default), allows reconstructing multiple sub-models if the scene is disconnected, automatically selecting the primary model with the largest point cloud.- extract_colors
Logical. If
TRUE(default), extracts true RGB colors from images for each 3D tie point.- ba_refine_focal_length
Logical. Refine camera focal length during bundle adjustment. Defaults to
TRUE.- ba_refine_principal_point
Logical. Refine principal point during bundle adjustment. Defaults to
FALSE.- ba_refine_extra_params
Logical. Refine distortion parameters during bundle adjustment. Defaults to
TRUE.- dense
Logical. If
TRUE, executes dense Multi-View Stereo (MVS) reconstruction viaimage_undistorter,patch_match_stereo(using GPU CUDA), andstereo_fusion, generating a dense point cloud (fused.ply). Defaults toFALSE(fast sparse SfM).- dense_geom_consistency
Logical. Enforces multi-view geometric consistency during dense stereo. Defaults to
TRUE.- dense_max_image_size
Integer. Maximum image size for dense depth estimation. Defaults to
-1.- use_gpu
Logical. If
TRUE(default), enables GPU CUDA acceleration when available.- gpu_index
Character or integer. GPU device index. Defaults to
"-1"(automatic selection).- num_threads
Integer. Number of CPU threads to use. Defaults to
-1(all available cores).- custom_args
Optional character vector of extra custom CLI flags to pass to COLMAP commands.
- overwrite
Logical. If
TRUE, removes any existing database or previous reconstructions inoutput_dirto start fresh. Defaults toFALSE.- show_colmap_output
Logical. If
FALSE(default), suppresses raw COLMAP C++ terminal output, logging it cleanly tocolmap.loginoutput_dirwhile displaying clean high-levelclimessages. IfTRUE, streams raw COLMAP terminal output directly to the console.- colmap_path
Optional path to the COLMAP executable. If
NULL, automatically resolved viafind_colmap()orinstall_colmap().- verbose
Logical. If
TRUE(default), displays step-by-step progress messages.
Value
An object of class colmap_sfm (named list) containing paths to generated assets (database,
sparse_dir, recon_dir, cameras_txt, images_txt, points3d_ply, points3d_txt,
dense_dir, fused_ply) and reconstruction metrics (n_cameras, n_points).
Examples
if (FALSE) { # interactive()
library(pliman)
# Fast sparse reconstruction with SIFT & OpenCV camera model
sfm_res <- colmap_sfm("my_photos/", camera_model = "OPENCV")
print(sfm_res)
# Sequential video frame reconstruction
sfm_seq <- colmap_sfm("frames/", matching = "sequential", sequential_overlap = 15)
# Full dense point cloud (PatchMatch MVS with GPU CUDA)
dense_res <- colmap_sfm("my_photos/", camera_model = "OPENCV", dense = TRUE)
}
