Debian Codegraph @

doc/install.rst

raw
1 .. _installation:
2
3 Installation
4 ============
5
6 You can either download one of the pre-built binaries or build the source code
7 manually. Pre-built binaries and other resources can be downloaded from
8 https://demuc.de/colmap/.
9
10 An overview of system packages for Linux/Unix/BSD distributions are available at
11 https://repology.org/metapackage/colmap/versions. Note that the COLMAP packages
12 in the default repositories for Linux/Unix/BSD do not come with CUDA or HIP/ROCm
13 support, which requires a manual build from source, as explained further below.
14
15 For Mac users, `Homebrew <https://brew.sh>`__ provides a formula for COLMAP with
16 pre-compiled binaries or the option to build from source. After installing
17 homebrew, installing COLMAP is as easy as running ``brew install colmap``.
18
19 COLMAP can be used as an independent application through the command-line or
20 graphical user interface. Alternatively, COLMAP is also built as a reusable
21 library, i.e., you can include and link COLMAP against your own C++ source code,
22 as described further below. Furthermore, you can use most of COLMAP's
23 functionality with :ref:`PyCOLMAP <pycolmap/index>` in Python.
24
25 ------------------
26 Pre-built Binaries
27 ------------------
28
29 Windows
30 -------
31
32 For convenience, the pre-built binaries for Windows contain both the graphical
33 and command-line interface executables. To start the COLMAP GUI, you can simply
34 double-click the ``COLMAP.bat`` batch script or alternatively run it from the
35 Windows command shell or Powershell. The command-line interface is also
36 accessible through this batch script, which automatically sets the necessary
37 library paths. To list the available COLMAP commands, run ``COLMAP.bat -h`` in
38 the command shell ``cmd.exe`` or in Powershell. The first time you run COLMAP,
39 Windows defender may prompt you with a security warning, because the binaries
40 are not officially signed. The provided COLMAP binaries are automatically built
41 from GitHub Actions CI machines. If you do not trust them, you can build from
42 source as described below.
43
44 Docker
45 ------
46
47 COLMAP provides a pre-built Docker image with CUDA support. For detailed
48 instructions on how to build and run COLMAP using Docker, please refer to the
49 `Docker documentation <https://github.com/colmap/colmap/tree/main/docker>`__.
50
51 -----------------
52 Build from Source
53 -----------------
54
55 COLMAP builds on all major platforms (Linux, Mac, Windows) with little effort.
56 First, checkout the latest source code::
57
58 git clone https://github.com/colmap/colmap
59
60 Under Linux and Mac, it is generally recommended to follow the installation
61 instructions below, which use the respective system package managers to install
62 the required dependencies. Alternatively, the instructions for VCPKG can be used
63 to compile the required dependencies from scratch on more exotic systems with
64 limited system packages. The VCPKG approach is also the method of choice under
65 Windows, compute clusters, or if you do not have root access under Linux or Mac.
66
67
68 Debian/Ubuntu
69 -------------
70
71 *Recommended dependencies:* CUDA (at least version 11.X)
72
73 Dependencies from the default Ubuntu repositories::
74
75 sudo apt-get install \
76 git \
77 cmake \
78 ninja-build \
79 build-essential \
80 libboost-program-options-dev \
81 libboost-graph-dev \
82 libboost-system-dev \
83 libeigen3-dev \
84 libopenimageio-dev \
85 openimageio-tools \
86 libmetis-dev \
87 libgoogle-glog-dev \
88 libgtest-dev \
89 libgmock-dev \
90 libsqlite3-dev \
91 libglew-dev \
92 qt6-base-dev \
93 libqt6opengl6-dev \
94 libqt6openglwidgets6 \
95 qt6-svg-dev \
96 libcgal-dev \
97 libceres-dev \
98 libsuitesparse-dev \
99 libcurl4-openssl-dev \
100 libssl-dev \
101 libmkl-full-dev
102 # Fix issue in Ubuntu's openimageio CMake config.
103 # We don't depend on any of openimageio's OpenCV functionality,
104 # but it still requires the OpenCV include directory to exist.
105 sudo mkdir -p /usr/include/opencv4
106
107 Alternatively, you can also build against Qt 5 instead of Qt 6 using::
108
109 qtbase5-dev libqt5opengl5-dev libqt5svg5-dev
110
111 To compile with **CUDA support**, also install Ubuntu's default CUDA package::
112
113 sudo apt-get install -y \
114 nvidia-cuda-toolkit \
115 nvidia-cuda-toolkit-gcc
116
117 Or, manually install the latest CUDA from NVIDIA's homepage. During CMake
118 configuration, specify ``-DCMAKE_CUDA_ARCHITECTURES=native``, if you want to run
119 COLMAP only on your current machine (default), "all"/"all-major" to be able to
120 distribute to other machines, or a specific CUDA architecture like "75", etc.
121
122 To compile with **HIP / ROCm support** instead of CUDA (for AMD GPUs), install
123 ROCm following the `AMD ROCm installation guide
124 <https://rocm.docs.amd.com/projects/install-on-linux/en/latest/>`__ and ensure
125 the ``hip``, ``hiprand``, and ``rocrand`` packages are present (default
126 location ``/opt/rocm``). Then pass the following flags at configure time::
127
128 cmake .. -GNinja \
129 -DCUDA_ENABLED=OFF \
130 -DHIP_ENABLED=ON \
131 -DCMAKE_HIP_ARCHITECTURES=gfx90a \
132 -DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++
133
134 Set ``CMAKE_HIP_ARCHITECTURES`` to match the target AMD GPU
135 (``gfx90a`` for MI200/MI250, ``gfx942`` for MI300, ``gfx1030`` for RDNA2,
136 ``gfx1100`` for RDNA3, etc.; multiple values can be passed as a
137 semicolon-separated list). ``CUDA_ENABLED`` and ``HIP_ENABLED`` are mutually
138 exclusive. CMake 3.21 or newer is required for the HIP backend. On RDNA3
139 consumer parts where ROCm only officially supports a subset of architectures,
140 you may also need ``HSA_OVERRIDE_GFX_VERSION=11.0.0`` in the runtime
141 environment. The HIP backend currently accelerates dense reconstruction
142 (``patch_match_stereo``); see the changelog for ongoing coverage.
143
144 If ROCm is installed through a Python wheel / virtualenv (for example AMD's
145 TheRock packaging, which puts a ``rocm-sdk`` command on the ``PATH``), the
146 install root and target architectures are detected automatically from
147 ``rocm-sdk path --root`` and ``rocm-sdk targets``, so ``ROCM_PATH`` and
148 ``CMAKE_HIP_ARCHITECTURES`` need not be set by hand. An explicit
149 ``-DROCM_PATH`` or a ``ROCM_PATH`` environment variable still takes
150 precedence, and CMake's own architecture autodetection sets
151 ``CMAKE_HIP_ARCHITECTURES`` when a target GPU is visible at configure time.
152
153 Configure and compile COLMAP::
154
155 git clone https://github.com/colmap/colmap.git
156 cd colmap
157 mkdir build
158 cd build
159 cmake .. -GNinja -DBLA_VENDOR=Intel10_64lp
160 ninja
161 sudo ninja install
162
163 .. note::
164
165 COLMAP can use ``boost::unordered`` flat/node hash maps for the
166 performance-critical scene and SfM containers, selected via
167 ``-DCOLMAP_HASH_MAP_BACKEND=BOOST|STD`` (default: auto). Auto selects
168 ``BOOST`` when Boost is recent enough (``boost::unordered_node_map`` requires
169 **Boost >= 1.84**) and falls back to ``STD`` (``std::unordered_map``)
170 otherwise. Ubuntu's default Boost is older than 1.84, so apt-based builds use
171 ``STD``; to use the faster ``BOOST`` backend, build against a newer Boost
172 (e.g. via vcpkg, which installs ``boost-unordered`` automatically) or install
173 Boost >= 1.84 manually. Explicitly requesting ``-DCOLMAP_HASH_MAP_BACKEND=BOOST``
174 with an older Boost is a configuration error.
175
176 Run COLMAP::
177
178 colmap -h
179 colmap gui
180
181 Under **Ubuntu 22.04**, there is a problem when compiling with Ubuntu's default
182 CUDA package and GCC, and you must compile against GCC 10::
183
184 sudo apt-get install gcc-10 g++-10
185 export CC=/usr/bin/gcc-10
186 export CXX=/usr/bin/g++-10
187 export CUDAHOSTCXX=/usr/bin/g++-10
188 # ... and then run CMake against COLMAP's sources.
189
190 Notice that the ``BLA_VENDOR=Intel10_64lp`` option tells CMake to find Intel's MKL
191 implementation of BLAS. If you decide to compile against OpenBLAS instead of
192 MKL, you must install and select the OpenMP version under Debian/Ubuntu because
193 of `this issue <https://github.com/facebookresearch/faiss/wiki/Troubleshooting#surprising-faiss-openmp-and-openblas-interaction>`__.
194
195 Fedora
196 ------
197
198 *Recommended dependencies:* CUDA (at least version 11.X)
199
200 Dependencies from the default Fedora repositories::
201
202 sudo dnf install -y \
203 git \
204 cmake \
205 ninja-build \
206 gcc-c++ \
207 boost-devel \
208 eigen3-devel \
209 OpenImageIO-devel \
210 OpenImageIO-utils \
211 metis-devel \
212 glog-devel \
213 gtest-devel \
214 gmock-devel \
215 sqlite-devel \
216 glew-devel \
217 qt6-qtbase-devel \
218 qt6-qtsvg-devel \
219 CGAL-devel \
220 ceres-solver-devel \
221 suitesparse-devel \
222 suitesparse-static \
223 libcurl-devel \
224 openssl-devel \
225 openblas-devel
226 # suitesparse-static is required even for a dynamic build, because Fedora's
227 # SuiteSparse CMake config references the static targets file regardless of
228 # link type. This can be dropped once Fedora ships SuiteSparse >= 7.11.0 with
229 # its separated static config.
230
231 Alternatively, you can also build against Qt 5 instead of Qt 6 using::
232
233 qt5-qtbase-devel qt5-qtsvg-devel
234
235 To compile with **CUDA support**, install the CUDA toolkit from NVIDIA's official
236 Fedora repository, which (unlike the plain ``cuda`` meta-package) preserves an
237 existing NVIDIA driver. Replace ``<VERSION>`` with your Fedora release, e.g.
238 ``43``::
239
240 sudo dnf config-manager addrepo --from-repofile=https://developer.download.nvidia.com/compute/cuda/repos/fedora<VERSION>/x86_64/cuda-fedora<VERSION>.repo
241 sudo dnf install -y cuda-toolkit
242
243 During CMake configuration, specify ``-DCMAKE_CUDA_ARCHITECTURES=native``, if you
244 want to run COLMAP only on your current machine (default), "all"/"all-major" to be
245 able to distribute to other machines, or a specific CUDA architecture like "89", etc.
246
247 Configure and compile COLMAP::
248
249 git clone https://github.com/colmap/colmap.git
250 cd colmap
251 mkdir build
252 cd build
253 cmake .. -GNinja -DCMAKE_CUDA_ARCHITECTURES=native
254 ninja
255 sudo ninja install
256
257 Run COLMAP::
258
259 colmap -h
260 colmap gui
261
262 Mac
263 ---
264
265 Dependencies from `Homebrew <https://brew.sh/>`__::
266
267 brew install \
268 cmake \
269 ninja \
270 boost \
271 eigen \
272 openimageio \
273 curl \
274 libomp \
275 metis \
276 glog \
277 googletest \
278 ceres-solver \
279 suitesparse \
280 qt \
281 glew \
282 cgal \
283 sqlite3
284 brew link --force libomp
285
286 Configure and compile COLMAP::
287
288 git clone https://github.com/colmap/colmap.git
289 cd colmap
290 mkdir build
291 cd build
292 cmake .. -GNinja
293 ninja
294 sudo ninja install
295
296 If you have Qt 5 installed on your system as well, you might have to temporarily
297 link your Qt 5 installation while configuring CMake::
298
299 brew unlink qt && brew link --force qt
300 cmake ...
301
302 Run COLMAP::
303
304 colmap -h
305 colmap gui
306
307
308 Windows
309 -------
310
311 *Recommended dependencies:* CUDA (at least version 11.X), Visual Studio 2019 or newer
312
313 On Windows, the recommended way is to build COLMAP using VCPKG::
314
315 git clone https://github.com/microsoft/vcpkg
316 cd vcpkg
317 .\bootstrap-vcpkg.bat
318 .\vcpkg install colmap[cuda,tests]:x64-windows
319
320 To compile CUDA for multiple compute architectures, please use::
321
322 .\vcpkg install colmap[cuda-redist]:x64-windows
323
324 Please refer to the next section for more details.
325
326
327 VCPKG
328 -----
329
330 COLMAP ships as part of the VCPKG distribution. This enables to conveniently
331 build COLMAP and all of its dependencies from scratch under different platforms.
332 Note that VCPKG requires you to install CUDA manually in the standard way on
333 your platform. To compile COLMAP using VCPKG, you run::
334
335 git clone https://github.com/microsoft/vcpkg
336 cd vcpkg
337 ./bootstrap-vcpkg.sh
338 ./vcpkg install colmap:x64-linux
339
340 VCPKG ships with support for various other platforms (e.g., x64-osx,
341 x64-windows, etc.). To compile with CUDA support and to build all tests::
342
343 ./vcpkg install colmap[cuda,tests]:x64-linux
344
345 The above commands will build the latest release version of COLMAP. To compile
346 the latest commit in the dev branch, you can use the following options::
347
348 ./vcpkg install colmap:x64-linux --head
349
350 To modify the source code, you can further add ``--editable --no-downloads``.
351 Or, if you want to build from another folder and use the dependencies from
352 vcpkg, first run ``./vcpkg integrate install`` (under Windows use pwsh and
353 ``./scripts/shell/enter_vs_dev_shell.ps1``) and then configure COLMAP as::
354
355 cd path/to/colmap
356 mkdir build
357 cd build
358 cmake .. -DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release
359 cmake --build . --config release --target colmap --parallel 24
360
361 Anaconda/Mamba
362 --------------
363
364 Install miniconda and run the following commands. You can replace ``conda`` with ``mamba`` for faster package installation::
365
366 conda create -n colmap python=3.12
367 conda config --add channels conda-forge
368 conda config --set channel_priority strict
369 conda install \
370 cmake \
371 ninja \
372 boost \
373 ccache \
374 eigen \
375 openimageio \
376 curl \
377 metis \
378 glog \
379 gtest \
380 ceres-solver \
381 suitesparse \
382 qt \
383 glew \
384 sqlite \
385 cgal-cpp \
386 mesa-libgl-devel-cos7-x86_64 \
387 cuda-compiler==12.6.2 \
388 cuda-cudart-dev \
389 cuda-nvrtc-dev \
390 libcurand-dev
391
392 git clone https://github.com/colmap/colmap.git
393 cd colmap
394 mkdir build
395 cd build
396 cmake .. -GNinja
397 ninja
398
399
400
401 .. _installation-library:
402
403 -------
404 Library
405 -------
406
407 If you want to include and link COLMAP against your own library, the easiest way
408 is to use CMake as a build configuration tool. After configuring the COLMAP
409 build and running ``ninja/make install``, COLMAP automatically installs all
410 headers to ``${CMAKE_INSTALL_PREFIX}/include/colmap``, all libraries to
411 ``${CMAKE_INSTALL_PREFIX}/lib/colmap``, and the CMake configuration to
412 ``${CMAKE_INSTALL_PREFIX}/share/colmap``.
413
414 For example, compiling your own source code against COLMAP is as simple as
415 using the following ``CMakeLists.txt``::
416
417 cmake_minimum_required(VERSION 3.10)
418
419 project(SampleProject)
420
421 find_package(colmap REQUIRED)
422 # or to require a specific version: find_package(colmap 3.4 REQUIRED)
423
424 add_executable(hello_world hello_world.cc)
425 target_link_libraries(hello_world colmap::colmap)
426
427 with the source code ``hello_world.cc``::
428
429 #include <cstdlib>
430 #include <iostream>
431
432 #include <colmap/controllers/option_manager.h>
433 #include <colmap/util/string.h>
434
435 int main(int argc, char** argv) {
436 colmap::InitializeGlog(argv);
437
438 std::string message;
439 colmap::OptionManager options;
440 options.AddRequiredOption("message", &message);
441 if (!options.Parse(argc, argv)) {
442 return EXIT_FAILURE;
443 }
444
445 std::cout << colmap::StringPrintf("Hello %s!\n", message.c_str());
446
447 return EXIT_SUCCESS;
448 }
449
450 Then compile and run your code as::
451
452 mkdir build
453 cd build
454 export colmap_DIR=${CMAKE_INSTALL_PREFIX}/share/colmap
455 cmake .. -GNinja
456 ninja
457 ./hello_world --message "world"
458
459 The sources of this example are stored under ``doc/sample-project``.
460
461 ----------------
462 Shared Libraries
463 ----------------
464
465 By default, COLMAP builds static libraries. To build shared/dynamic libraries
466 instead, enable the ``BUILD_SHARED_LIBS`` option::
467
468 cmake .. -GNinja -DBUILD_SHARED_LIBS=ON
469
470 Trade-offs compared to static libraries:
471
472 - **Faster incremental linking**: Only the changed shared library needs to be
473 re-linked during development, rather than all executables.
474 - **Reduced disk usage**: Multiple executables share the same library files on
475 disk and in memory.
476 - **No cross-library optimization**: The compiler cannot inline or apply
477 link-time optimization (LTO/IPO) across shared library boundaries, which
478 reduces runtime performance.
479 - **Symbol resolution overhead**: The dynamic linker resolves symbols at load
480 time, adding minor startup cost and indirect call overhead.
481
482 For development workflows, shared libraries can significantly speed up
483 edit-compile-test cycles. For production or benchmarking, static libraries are
484 recommended.
485
486 ----------------
487 AddressSanitizer
488 ----------------
489
490 If you want to build COLMAP with address sanitizer flags enabled, you need to
491 use a recent compiler with ASan support. For example, you can manually install
492 a recent clang version on your Ubuntu machine and invoke CMake as follows::
493
494 CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake .. \
495 -DASAN_ENABLED=ON \
496 -DTESTS_ENABLED=ON \
497 -DCMAKE_BUILD_TYPE=RelWithDebInfo
498
499 Note that it is generally useful to combine ASan with debug symbols to get
500 meaningful traces for reported issues.
501
502 -------------
503 Documentation
504 -------------
505
506 1. Install latest pycolmap for up-to-date pycolmap API documentation.
507 2. Build the documentation::
508
509 cd path/to/colmap/doc
510 pip install -r requirements.txt
511 make html
512 open _build/html/index.html # preview results
513
514 Alternatively, you can build the documentation as PDF, EPUB, etc.::
515
516 make latexpdf
517 open _build/pdf/COLMAP.pdf
518
519 Publishing to the website (`colmap.github.io <https://colmap.github.io/>`__) is
520 automated: whenever documentation-relevant files change on ``main``, the CI
521 pipeline builds these docs and pushes the result to the ``master`` branch of the
522 `colmap/colmap.github.io <https://github.com/colmap/colmap.github.io>`__
523 repository. Pull requests that touch the docs build them too and upload the
524 generated HTML as a downloadable ``docs-preview`` artifact for review, without
525 publishing. The manual steps above are therefore only needed to preview the docs
526 locally.
527
528 For a main release, still copy the previous release as legacy to the "legacy"
529 folder in the website repository, under a folder with the release number
530 (`see here <https://github.com/colmap/colmap.github.io/tree/master/legacy>`__).
531 The automated deploy preserves the existing ``legacy`` folder.