Debian Codegraph @

doc/cli.rst

raw
1 .. _cli:
2
3 Command-line Interface
4 ======================
5
6 The command-line interface provides access to all of COLMAP's functionality for
7 automated scripting. Each core functionality is implemented as a command to the
8 ``colmap`` executable. Run ``colmap -h`` to list the available commands (or
9 ``COLMAP.bat -h`` under Windows). Note that if you run COLMAP from the CMake
10 build folder, the executable is located at ``./src/colmap/exe/colmap``. To start the
11 graphical user interface, run ``colmap gui``.
12
13 Example
14 -------
15
16 Assuming you stored the images of your project in the following structure::
17
18 /path/to/project/...
19 +── images
20 │   +── image1.jpg
21 │   +── image2.jpg
22 │   +── ...
23 │   +── imageN.jpg
24
25 The command for the automatic reconstruction tool would be::
26
27 # The project folder must contain a folder "images" with all the images.
28 $ DATASET_PATH=/path/to/project
29
30 $ colmap automatic_reconstructor \
31 --workspace_path $DATASET_PATH \
32 --image_path $DATASET_PATH/images
33
34 Note that any command lists all available options using the ``-h,--help``
35 command-line argument. In case you need more control over the individual
36 parameters of the reconstruction process, you can execute the following sequence
37 of commands as an alternative to the automatic reconstruction command::
38
39 # The project folder must contain a folder "images" with all the images.
40 $ DATASET_PATH=/path/to/dataset
41
42 $ colmap feature_extractor \
43 --database_path $DATASET_PATH/database.db \
44 --image_path $DATASET_PATH/images
45
46 $ colmap exhaustive_matcher \
47 --database_path $DATASET_PATH/database.db
48
49 $ mkdir -p $DATASET_PATH/sparse
50
51 $ colmap mapper \
52 --database_path $DATASET_PATH/database.db \
53 --image_path $DATASET_PATH/images \
54 --output_path $DATASET_PATH/sparse
55
56 $ mkdir -p $DATASET_PATH/dense
57
58 $ colmap image_undistorter \
59 --image_path $DATASET_PATH/images \
60 --input_path $DATASET_PATH/sparse/0 \
61 --output_path $DATASET_PATH/dense \
62 --output_type COLMAP \
63 --max_image_size 2000
64
65 $ colmap patch_match_stereo \
66 --workspace_path $DATASET_PATH/dense \
67 --workspace_format COLMAP \
68 --PatchMatchStereo.geom_consistency true
69
70 $ colmap stereo_fusion \
71 --workspace_path $DATASET_PATH/dense \
72 --workspace_format COLMAP \
73 --input_type geometric \
74 --output_path $DATASET_PATH/dense/fused.ply
75
76 $ colmap poisson_mesher \
77 --input_path $DATASET_PATH/dense/fused.ply \
78 --output_path $DATASET_PATH/dense/meshed-poisson.ply
79
80 $ colmap delaunay_mesher \
81 --input_path $DATASET_PATH/dense \
82 --output_path $DATASET_PATH/dense/meshed-delaunay.ply
83
84 $ colmap advancing_front_mesher \
85 --input_path $DATASET_PATH/dense \
86 --output_path $DATASET_PATH/dense/meshed-advancing-front.ply
87
88 # Optionally simplify a dense mesh to reduce its size.
89 $ colmap mesh_simplifier \
90 --input_path $DATASET_PATH/dense/meshed-poisson.ply \
91 --output_path $DATASET_PATH/dense/meshed-poisson-simplified.ply \
92 --MeshSimplification.target_face_ratio 0.25
93
94 # Optionally texture a mesh using the undistorted images.
95 $ colmap mesh_texturer \
96 --workspace_path $DATASET_PATH/dense \
97 --input_path $DATASET_PATH/dense/meshed-poisson.ply \
98 --output_path $DATASET_PATH/dense/textured
99
100 Graceful shutdown and resuming
101 ------------------------------
102
103 The feature extraction and matching commands, ``mapper``,
104 ``pose_prior_mapper``, ``bundle_adjuster``, ``point_triangulator``,
105 ``image_registrator``, the image undistortion commands,
106 ``patch_match_stereo``, and ``stereo_fusion`` handle ``SIGINT`` and ``SIGTERM``
107 cooperatively. ``automatic_reconstructor`` supports graceful shutdown when
108 using the incremental mapper. The first signal stops work at a safe point and
109 writes any usable in-progress results. The process then exits with status 130
110 for ``SIGINT`` or 143 for ``SIGTERM``. A second signal terminates immediately
111 and may interrupt an output write.
112
113 Feature extraction and matching can be resumed by rerunning the same command
114 against the same database. PatchMatch can likewise be rerun against the same
115 workspace; complete depth and normal maps are skipped. An interrupted
116 incremental reconstruction is written to its normal numbered model directory
117 and can be continued with ``--input_path``::
118
119 $ colmap mapper \
120 --database_path $DATASET_PATH/database.db \
121 --image_path $DATASET_PATH/images \
122 --input_path $DATASET_PATH/sparse/0 \
123 --output_path $DATASET_PATH/sparse/0
124
125 Point triangulation, image registration, and bundle adjustment write their
126 usable partial results before exiting. Stereo fusion writes non-empty partial
127 results to a sibling path containing ``.partial`` so that an existing completed
128 result is not overwritten. Interrupted image undistortion can be restarted by
129 rerunning the same command. Ceres optimizations stop between iterations. The
130 Caspar bundle-adjustment backend can only stop after its current solver
131 invocation. The global mapper does not support graceful shutdown because its
132 intermediate reconstructions cannot currently be resumed.
133
134 The equivalent pycolmap functions automatically handle ``SIGINT`` (Ctrl-C) by
135 performing a graceful shutdown and raising ``KeyboardInterrupt``. For other
136 termination events, they accept an optional ``cancellation_token``. Explicit
137 cancellation finishes cleanup and then raises ``InterruptedError``. This allows
138 applications to connect cloud-preemption signals (like ``SIGTERM``) to the token
139 without pycolmap replacing the host application's signal handlers. Automatic
140 ``SIGINT`` handling requires calling the pycolmap function from Python's main
141 thread; use a cancellation token when calling it from another thread::
142
143 import signal
144 import pycolmap
145
146 token = pycolmap.CancellationToken()
147 signal.signal(signal.SIGTERM, lambda *_: token.cancel())
148 pycolmap.incremental_mapping(
149 database_path,
150 image_path,
151 output_path,
152 cancellation_token=token,
153 )
154
155 To use the global SfM pipeline instead of the incremental mapper, replace the
156 ``mapper`` step with ``global_mapper``. The global mapper depends on good focal
157 length priors, so if reliable intrinsics are not available (e.g., from EXIF or
158 lab calibration), you should run ``view_graph_calibrator`` first. This step is
159 optional but recommended to improve the quality of global SfM, as was always
160 the default in `GLOMAP <https://github.com/colmap/glomap>`_. Note that
161 ``view_graph_calibrator`` modifies camera intrinsics and two-view geometries
162 in the database in-place, so it is recommended to work on a copy of the
163 database::
164
165 $ colmap feature_extractor \
166 --database_path $DATASET_PATH/database.db \
167 --image_path $DATASET_PATH/images
168
169 $ colmap exhaustive_matcher \
170 --database_path $DATASET_PATH/database.db
171
172 # Optional but often needed: calibrate intrinsics from the view graph.
173 # This modifies the database in-place, so work on a copy.
174 $ cp $DATASET_PATH/database.db $DATASET_PATH/database_global.db
175 $ colmap view_graph_calibrator \
176 --database_path $DATASET_PATH/database_global.db
177
178 $ mkdir -p $DATASET_PATH/sparse
179
180 $ colmap global_mapper \
181 --database_path $DATASET_PATH/database_global.db \
182 --image_path $DATASET_PATH/images \
183 --output_path $DATASET_PATH/sparse
184
185 If you want to run COLMAP on a computer without an attached display (e.g.,
186 cluster or cloud service), COLMAP automatically switches to use CUDA if
187 supported by your system. If no CUDA enabled device is available, you can
188 manually select to use CPU-based feature extraction and matching by setting the
189 ``--FeatureExtraction.use_gpu 0`` and ``--FeatureMatching.use_gpu 0`` options.
190
191 Help
192 ----
193
194 The available commands can be listed using the command::
195
196 $ colmap help
197
198 Usage:
199 colmap [command] [options]
200
201 Documentation:
202 https://colmap.github.io/
203
204 Example usage:
205 colmap help [ -h, --help ]
206 colmap gui
207 colmap gui -h [ --help ]
208 colmap automatic_reconstructor -h [ --help ]
209 colmap automatic_reconstructor --image_path IMAGES --workspace_path WORKSPACE
210 colmap feature_extractor --image_path IMAGES --database_path DATABASE
211 colmap exhaustive_matcher --database_path DATABASE
212 colmap mapper --image_path IMAGES --database_path DATABASE --output_path MODEL
213 ...
214
215 Available commands:
216 help
217 gui
218 automatic_reconstructor
219 bundle_adjuster
220 color_extractor
221 database_cleaner
222 database_creator
223 database_merger
224 delaunay_mesher
225 exhaustive_matcher
226 feature_extractor
227 feature_importer
228 geometric_verifier
229 global_mapper
230 guided_geometric_verifier
231 hierarchical_mapper
232 image_deleter
233 image_filterer
234 image_rectifier
235 image_registrator
236 image_undistorter
237 image_undistorter_standalone
238 mapper
239 matches_importer
240 mesh_simplifier
241 mesh_texturer
242 model_aligner
243 model_analyzer
244 model_clusterer
245 model_comparer
246 model_converter
247 model_cropper
248 model_merger
249 model_orientation_aligner
250 model_splitter
251 model_transformer
252 patch_match_stereo
253 point_filtering
254 point_triangulator
255 pose_prior_mapper
256 poisson_mesher
257 project_generator
258 rig_configurator
259 rotation_averager
260 sequential_matcher
261 spatial_matcher
262 stereo_fusion
263 transitive_matcher
264 view_graph_calibrator
265 vocab_tree_builder
266 vocab_tree_matcher
267 vocab_tree_retriever
268
269 And each command has a ``-h,--help`` command-line argument to show the usage and
270 the available options, e.g.::
271
272 $ colmap feature_extractor -h
273
274 Options can either be specified via command-line or by defining
275 them in a .ini project file passed to ``--project_path``.
276
277 -h [ --help ]
278 --default_random_seed arg (=0)
279 --log_target arg (=stderr_and_file)
280 {stderr, stdout, file, stderr_and_file}
281 --log_path arg
282 --log_level arg (=0)
283 --log_severity arg (=0) 0:INFO, 1:WARNING, 2:ERROR, 3:FATAL
284 --log_color arg (=1)
285 --project_path arg
286 --database_path arg
287 --image_path arg
288 --camera_mode arg (=-1)
289 --image_list_path arg
290 --descriptor_normalization arg (=l1_root)
291 {'l1_root', 'l2'}
292 --ImageReader.mask_path arg
293 --ImageReader.camera_model arg (=SIMPLE_RADIAL)
294 --ImageReader.single_camera arg (=0)
295 --ImageReader.single_camera_per_folder arg (=0)
296 --ImageReader.single_camera_per_image arg (=0)
297 --ImageReader.existing_camera_id arg (=-1)
298 --ImageReader.camera_params arg
299 --ImageReader.default_focal_length_factor arg (=1.2)
300 --ImageReader.camera_mask_path arg
301 --FeatureExtraction.type arg (=SIFT)
302 --FeatureExtraction.max_image_size arg (=3200)
303 --FeatureExtraction.num_threads arg (=-1)
304 --FeatureExtraction.use_gpu arg (=1)
305 --FeatureExtraction.gpu_index arg (=-1)
306 --SiftExtraction.max_num_features arg (=8192)
307 --SiftExtraction.first_octave arg (=-1)
308 --SiftExtraction.num_octaves arg (=4)
309 --SiftExtraction.octave_resolution arg (=3)
310 --SiftExtraction.peak_threshold arg (=0.0066666666666666671)
311 --SiftExtraction.edge_threshold arg (=10)
312 --SiftExtraction.estimate_affine_shape arg (=0)
313 --SiftExtraction.max_num_orientations arg (=2)
314 --SiftExtraction.upright arg (=0)
315 --SiftExtraction.domain_size_pooling arg (=0)
316 --SiftExtraction.dsp_min_scale arg (=0.16666666666666666)
317 --SiftExtraction.dsp_max_scale arg (=3)
318 --SiftExtraction.dsp_num_scales arg (=10)
319
320
321 The available options can either be provided directly from the command-line or
322 through a ``.ini`` file provided to ``--project_path``.
323
324
325 Commands
326 --------
327
328 The following list briefly documents the functionality of each command, that is
329 available as ``colmap [command]``:
330
331 - ``gui``: The graphical user interface, see
332 :ref:`Graphical User Interface <gui>` for more information.
333
334 - ``automatic_reconstructor``: Automatically reconstruct sparse and dense model
335 for a set of input images. Key options include ``--quality`` (LOW, MEDIUM,
336 HIGH, EXTREME), ``--data_type`` (INDIVIDUAL, VIDEO, INTERNET) to tune settings
337 for different capture scenarios, ``--feature`` (SIFT, ALIKED, LOMA, LOMA128)
338 to select the feature extraction algorithm, ``--mapper`` (INCREMENTAL,
339 HIERARCHICAL, GLOBAL) to choose the SfM pipeline, and ``--mesher`` (POISSON,
340 DELAUNAY, ADVANCING_FRONT) to select the surface reconstruction method.
341
342 - ``project_generator``: Generate project files at different quality settings.
343
344 - ``feature_extractor``, ``feature_importer``: Perform feature extraction or
345 import features for a set of images.
346
347 - ``exhaustive_matcher``, ``vocab_tree_matcher``, ``sequential_matcher``,
348 ``spatial_matcher``, ``transitive_matcher``, ``matches_importer``:
349 Perform feature matching after performing feature extraction.
350
351 - ``geometric_verifier``: Run standalone geometric verification on existing
352 feature matches in the database. This estimates two-view geometries
353 (fundamental/essential matrices, homographies) for matched image pairs.
354
355 - ``guided_geometric_verifier``: Run geometric verification guided by an
356 existing sparse reconstruction. Uses the known relative camera poses to
357 improve match verification results.
358
359 - ``mapper``: Sparse 3D reconstruction / mapping of the dataset using SfM after
360 performing feature extraction and matching.
361
362 - ``global_mapper``: Sparse 3D reconstruction using the global SfM pipeline.
363 Unlike the incremental ``mapper``, the global approach solves for all camera
364 poses simultaneously using rotation averaging and global positioning. This
365 can be faster for large datasets but may be less robust to outliers.
366 The global mapper depends on reasonably good focal length priors to perform
367 well. Run ``view_graph_calibrator`` before ``global_mapper`` to calibrate
368 camera intrinsics and estimate relative poses from the view graph, or provide
369 camera calibrations manually.
370
371 - ``pose_prior_mapper``: Sparse 3D reconstruction / mapping using pose priors.
372
373 - ``hierarchical_mapper``: Sparse 3D reconstruction / mapping of the dataset
374 using hierarchical SfM after performing feature extraction and matching.
375 This parallelizes the reconstruction process by partitioning the scene into
376 overlapping submodels and then reconstructing each submodel independently.
377 Finally, the overlapping submodels are merged into a single reconstruction.
378 It is recommended to run a few rounds of point triangulation and bundle
379 adjustment after this step.
380
381 - ``image_undistorter``: Undistort images and/or export them for MVS or to
382 external dense reconstruction software, such as CMVS/PMVS.
383
384 - ``image_rectifier``: Stereo rectify cameras and undistort images for stereo
385 disparity estimation.
386
387 - ``image_filterer``: Filter images from a sparse reconstruction.
388
389 - ``image_deleter``: Delete specific images from a sparse reconstruction.
390
391 - ``patch_match_stereo``: Dense 3D reconstruction / mapping using MVS after
392 running the ``image_undistorter`` to initialize the workspace.
393
394 - ``stereo_fusion``: Fusion of ``patch_match_stereo`` results into to a colored
395 point cloud.
396
397 - ``poisson_mesher``: Meshing of the fused point cloud using Poisson
398 surface reconstruction.
399
400 - ``delaunay_mesher``: Meshing of the reconstructed sparse or dense point cloud
401 using a graph cut on the Delaunay triangulation and visibility voting.
402
403 - ``advancing_front_mesher``: Meshing of the fused point cloud using advancing
404 front surface reconstruction. Supports visibility-based filtering and
405 block-wise parallel processing for large-scale scenes. Requires CGAL.
406
407 - ``mesh_simplifier``: Simplify a triangle mesh (PLY format) using Quadric Error
408 Metric (QEM) decimation. This reduces the number of faces in a mesh while
409 preserving its overall shape and appearance. Key options include
410 ``--MeshSimplification.target_face_ratio`` to control the fraction of faces
411 to retain (default 0.1), ``--MeshSimplification.max_error`` to set a maximum
412 quadric error threshold (0 = disabled), and
413 ``--MeshSimplification.boundary_weight`` to control boundary edge preservation
414 (default 1000). Supports multi-threaded initialization via
415 ``--MeshSimplification.num_threads``.
416
417 - ``mesh_texturer``: Produce a texture atlas and UV coordinates for a triangle
418 mesh using calibrated multi-view images.
419
420 - ``image_registrator``: Register new images in the database against an existing
421 model, e.g., when extracting features and matching newly added images in a
422 database after running ``mapper``. Note that no bundle adjustment or
423 triangulation is performed.
424
425 - ``point_triangulator``: Triangulate all observations of registered images in
426 an existing model using the feature matches in a database.
427
428 - ``point_filtering``: Filter sparse points in model by enforcing criteria,
429 such as minimum track length, maximum reprojection error, etc.
430
431 - ``bundle_adjuster``: Run global bundle adjustment on a reconstructed scene,
432 e.g., when a refinement of the intrinsics is needed or
433 after running the ``image_registrator``. The solver backend is selected via
434 ``--BundleAdjustment.backend`` (``CERES`` or ``CASPAR``). Caspar [caspar]_ is
435 an experimental GPU-accelerated backend; see :doc:`faq` for details and
436 limitations.
437
438 - ``database_cleaner``: Clean specific or all database tables.
439
440 - ``database_creator``: Create an empty COLMAP SQLite database with the
441 necessary database schema information.
442
443 - ``database_merger``: Merge two databases into a new database. Note that the
444 cameras will not be merged and that the unique camera and image identifiers
445 might change during the merging process.
446
447 - ``model_analyzer``: Print statistics about reconstructions.
448
449 - ``model_clusterer``: Split a reconstruction into smaller
450 sub-model clusters. Useful for managing and processing large-scale
451 reconstructions.
452
453 - ``model_aligner``: Align/geo-register model to coordinate system of given
454 camera centers.
455
456 - ``model_orientation_aligner``: Align the coordinate axis of a model using a
457 Manhattan world assumption.
458
459 - ``model_comparer``: Compare statistics of two reconstructions.
460
461 - ``model_converter``: Convert the COLMAP export format to another format,
462 such as PLY or NVM.
463
464 - ``model_cropper``: Crop model to specific bounding box described in GPS or
465 model coordinate system.
466
467 - ``model_merger``: Attempt to merge two disconnected reconstructions,
468 if they have common registered images.
469
470 - ``model_splitter``: Divide model in rectangular sub-models specified from
471 file containing bounding box coordinates, or max extent of sub-model, or
472 number of subdivisions in each dimension.
473
474 - ``model_transformer``: Transform coordinate frame of a model.
475
476 - ``color_extractor``: Extract mean colors for all 3D points of a model.
477
478 - ``rig_configurator``: Configure rigs and frames after feature extraction.
479
480 - ``vocab_tree_builder``: Create a vocabulary tree from a database with
481 extracted images. This is an offline procedure and can be run once, while the
482 same vocabulary tree can be reused for other datasets. Note that, as a rule of
483 thumb, you should use at least 10-100 times more features than visual words.
484 Pre-trained trees can be downloaded from https://demuc.de/colmap/.
485 This is useful if you want to build a custom tree with a different trade-off
486 in terms of precision/recall vs. speed.
487
488 - ``vocab_tree_retriever``: Perform vocabulary tree based image retrieval.
489
490 - ``rotation_averager``: Run standalone rotation averaging on the view graph.
491 Estimates global camera rotations from pairwise relative rotations.
492
493 - ``view_graph_calibrator``: Calibrate camera intrinsics using the view graph.
494 Estimates focal lengths and other intrinsic parameters from pairwise
495 geometric relations. Should be run before ``global_mapper``, if no good
496 prior camera intrinsics are known, since the global mapper
497 depends on reasonably good focal length priors to perform well.
498
499
500 Visualization
501 -------------
502
503 If you want to quickly visualize the outputs of the sparse or dense
504 reconstruction pipelines, COLMAP offers you the following possibilities:
505
506 - The sparse point cloud obtained with the ``mapper`` can be visualized via the
507 COLMAP GUI by importing the model files: choose ``File > Import Model``
508 and select the folder containing the sparse model files (``cameras.txt``,
509 ``images.txt``, ``points3D.txt``, etc.).
510
511 - The dense point cloud obtained with the ``stereo_fusion`` can be visualized
512 via the COLMAP GUI by importing ``fused.ply``: choose
513 ``File > Import Model from...`` and then select the file ``fused.ply``.
514
515 - The dense mesh model ``meshed-*.ply`` obtained with the ``poisson_mesher`` or
516 the ``delaunay_mesher`` can currently not be visualized with COLMAP, instead
517 you can use an external viewer, such as Meshlab. Use the ``mesh_simplifier``
518 command to reduce the mesh size for faster visualization or downstream
519 processing. Use the ``mesh_texturer`` command to produce a textured mesh
520 with a texture atlas that can be visualized in Meshlab or other 3D viewers.