Debian Codegraph @

doc/faq.rst

raw
1 Frequently Asked Questions
2 ==========================
3
4 Adjusting the options for different reconstruction scenarios and output quality
5 -------------------------------------------------------------------------------
6
7 COLMAP provides many options that can be tuned for different reconstruction
8 scenarios and to trade off accuracy and completeness versus efficiency. The
9 default options are set for medium to high quality reconstruction of
10 unstructured input data. There are several presets for different scenarios and
11 quality levels, which can be set in the GUI as ``Extras > Set options for ...``.
12 To use these presets from the command-line, you can save the current set of
13 options as ``File > Save project`` after choosing the presets. The resulting
14 project file can be opened with a text editor to view the different options.
15 Alternatively, you can generate the project file also from the command-line
16 by running ``colmap project_generator``.
17
18
19 Extending COLMAP
20 ----------------
21
22 If you need to simply analyze the produced sparse or dense reconstructions from
23 COLMAP, you can load the sparse models using pycolmap in Python or the
24 scripts in ``scripts/matlab`` for Matlab.
25
26 If you want to write a C/C++ executable that builds on top of COLMAP, there are
27 two possible approaches. First, the COLMAP headers and library are installed
28 to the ``CMAKE_INSTALL_PREFIX`` by default. Compiling against COLMAP as a
29 library is described :ref:`here <installation-library>`. Alternatively, you can
30 start from the ``src/colmap/tools/example.cc`` code template and implement the desired
31 functionality directly as a new binary within COLMAP.
32
33
34 Choosing between SIFT, ALIKED, and LoMa features
35 ------------------------------------------------
36
37 COLMAP supports three feature extraction algorithms: SIFT (default), ALIKED,
38 and LoMa (the latter two require ONNX support). Here are some guidelines for
39 choosing between them:
40
41 - **SIFT** is the most widely tested and robust choice. It works well for
42 scenarios with moderate to high view overlap, sufficient scene texture,
43 and captured under similar illumination conditions. It supports both GPU
44 and CPU extraction.
45
46 - **ALIKED** is a learned feature extractor that can produce more repeatable
47 features in some cases, particularly for scenes with limited view overlap,
48 little scene texture, and drastic illumination changes. It requires ONNX
49 Runtime at build time (``-DONNX_ENABLED=ON``).
50
51 - **LoMa** is a learned feature extractor targeting the same difficult
52 scenarios as ALIKED, paired with dedicated matchers that trade inference
53 cost for matching quality. It also requires ONNX Runtime at build time.
54
55 SIFT and ALIKED support brute-force matching as well as LightGlue neural
56 network-based matching. LightGlue typically produces higher inlier ratios,
57 especially for image pairs with large viewpoint or illumination changes, but
58 requires ONNX support. LoMa descriptors are matched either brute-force or with
59 one of the dedicated LoMa matchers. See
60 :ref:`Feature Extraction and Matching <features>` for details on available
61 options.
62
63 Do not mix different feature types (e.g., SIFT and ALIKED) in the same
64 database, as the descriptors are incompatible.
65
66
67 .. _faq-choosing-camera-model:
68
69 Choosing the right camera model
70 -------------------------------
71
72 COLMAP supports many camera models with varying numbers of parameters (see
73 :doc:`cameras` for the full list). Choosing the right model depends on your
74 lens type and reconstruction requirements:
75
76 - **SIMPLE_RADIAL** (default): A good starting point for most standard cameras.
77 Models a single focal length, principal point, and one radial distortion
78 parameter.
79
80 - **PINHOLE**: Use if your images have negligible lens distortion (e.g.,
81 already undistorted images or high-quality industrial lenses).
82
83 - **OPENCV**: A good choice for wider-angle lenses with moderate distortion.
84 Models 2 focal lengths, principal point, and 4 distortion parameters (2 radial
85 + 2 tangential).
86
87 - **SIMPLE_RADIAL_FISHEYE** or **OPENCV_FISHEYE**: Use for fisheye lenses with
88 a field of view significantly larger than 120 degrees.
89
90 - **FULL_OPENCV**: Use only when you have many images sharing intrinsics
91 and need to model complex distortion patterns. With 12 parameters, this model
92 requires a large number of observations to converge reliably.
93
94 As a rule of thumb, use the simplest model that adequately describes your lens.
95 Overly complex models with many parameters can lead to degenerate or overfitted
96 calibration, especially when few images share intrinsics. If in doubt, start
97 with ``SIMPLE_RADIAL`` and inspect the reprojection errors in the model
98 statistics.
99
100
101 Using calibration from OpenCV, Kalibr, or other tools
102 -----------------------------------------------------
103
104 If you already calibrated your camera with an external tool such as OpenCV or
105 Kalibr, you can reuse those intrinsics in COLMAP (see :ref:`Fix intrinsics
106 <faq-fix-intrinsics>` to keep them constant during reconstruction). Two
107 conventions have to be matched first.
108
109 **Pixel coordinate convention.** COLMAP places the origin at the top-left
110 *corner* of the image, so the center of the top-left pixel is at ``(0.5, 0.5)``
111 and a centered principal point is ``(width / 2, height / 2)``. OpenCV and Kalibr
112 place integer coordinates at pixel *centers*, so their centered principal point
113 is ``((width - 1) / 2, (height - 1) / 2)``. To convert a principal point from
114 OpenCV/Kalibr to COLMAP, add ``0.5`` to both ``cx`` and ``cy``::
115
116 cx_colmap = cx_opencv + 0.5
117 cy_colmap = cy_opencv + 0.5
118
119 For example, an OpenCV calibration of an 800×600 image with a centered principal
120 point ``(399.5, 299.5)`` becomes ``(400.0, 300.0)`` in COLMAP. The focal lengths
121 ``fx``, ``fy`` and the distortion coefficients are unaffected by this shift.
122
123 **Distortion parameter order.** COLMAP's ``OPENCV`` model uses the same
124 ``k1, k2, p1, p2`` distortion parameters as OpenCV, and ``FULL_OPENCV``
125 additionally uses ``k3, k4, k5, k6``, in that order (see :doc:`cameras`). A
126 camera line in ``cameras.txt`` for the example above is therefore::
127
128 1 OPENCV 800 600 fx fy 400.0 300.0 k1 k2 p1 p2
129
130
131 Choosing between incremental, global, and hierarchical SfM
132 ----------------------------------------------------------
133
134 COLMAP offers three SfM pipelines:
135
136 - **Incremental mapper** (``mapper``, default): Reconstructs the scene by
137 incrementally adding one image at a time. This is the most robust and
138 well-tested pipeline, but can become slow for large image collections, where
139 repeated bundle adjustment is often the bottleneck. This can be accelerated
140 substantially with the GPU-based Caspar backend (see
141 :ref:`Speedup bundle adjustment <speedup-bundle-adjustment>`).
142
143 - **Global mapper** (``global_mapper``): Solves for all camera poses
144 simultaneously using rotation averaging and global positioning. This can be
145 faster for large datasets with good matching graphs, but may be less robust
146 to outliers in the matching. The global mapper depends on good focal length
147 priors. If reliable intrinsics are not available, run
148 ``view_graph_calibrator`` before ``global_mapper`` to estimate them from the
149 view graph (optional but recommended to improve the quality of
150 global SfM). Note that ``view_graph_calibrator`` modifies the database
151 in-place, so it is recommended to work on a copy.
152
153 - **Hierarchical mapper** (``hierarchical_mapper``): Partitions the scene into
154 overlapping sub-models and reconstructs each independently, then merges them.
155 This is useful for very large-scale datasets where the incremental approach
156 becomes too slow but is usually less robust than the other two pipelines.
157
158 All three can also be selected via the ``automatic_reconstructor`` using
159 ``--mapper INCREMENTAL``, ``--mapper GLOBAL``, or ``--mapper HIERARCHICAL``.
160
161
162 Reconstruction with pose priors (GPS)
163 -------------------------------------
164
165 If your images have GPS information in their EXIF metadata, COLMAP
166 automatically extracts and stores it as pose priors in the database during
167 feature extraction. These priors can then be used during reconstruction with
168 the ``pose_prior_mapper``::
169
170 colmap feature_extractor \
171 --database_path $PROJECT_PATH/database.db \
172 --image_path $PROJECT_PATH/images
173
174 colmap exhaustive_matcher \
175 --database_path $PROJECT_PATH/database.db
176
177 colmap pose_prior_mapper \
178 --database_path $PROJECT_PATH/database.db \
179 --image_path $PROJECT_PATH/images \
180 --output_path $PROJECT_PATH/sparse
181
182 The ``pose_prior_mapper`` is essentially the incremental mapper with prior
183 position constraints enabled. You can override the priors covariance (uncertainty)
184 using ``--overwrite_priors_covariance``. The new covariance will be built based
185 on the values of ``--prior_position_std_x``, ``--prior_position_std_y``, and
186 ``--prior_position_std_z`` (default: 1.0 meter each).
187
188 For geo-registration of an already reconstructed model (without using priors
189 during mapping), see the `Geo-registration`_ section.
190
191
192 .. _faq-share-intrinsics:
193
194 Share intrinsics
195 ----------------
196
197 COLMAP supports shared intrinsics for arbitrary groups of images and camera
198 models. Images share the same intrinsics, if they refer to the same camera, as
199 specified by the ``camera_id`` property in the database. You can add new cameras
200 and set shared intrinsics in the database management tool. Please, refer to
201 :ref:`Database Management <database-management>` for more information.
202
203
204 Set known camera intrinsics
205 ---------------------------
206
207 If the camera calibration is known a priori, the recommended way to provide it
208 is during feature extraction using the ``ImageReader`` options::
209
210 colmap feature_extractor \
211 --database_path $PROJECT_PATH/database.db \
212 --image_path $PROJECT_PATH/images \
213 --ImageReader.single_camera 1 \
214 --ImageReader.camera_model OPENCV \
215 --ImageReader.camera_params "fx,fy,cx,cy,k1,k2,p1,p2"
216
217 The parameters must be provided as a comma-separated list in the order defined
218 by the chosen camera model (see :doc:`cameras`). In the GUI, the equivalent
219 settings can be found under ``Processing > Feature extraction > Custom
220 parameters``. Use ``--ImageReader.single_camera 1`` if all images were captured
221 by the same physical camera with identical settings, so that they share one
222 camera in the database (see `Share intrinsics`_).
223
224 To modify the intrinsics of an existing database, do not edit the SQLite tables
225 by hand (the parameters are stored as binary blobs of doubles), but use
226 pycolmap's database API instead::
227
228 import pycolmap
229 with pycolmap.Database.open("path/to/database.db") as db:
230 camera = db.read_camera(1)
231 camera.params = [fx, fy, cx, cy, k1, k2, p1, p2]
232 camera.has_prior_focal_length = True
233 db.update_camera(camera)
234
235 Note that the provided parameters are still refined during bundle adjustment by
236 default. To keep them fixed during the reconstruction, see
237 :ref:`Fix intrinsics <faq-fix-intrinsics>`.
238
239
240 .. _faq-fix-intrinsics:
241
242 Fix intrinsics
243 --------------
244
245 By default, COLMAP tries to refine the intrinsic camera parameters (except
246 principal point) automatically during the reconstruction. Usually, if there are
247 enough images in the dataset and you share the intrinsics between multiple
248 images, the estimated intrinsic camera parameters in SfM should be better than
249 parameters manually obtained with a calibration pattern.
250
251 However, sometimes COLMAP's self-calibration routine might converge in
252 degenerate parameters, especially in case of the more complex camera models with
253 many distortion parameters. If you know the calibration parameters a priori, you
254 can fix different parameter groups during the reconstruction. Choose
255 ``Reconstruction > Reconstruction options > Bundle Adj. > refine_*`` and check
256 which parameter group to refine or to keep constant. Even if you keep the
257 parameters constant during the reconstruction, you can refine the parameters in
258 a final global bundle adjustment by setting ``Reconstruction > Bundle adj.
259 options > refine_*`` and then running ``Reconstruction > Bundle adjustment``.
260
261
262 Principal point refinement
263 --------------------------
264
265 By default, COLMAP keeps the principal point constant during the reconstruction,
266 as principal point estimation is an ill-posed problem in general. Once all
267 images are reconstructed, the problem is most often constrained enough that you
268 can try to refine the principal point in global bundle adjustment, especially
269 when sharing intrinsic parameters between multiple images. Please, refer to
270 :ref:`Fix intrinsics <faq-fix-intrinsics>` for more information.
271
272
273 Increase number of matches / sparse 3D points
274 ---------------------------------------------
275
276 To increase the number of matches, you should use the more discriminative
277 DSP-SIFT features instead of plain SIFT and also estimate the affine feature
278 shape using the options: ``--SiftExtraction.estimate_affine_shape=true`` and
279 ``--SiftExtraction.domain_size_pooling=true``. In addition, you should enable
280 guided feature matching using: ``--FeatureMatching.guided_matching=true``.
281
282 By default, COLMAP ignores two-view feature tracks in triangulation, resulting
283 in fewer 3D points than possible. Triangulation of two-view tracks can in rare
284 cases improve the stability of sparse image collections by providing additional
285 constraints in bundle adjustment. To also triangulate two-view tracks, unselect
286 the option ``Reconstruction > Reconstruction options > Triangulation >
287 ignore_two_view_tracks``. If your images are taken from far distance with
288 respect to the scene, you can try to reduce the minimum triangulation angle.
289
290
291 Reconstruct sparse/dense model from known camera poses
292 ------------------------------------------------------
293
294 If the camera poses are known and you want to reconstruct a sparse or dense
295 model of the scene, you must first manually construct a sparse model by creating
296 a ``cameras.txt``, ``points3D.txt``, and ``images.txt`` under a new folder::
297
298 +── path/to/manually/created/sparse/model
299 │   +── cameras.txt
300 │   +── images.txt
301 │   +── points3D.txt
302
303 The ``points3D.txt`` file should be empty while every other line in the ``images.txt``
304 should also be empty, since the sparse features are computed, as described below. You can
305 refer to :ref:`this article <output-format>` for more information about the structure of
306 a sparse model.
307
308 Example of images.txt::
309
310 1 0.695104 0.718385 -0.024566 0.012285 -0.046895 0.005253 -0.199664 1 image0001.png
311 # Make sure every other line is left empty
312 2 0.696445 0.717090 -0.023185 0.014441 -0.041213 0.001928 -0.134851 2 image0002.png
313
314 3 0.697457 0.715925 -0.025383 0.018967 -0.054056 0.008579 -0.378221 1 image0003.png
315
316 4 0.698777 0.714625 -0.023996 0.021129 -0.048184 0.004529 -0.313427 2 image0004.png
317
318 Each image above must have the same ``image_id`` (first column) as in the database (next step).
319 This database can be inspected either in the GUI (under ``Database management > Processing``),
320 or, one can create a reconstruction with colmap and later export it as text in order to see
321 the images.txt file it creates.
322
323 To reconstruct a sparse map, you first have to recompute features from the
324 images of the known camera poses as follows::
325
326 colmap feature_extractor \
327 --database_path $PROJECT_PATH/database.db \
328 --image_path $PROJECT_PATH/images
329
330 If your known camera intrinsics have large distortion coefficients, you should
331 now manually copy the parameters from your ``cameras.txt`` to the database, such
332 that the matcher can leverage the intrinsics. Modifying the database is possible
333 in many ways, but an easy option is to use pycolmap's database API.
334 Otherwise, you can skip this step and
335 simply continue as follows::
336
337 colmap exhaustive_matcher \ # or alternatively any other matcher
338 --database_path $PROJECT_PATH/database.db
339
340 colmap point_triangulator \
341 --database_path $PROJECT_PATH/database.db \
342 --image_path $PROJECT_PATH/images
343 --input_path path/to/manually/created/sparse/model \
344 --output_path path/to/triangulated/sparse/model
345
346 Note that the sparse reconstruction step is not necessary in order to compute
347 a dense model from known camera poses. Assuming you computed a sparse model
348 from the known camera poses, you can compute a dense model as follows::
349
350 colmap image_undistorter \
351 --image_path $PROJECT_PATH/images \
352 --input_path path/to/triangulated/sparse/model \
353 --output_path path/to/dense/workspace
354
355 colmap patch_match_stereo \
356 --workspace_path path/to/dense/workspace
357
358 colmap stereo_fusion \
359 --workspace_path path/to/dense/workspace \
360 --output_path path/to/dense/workspace/fused.ply
361
362 Alternatively, you can also produce a dense model without a sparse model as::
363
364 colmap image_undistorter \
365 --image_path $PROJECT_PATH/images \
366 --input_path path/to/manually/created/sparse/model \
367 --output_path path/to/dense/workspace
368
369 Since the sparse point cloud is used to automatically select neighboring images
370 during the dense stereo stage, you have to manually specify the source images,
371 as described :ref:`here <faq-dense-manual-source>`. The dense stereo stage
372 now also requires a manual specification of the depth range.
373
374 Finally, in this case, fusion will fail to successfully match points if min_num_pixels is
375 left at the default (greater than 1). So also set that parameter, as below::
376
377 colmap patch_match_stereo \
378 --workspace_path path/to/dense/workspace \
379 --PatchMatchStereo.depth_min $MIN_DEPTH \
380 --PatchMatchStereo.depth_max $MAX_DEPTH
381
382 colmap stereo_fusion \
383 --workspace_path path/to/dense/workspace \
384 --StereoFusion.min_num_pixels 1 \
385 --output_path path/to/dense/workspace/fused.ply
386
387
388 .. _faq-merge-models:
389
390 Merge disconnected models
391 -------------------------
392
393 Sometimes COLMAP fails to reconstruct all images into the same model and hence
394 produces multiple sub-models. If those sub-models have common registered images,
395 they can be merged into a single model as post-processing step::
396
397 colmap model_merger \
398 --input_path1 /path/to/sub-model1 \
399 --input_path2 /path/to/sub-model2 \
400 --output_path /path/to/merged-model
401
402 To improve the quality of the alignment between the two sub-models, it is
403 recommended to run another global bundle adjustment after the merge::
404
405 colmap bundle_adjuster \
406 --input_path /path/to/merged-model \
407 --output_path /path/to/refined-merged-model
408
409
410 Geo-registration
411 ----------------
412
413 Geo-registration of models is possible by providing the 3D locations for the
414 camera centers of a subset or all registered images. The 3D similarity
415 transformation between the reconstructed model and the target coordinate frame
416 of the geo-registration is determined from these correspondences.
417
418 The geo-registered 3D coordinates can either be extracted from the database
419 (tvec_prior field) or from a user specified text file.
420 For text-files, the geo-registered 3D coordinates of the camera centers for
421 images must be specified with the following format::
422
423 image_name1.jpg X1 Y1 Z1
424 image_name2.jpg X2 Y2 Z2
425 image_name3.jpg X3 Y3 Z3
426 ...
427
428 The coordinates can be either GPS-based (lat/lon/alt) or cartesian-based (x/y/z).
429 In case of GPS coordinates, a conversion will be performed to turn those into
430 cartesian coordinates. The conversion can be done from GPS to ECEF
431 (Earth-Centered-Earth-Fixed) or to ENU (East-North-Up) coordinates. If ENU coordinates
432 are used, the first image GPS coordinates will define the origin of the ENU frame.
433 It is also possible to use ECEF coordinates for alignment and then rotate the aligned
434 reconstruction into the ENU plane.
435
436 Note that at least 3 images must be specified to estimate a 3D similarity
437 transformation. Then, the model can be geo-registered using::
438
439 colmap model_aligner \
440 --input_path /path/to/model \
441 --output_path /path/to/geo-registered-model \
442 --ref_images_path /path/to/text-file (or --database_path /path/to/database.db) \
443 --ref_is_gps 1 \
444 --alignment_type ecef \
445 --alignment_max_error 3.0 (where 3.0 is the error threshold to be used in RANSAC)
446
447 A 3D similarity transformation will be estimated with a RANSAC estimator to be robust to potential outliers
448 in the data. It is required to provide the error threshold to be used in the RANSAC estimator.
449
450 Manhattan world alignment
451 -------------------------
452
453 COLMAP has functionality to align the coordinate axes of a reconstruction using
454 a Manhattan world assumption, i.e. COLMAP can automatically determine the
455 gravity axis and the major horizontal axis of the Manhattan world through
456 vanishing point detection in the images. Please, refer to the
457 ``model_orientation_aligner`` for more details.
458
459
460 Mask image regions
461 ------------------
462
463 COLMAP supports masking of keypoints during feature extraction two different ways:
464
465 1. Passing ``mask_path`` to a folder with image masks. For a given image, the corresponding
466 mask must have the same sub-path below this root as the image has below
467 ``image_path``. The filename must be equal, aside from the added extension
468 ``.png``. For example, for an image ``image_path/abc/012.jpg``, the mask would
469 be ``mask_path/abc/012.jpg.png``.
470
471 2. Passing ``camera_mask_path`` to a single mask image. This single mask is applied to all images.
472
473 In both cases no features will be extracted in regions,
474 where the mask image is black (pixel intensity value 0 in grayscale).
475
476
477 Image orientation and EXIF
478 --------------------------
479
480 COLMAP automatically reads the EXIF orientation tag from images during feature
481 extraction. The orientation is converted to a gravity direction vector in sensor
482 coordinates, which is stored as part of the pose prior in the database. This
483 gravity information is used during feature extraction and matching to improve
484 robustness against image rotation. This is crucial for feature extractors/matchers
485 with limited orientation invariance, such as ALIKED, LightGlue, and LoMa.
486
487
488
489 Register/localize new images into an existing reconstruction
490 ------------------------------------------------------------
491
492 If you have an existing reconstruction of images and want to register/localize
493 new images within this reconstruction, you can follow these steps::
494
495 colmap feature_extractor \
496 --database_path $PROJECT_PATH/database.db \
497 --image_path $PROJECT_PATH/images \
498 --image_list_path /path/to/image-list.txt
499
500 colmap vocab_tree_matcher \
501 --database_path $PROJECT_PATH/database.db \
502 --VocabTreeMatching.match_list_path /path/to/image-list.txt
503
504 colmap image_registrator \
505 --database_path $PROJECT_PATH/database.db \
506 --input_path /path/to/existing-model \
507 --output_path /path/to/model-with-new-images
508
509 colmap bundle_adjuster \
510 --input_path /path/to/model-with-new-images \
511 --output_path /path/to/model-with-new-images
512
513 Note that this first extracts features for the new images, then matches them to
514 the existing images in the database, and finally registers them into the model.
515 The image list text file contains a list of images to extract and match,
516 specified as one image file name per line. The bundle adjustment is optional.
517
518 If you need a more accurate image registration with triangulation, then you
519 should restart or continue the reconstruction process rather than just
520 registering the images to the model. Instead of running the
521 ``image_registrator``, you should run the ``mapper`` to continue the
522 reconstruction process from the existing model::
523
524 colmap mapper \
525 --database_path $PROJECT_PATH/database.db \
526 --image_path $PROJECT_PATH/images \
527 --input_path /path/to/existing-model \
528 --output_path /path/to/model-with-new-images
529
530 Or, alternatively, you can start the reconstruction from scratch::
531
532 colmap mapper \
533 --database_path $PROJECT_PATH/database.db \
534 --image_path $PROJECT_PATH/images \
535 --output_path /path/to/model-with-new-images
536
537 Note that dense reconstruction must be re-run from scratch after running the
538 ``mapper`` or the ``bundle_adjuster``, as the coordinate frame of the model can
539 change during these steps.
540
541
542 Available functionality without GPU/CUDA
543 ----------------------------------------
544
545 If you do not have a CUDA-enabled GPU but some other GPU, you can use all COLMAP
546 functionality except the dense reconstruction part. However, you can use
547 external dense reconstruction software as an alternative, as described in the
548 :ref:`Tutorial <dense-reconstruction>`. If you have a GPU with low compute power
549 or you want to execute COLMAP on a machine without an attached display and
550 without CUDA support, you can run all steps on the CPU by specifying the
551 appropriate options (e.g., ``--FeatureExtraction.use_gpu=false`` for the feature
552 extraction step). But note that this might result in a significant slow-down of
553 the reconstruction pipeline. Please, also note that feature extraction on the
554 CPU can consume excessive RAM for large images in the default settings, which
555 might require manually reducing the maximum image size using
556 ``--FeatureExtraction.max_image_size`` and/or setting
557 ``--SiftExtraction.first_octave 0`` or by manually limiting the number of
558 threads using ``--FeatureExtraction.num_threads``.
559
560
561 Multi-GPU support in feature extraction/matching
562 ------------------------------------------------
563
564 You can run feature extraction/matching on multiple GPUs by specifying multiple
565 indices for CUDA-enabled GPUs, e.g., ``--FeatureExtraction.gpu_index=0,1,2,3`` and
566 ``--FeatureMatching.gpu_index=0,1,2,3`` runs the feature extraction/matching on 4
567 GPUs in parallel. Note that you can only run one thread per GPU and this
568 typically also gives the best performance. By default, COLMAP runs one feature
569 extraction/matching thread per CUDA-enabled GPU and this usually gives the best
570 performance as compared to running multiple threads on the same GPU.
571
572
573 Feature matching fails due to illegal memory access
574 ---------------------------------------------------
575
576 If you encounter the following error message::
577
578 MultiplyDescriptor: an illegal memory access was encountered
579
580 or the following:
581
582 ERROR: Feature matching failed. This probably caused by insufficient GPU
583 memory. Consider reducing the maximum number of features.
584
585 during feature matching, your GPU runs out of memory. Try decreasing the option
586 ``--FeatureMatching.max_num_matches`` until the error disappears. Note that this
587 might lead to inferior feature matching results, since the lower-scale input
588 features will be clamped in order to fit them into GPU memory. Alternatively,
589 you could change to CPU-based feature matching, but this can become very slow,
590 or better you buy a GPU with more memory.
591
592 The maximum required GPU memory can be approximately estimated using the
593 following formula: ``4 * num_matches * num_matches + 4 * num_matches * 256`` for SIFT.
594 For example, if you set ``--FeatureMatching.max_num_matches 10000``, the maximum
595 required GPU memory will be around 400MB, which are only allocated if one of
596 your images actually has that many features.
597
598
599 .. _speedup-bundle-adjustment:
600
601 Speedup bundle adjustment
602 -------------------------
603
604 The following describes practical ways to reduce bundle adjustment runtime.
605
606 - **Reduce the problem size**
607
608 Limit the number of correspondences so that BA solves a smaller problem:
609
610 - Reduce features by decreasing ``--SiftExtraction.max_image_size`` and/or
611 ``--SiftExtraction.max_num_features``.
612 - Reduce matching pairs (and avoid ``exhaustive_matcher`` when possible) by
613 decreasing ``--SequentialMatching.overlap``,
614 ``--SpatialMatching.max_num_neighbors``, or ``--VocabTreeMatching.num_images``.
615 - Reduce matches by decreasing ``--FeatureMatching.max_num_matches``.
616 - Enable experimental landmark pruning to drop redundant 3D points using
617 ``--Mapper.ba_global_ignore_redundant_points3D 1``.
618
619 - **Utilize GPU acceleration**
620
621 Enable GPU-based Ceres solvers for bundle adjustment by setting
622 ``--Mapper.ba_use_gpu 1`` for the ``mapper`` and ``--BundleAdjustmentCeres.use_gpu 1``
623 for the standalone ``bundle_adjuster``. Several parameters control when and which
624 GPU solver is used:
625
626 - The GPU solver is activated only when the number of images exceeds
627 ``--BundleAdjustmentCeres.min_num_images_gpu_solver``.
628 - Select between the direct dense, direct sparse, and iterative sparse GPU solvers
629 using ``--BundleAdjustmentCeres.max_num_images_direct_dense_gpu_solver`` and
630 ``--BundleAdjustmentCeres.max_num_images_direct_sparse_gpu_solver``
631
632 .. Attention:: COLMAP's official CUDA-enabled binaries are not distributed with
633 ceres[cuda] until Ceres 2.3 is officially released. To use the GPU solvers you
634 must compile Ceres with the CUDA/cuDSS support and link that build to COLMAP.
635
636 **Note:** Low GPU utilization for the Schur-based sparse solver (cuDSS) can occur
637 when the Schur-complement matrix becomes less sparse (i.e., exhibits more fill-in).
638 Typical causes include:
639
640 - High image covisibility
641 - Shared camera intrinsics.
642
643 - **Use the Caspar GPU bundle adjustment backend**
644
645 COLMAP includes Caspar [caspar]_, an experimental GPU-accelerated bundle
646 adjustment backend that can be one to two orders of magnitude faster than the
647 Ceres CUDA solver for medium- to large-scale problems, leading to drastic
648 speedups especially for the incremental mapper. Caspar requires CUDA and is
649 disabled by default; it must be enabled at build time by configuring COLMAP
650 with ``-DCASPAR_ENABLED=ON``.
651
652 Caspar is selected through the bundle adjustment ``backend`` option, which
653 accepts ``CERES`` (default) or ``CASPAR``:
654
655 - Standalone ``bundle_adjuster``: ``--BundleAdjustment.backend CASPAR``.
656 - Incremental ``mapper``: ``--Mapper.ba_local_backend CASPAR`` and/or
657 ``--Mapper.ba_global_backend CASPAR``. The GPU device is selected via
658 ``--Mapper.ba_gpu_index``.
659
660 The solver behavior and GPU device of the standalone backend can be tuned via
661 the ``--BundleAdjustmentCaspar.*`` options, e.g. ``--BundleAdjustmentCaspar.gpu_index``
662 (default ``-1`` auto-selects the best CUDA device).
663
664 .. Attention:: Caspar is experimental and currently supports only the
665 ``SIMPLE_RADIAL`` and ``PINHOLE`` camera models; observations using other
666 camera models are skipped. It does not support pose priors or refining
667 ``sensor_from_rig`` for non-reference rig sensors, and requires
668 ``refine_focal_length`` and ``refine_extra_params`` to be equal. The
669 ``global_mapper`` does not expose a Caspar backend selector.
670
671 - **Additional practical tips**
672
673 - Improve initial conditions by tuning observation-filtering parameters so BA
674 receives more inliers and fewer outliers, or by supplying accurate priors
675 (e.g., intrinsics, poses).
676 - Fix or restrict refinement of parameters when possible (e.g., hold intrinsics
677 fixed if they are known) to reduce the number of optimized variables.
678 - Reduce LM iterations or relax convergence tolerances to trade a small amount of
679 accuracy for runtime: ``--Mapper.ba_global_max_num_iterations``,
680 ``--Mapper.ba_global_function_tolerance``.
681 - Reduce the frequency of expensive global BA passes with mapper options:
682 ``--Mapper.ba_global_frames_freq``, ``--Mapper.ba_global_points_freq``,
683 ``--Mapper.ba_global_frames_ratio`` and ``--Mapper.ba_global_points_ratio``.
684
685
686 Trading off completeness and accuracy in dense reconstruction
687 -------------------------------------------------------------
688
689 If the dense point cloud contains too many outliers and too much noise, try to
690 increase the value of option ``--StereoFusion.min_num_pixels``.
691
692 If the reconstructed dense surface mesh model using Poisson reconstruction
693 contains no surface or there are too many outlier surfaces, you should reduce
694 the value of option ``--PoissonMeshing.trim`` to decrease the surface area and
695 vice versa to increase it. Also consider to try the reduce the outliers or
696 increase the completeness in the fusion stage, as described above.
697
698 If the reconstructed dense surface mesh model using Delaunay reconstruction
699 contains too noisy or incomplete surfaces, you should increase the
700 ``--DelaunayMeshing.quality_regularization`` parameter to obtain a smoother
701 surface. If the resolution of the mesh is too coarse, you should reduce the
702 ``--DelaunayMeshing.max_proj_dist`` option to a lower value.
703
704
705 Improving dense reconstruction results for weakly textured surfaces
706 -------------------------------------------------------------------
707
708 For scenes with weakly textured surfaces it can help to have a high resolution
709 of the input images (``--PatchMatchStereo.max_image_size``) and a large patch window
710 radius (``--PatchMatchStereo.window_radius``). You may also want to reduce the
711 filtering threshold for the photometric consistency cost
712 (``--PatchMatchStereo.filter_min_ncc``).
713
714
715 Surface mesh reconstruction
716 ---------------------------
717
718 COLMAP supports three surface reconstruction algorithms:
719
720 - **Poisson surface reconstruction** [kazhdan2013]_ typically requires an almost
721 outlier-free input point cloud and often produces bad surfaces in the presence
722 of outliers or large holes in the input data.
723
724 - **Delaunay triangulation** based meshing is more robust to outliers and in
725 general more scalable to large datasets than the Poisson algorithm, but it
726 usually produces less smooth surfaces. It can be applied to both sparse and
727 dense reconstruction results.
728
729 - **Advancing front surface reconstruction** [cohen-steiner2004]_ incrementally
730 grows a surface mesh from a Delaunay triangulation of the input points.
731 It supports visibility-based filtering to remove faces that violate free-space
732 constraints and block-wise parallel processing for large-scale scenes. It uses
733 a float32 CGAL kernel for memory efficiency.
734
735 To increase the smoothness of the surface as a post-processing step, you could
736 use Laplacian smoothing, as e.g. implemented in Meshlab.
737
738 Note that Poisson and Delaunay meshing can also be combined by first running the
739 Delaunay meshing to robustly filter outliers from the sparse or dense point
740 cloud and then, in the second step, performing Poisson surface reconstruction to
741 obtain a smooth surface.
742
743 After meshing, the ``mesh_texturer`` command can be used to produce a textured
744 mesh with a texture atlas [waechter2014]_. This assigns each mesh face to the
745 best-view camera image based on projected area and viewing angle, and bakes the
746 texture into an atlas with per-face UV coordinates. The command requires the
747 undistorted workspace produced by ``image_undistorter`` as input.
748
749
750 Speedup dense reconstruction
751 ----------------------------
752
753 The dense reconstruction can be speeded up in multiple ways:
754
755 - Put more GPUs in your system as the dense reconstruction can make use of
756 multiple GPUs during the stereo reconstruction step. Put more RAM into your
757 system and increase the ``--PatchMatchStereo.cache_size``,
758 ``--StereoFusion.cache_size`` to the largest possible value in order to
759 speed up the dense fusion step.
760
761 - Do not perform geometric dense stereo reconstruction
762 ``--PatchMatchStereo.geom_consistency false``. Make sure to also enable
763 ``--PatchMatchStereo.filter true`` in this case.
764
765 - Reduce the ``--PatchMatchStereo.max_image_size``, ``--StereoFusion.max_image_size``
766 values to perform dense reconstruction on a maximum image resolution.
767
768 - Reduce the number of source images per reference image to be considered, as
769 described :ref:`here <faq-dense-memory>`.
770
771 - Increase the patch windows step ``--PatchMatchStereo.window_step`` to 2.
772
773 - Reduce the patch window radius ``--PatchMatchStereo.window_radius``.
774
775 - Reduce the number of patch match iterations ``--PatchMatchStereo.num_iterations``.
776
777 - Reduce the number of sampled views ``--PatchMatchStereo.num_samples``.
778
779 - To speedup the dense stereo and fusion step for very large reconstructions,
780 you can use CMVS to partition your scene into multiple clusters and to prune
781 redundant images, as described :ref:`here <faq-dense-memory>`.
782
783 Note that apart from upgrading your hardware, the proposed changes might degrade
784 the quality of the dense reconstruction results. When canceling the stereo
785 reconstruction process and restarting it later, the previous progress is not
786 lost and any already processed views will be skipped.
787
788
789 .. _faq-dense-memory:
790
791 Reduce memory usage during dense reconstruction
792 -----------------------------------------------
793
794 If you run out of GPU memory during patch match stereo, you can either reduce
795 the maximum image size by setting the option ``--PatchMatchStereo.max_image_size`` or
796 reduce the number of source images in the ``stereo/patch-match.cfg`` file from
797 e.g. ``__auto__, 30`` to ``__auto__, 10``. Note that enabling the
798 ``geom_consistency`` option increases the required GPU memory.
799
800 If you run out of CPU memory during stereo or fusion, you can reduce the
801 ``--PatchMatchStereo.cache_size`` or ``--StereoFusion.cache_size`` specified in
802 gigabytes or you can reduce ``--PatchMatchStereo.max_image_size`` or
803 ``--StereoFusion.max_image_size``. Note that a too low value might lead to very
804 slow processing and heavy load on the hard disk.
805
806 For large-scale reconstructions of several thousands of images, you should
807 consider splitting your sparse reconstruction into more manageable clusters of
808 images using e.g. CMVS [furukawa10]_. In addition, CMVS allows to prune
809 redundant images observing the same scene elements. Note that, for this use
810 case, COLMAP's dense reconstruction pipeline also supports the PMVS/CMVS folder
811 structure when executed from the command-line. Please, refer to the workspace
812 folder for example shell scripts. Note that the example shell scripts for
813 PMVS/CMVS are only generated, if the output type is set to PMVS. Since CMVS
814 produces highly overlapping clusters, it is recommended to increase the default
815 value of 100 images per cluster to as high as possible according to your
816 available system resources and speed requirements. To change the number of
817 images using CMVS, you must modify the shell scripts accordingly. For example,
818 ``cmvs pmvs/ 500`` to limit each cluster to 500 images. If you want to use CMVS
819 to prune redundant images but not to cluster the scene, you can simply set this
820 number to a very large value.
821
822
823 .. _faq-dense-manual-source:
824
825 Manual specification of source images during dense reconstruction
826 -----------------------------------------------------------------
827
828 You can change the number of source images in the ``stereo/patch-match.cfg``
829 file from e.g. ``__auto__, 30`` to ``__auto__, 10``. This selects the images
830 with the most visual overlap automatically as source images. You can also use
831 all other images as source images, by specifying ``__all__``. Alternatively, you
832 can manually specify images with their name, for example::
833
834 image1.jpg
835 image2.jpg, image3.jpg
836 image2.jpg
837 image1.jpg, image3.jpg
838 image3.jpg
839 image1.jpg, image2.jpg
840
841 Here, ``image2.jpg`` and ``image3.jpg`` are used as source images for
842 ``image1.jpg``, etc.
843
844
845 Multi-GPU support in dense reconstruction
846 -----------------------------------------
847
848 You can run dense reconstruction on multiple GPUs by specifying multiple indices
849 for CUDA-enabled GPUs, e.g., ``--PatchMatchStereo.gpu_index=0,1,2,3`` runs the dense
850 reconstruction on 4 GPUs in parallel. You can also run multiple dense
851 reconstruction threads on the same GPU by specifying the same GPU index twice,
852 e.g., ``--PatchMatchStereo.gpu_index=0,0,1,1,2,3``. By default, COLMAP runs one
853 dense reconstruction thread per CUDA-enabled GPU.
854
855
856 .. _faq-dense-timeout:
857
858 Fix GPU freezes and timeouts during dense reconstruction
859 --------------------------------------------------------
860
861 The stereo reconstruction pipeline runs on the GPU using CUDA and puts the GPU
862 under heavy load. You might experience a display freeze or even a program crash
863 during the reconstruction. As a solution to this problem, you could use a
864 secondary GPU in your system, that is not connected to your display by setting
865 the GPU indices explicitly (usually index 0 corresponds to the card that the
866 display is attached to). Alternatively, you can increase the GPU timeouts of
867 your system, as detailed in the following.
868
869 By default, the Windows operating system detects response problems from the GPU,
870 and recovers to a functional desktop by resetting the card and aborting the
871 stereo reconstruction process. The solution is to increase the so-called
872 "Timeout Detection & Recovery" (TDR) delay to a larger value. Please, refer to
873 the `NVIDIA Nsight documentation <https://goo.gl/UWKVs6>`_ or to the `Microsoft
874 documentation <http://www.microsoft.com/whdc/device/display/wddm_timeout.mspx>`_
875 on how to increase the delay time under Windows. You can increase the delay
876 using the following Windows Registry entries::
877
878 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers]
879 "TdrLevel"=dword:00000001
880 "TdrDelay"=dword:00000120
881
882 To set the registry entries, execute the following commands using administrator
883 privileges (e.g., in ``cmd.exe`` or ``powershell.exe``)::
884
885 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers /v TdrLevel /t REG_DWORD /d 00000001
886 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers /v TdrDelay /t REG_DWORD /d 00000120
887
888 and restart your machine afterwards to make the changes effective.
889
890 The X window system under Linux/Unix has a similar feature and detects response
891 problems of the GPU. The easiest solution to avoid timeout problems under the X
892 window system is to shut it down and run the stereo reconstruction from the
893 command-line. Under Ubuntu, you could first stop X using::
894
895 sudo service lightdm stop
896
897 And then run the dense reconstruction code from the command-line::
898
899 colmap patch_match_stereo ...
900
901 Finally, you can restart your desktop environment with the following command::
902
903 sudo service lightdm start
904
905 If the dense reconstruction still crashes after these changes, the reason is
906 probably insufficient GPU memory, as discussed in a separate item in this list.