Debian Codegraph @

doc/format.rst

raw
1 .. _output-format:
2
3 Output Format
4 =============
5
6 ==================
7 Binary File Format
8 ==================
9
10 Note that all binary data is stored using little endian byte ordering. All x86
11 processors are little endian and thus no special care has to be taken when
12 reading COLMAP binary data on most platforms. The data can be most conveniently
13 parsed using the C++ reconstruction API under ``src/colmap/scene/reconstruction_io.h``
14 or using the Python API provided by pycolmap.
15
16
17 =======================
18 Indices and Identifiers
19 =======================
20
21 Any variable name ending with ``*_idx`` should be considered as an ordered,
22 contiguous zero-based index. In general, any variable name ending with ``*_id``
23 should be considered as an unordered, non-contiguous identifier.
24
25 For example, the unique identifiers of cameras (``CAMERA_ID``), images
26 (``IMAGE_ID``), and 3D points (``POINT3D_ID``) are unordered and are most likely not
27 contiguous. This also means that the maximum ``POINT3D_ID`` does not necessarily
28 correspond to the number 3D points, since some ``POINT3D_ID``'s are missing due to
29 filtering during the reconstruction, etc.
30
31
32 =====================
33 Sparse Reconstruction
34 =====================
35
36 By default, COLMAP uses a binary file format (machine-readable, fast) for
37 storing sparse models. In addition, COLMAP provides the option to store the
38 sparse models as text files (human-readable, slow). In both cases, the
39 information is split into multiples files for the information about ``rigs``,
40 ``cameras``, ``frames``, ``images``, and ``points``. Any directory containing these
41 files constitutes a sparse model. The binary files have the file extension
42 ``.bin`` and the text files the file extension ``.txt``. Note that when loading a
43 model from a directory which contains both binary and text files, COLMAP prefers
44 the binary format.
45
46 Note that older versions of COLMAP had no rig support and thus the ``rigs`` and
47 ``frames`` files may be missing. The reconstruction I/O routines in COLMAP are
48 fully backwards compatible in that models without these files can be read and
49 trivial rigs and frames will be automatically initialized. Furthermore, newer
50 output reconstructions' ``cameras`` and ``images`` files are fully compatible with
51 old outputs.
52
53 To export the currently selected model in the GUI, choose ``File > Export
54 model``. To export all reconstructed models in the current dataset, choose
55 ``File > Export all``. The selected folder then contains the model files, and
56 for convenience, the current project configuration for importing the model to
57 COLMAP. To import the exported models, e.g., for visualization or to resume the
58 reconstruction, choose ``File > Import model`` and select the folder containing
59 the ``rigs``, ``cameras``, ``frames``, ``images``, and ``points3D`` files.
60
61 To convert between the binary and text format in the GUI, you can load the model
62 using ``File > Import model`` and then export the model in the desired output
63 format using ``File > Export model`` (binary) or ``File > Export model as text``
64 (text). In addition, you can export sparse models to other formats, such as
65 VisualSfM's NVM, Bundler files, PLY, VRML, etc., using ``File > Export as...``.
66 To convert between various formats from the CLI, use the ``model_converter``
67 executable.
68
69 There are two source files to conveniently read the sparse reconstructions using
70 Python (pycolmap) and Matlab (``scripts/matlab/read_model.m`` supporting text).
71
72
73 -----------
74 Text Format
75 -----------
76
77 COLMAP exports the following text files for every reconstructed model:
78 ``rigs.txt``, ``cameras.txt``, ``frames.txt``, ``images.txt``, and ``points3D.txt``.
79 Comments start with a leading "#" character and are ignored. The first comment
80 lines briefly describe the format of the text files, as described in more
81 detailed on this page.
82
83
84 rigs.txt
85 -----------
86
87 This file contains the configured rigs and sensors, e.g.::
88
89 # Rig calib list with one line of data per calib:
90 # RIG_ID, NUM_SENSORS, REF_SENSOR_TYPE, REF_SENSOR_ID, SENSORS[] as (SENSOR_TYPE, SENSOR_ID, HAS_POSE, [QW, QX, QY, QZ, TX, TY, TZ])
91 # Number of rigs: 1
92 1 2 CAMERA 1 CAMERA 2 1 -0.9999701516465348 -0.0011120266840749639 -0.0075347911527510894 0.0012985125893421306 -0.19316906391350164 0.00085222218993398979 0.0070758955539026785
93 2 1 CAMERA 3
94
95 Here, the dataset contains two rigs: the first rig has two cameras and the second
96 one has 1 camera.
97
98
99 cameras.txt
100 -----------
101
102 This file contains the intrinsic parameters of all reconstructed cameras in the
103 dataset using one line per camera, e.g.::
104
105 # Camera list with one line of data per camera:
106 # CAMERA_ID, MODEL, WIDTH, HEIGHT, PARAMS[]
107 # Number of cameras: 3
108 1 SIMPLE_PINHOLE 3072 2304 2559.81 1536 1152
109 2 PINHOLE 3072 2304 2560.56 2560.56 1536 1152
110 3 SIMPLE_RADIAL 3072 2304 2559.69 1536 1152 -0.0218531
111
112 Here, the dataset contains 3 cameras based on different distortion models
113 with the same sensor dimensions (width: 3072, height: 2304). The length of
114 parameters is variable and depends on the camera model. For the first camera,
115 there are 3 parameters with a single focal length of 2559.81 pixels and a
116 principal point at pixel location ``(1536, 1152)``. The intrinsic parameters of a
117 camera can be shared by multiple images, which refer to cameras using the unique
118 identifier ``CAMERA_ID``.
119
120
121 frames.txt
122 ----------
123
124 This file contains the frames, where a frame defines a specific
125 instance of a rig with all or a subset of sensors exposed at the same time, e.g.::
126
127 # Frame list with one line of data per frame:
128 # FRAME_ID, RIG_ID, RIG_FROM_WORLD[QW, QX, QY, QZ, TX, TY, TZ], NUM_DATA_IDS, DATA_IDS[] as (SENSOR_TYPE, SENSOR_ID, DATA_ID)
129 # Number of frames: 151
130 1 1 0.99801363919752195 0.040985139360073107 0.041890917712361225 -0.023111584553400576 -5.2666546897987896 -0.17120007823690631 0.12300519697527648 2 CAMERA 1 1 CAMERA 2 2
131 2 2 0.99816472047267968 0.037605501383281774 0.043101511724657163 -0.019881568259519072 -5.1956060695789192 -0.20794508616745555 0.14967533910764824 1 CAMERA 3 3
132
133 Here, the dataset contains two frames, where frame 1 is an instance of rig 1 and
134 frame 2 an instance of rig 2.
135
136
137 images.txt
138 ----------
139
140 This file contains the pose and keypoints of all reconstructed images in the
141 dataset using two lines per image, e.g.::
142
143 # Image list with two lines of data per image:
144 # IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME
145 # POINTS2D[] as (X, Y, POINT3D_ID)
146 # Number of images: 2, mean observations per image: 2
147 1 0.851773 0.0165051 0.503764 -0.142941 -0.737434 1.02973 3.74354 1 P1180141.JPG
148 2362.39 248.498 58396 1784.7 268.254 59027 1784.7 268.254 -1
149 2 0.851773 0.0165051 0.503764 -0.142941 -0.737434 1.02973 3.74354 1 P1180142.JPG
150 1190.83 663.957 23056 1258.77 640.354 59070
151
152 Here, the first two lines define the information of the first image, and so on.
153 The reconstructed pose of an image is specified as the projection from world to
154 the camera coordinate system of an image using a quaternion ``(QW, QX, QY, QZ)``
155 and a translation vector ``(TX, TY, TZ)``. The quaternion is defined using the
156 Hamilton convention, which is, for example, also used by the Eigen library. The
157 coordinates of the projection/camera center are given by ``-R^t * T``, where
158 ``R^t`` is the inverse/transpose of the 3x3 rotation matrix composed from the
159 quaternion and ``T`` is the translation vector. The local camera coordinate
160 system of an image is defined in a way that the X axis points to the right, the
161 Y axis to the bottom, and the Z axis to the front as seen from the image.
162
163 Both images in the example above use the same camera model and share intrinsics
164 (``CAMERA_ID = 1``). The image name is relative to the selected base image folder
165 of the project. The first image has 3 keypoints and the second image has 2
166 keypoints, while the location of the keypoints is specified in pixel
167 coordinates. Both images observe 2 3D points and note that the last keypoint of
168 the first image does not observe a 3D point in the reconstruction as the 3D
169 point identifier is -1.
170
171
172 points3D.txt
173 ------------
174
175 This file contains the information of all reconstructed 3D points in the
176 dataset using one line per point, e.g.::
177
178 # 3D point list with one line of data per point:
179 # POINT3D_ID, X, Y, Z, R, G, B, ERROR, TRACK[] as (IMAGE_ID, POINT2D_IDX)
180 # Number of points: 3, mean track length: 3.3334
181 63390 1.67241 0.292931 0.609726 115 121 122 1.33927 16 6542 15 7345 6 6714 14 7227
182 63376 2.01848 0.108877 -0.0260841 102 209 250 1.73449 16 6519 15 7322 14 7212 8 3991
183 63371 1.71102 0.28566 0.53475 245 251 249 0.612829 118 4140 117 4473
184
185 Here, there are three reconstructed 3D points, where ``POINT2D_IDX`` defines the
186 zero-based index of the keypoint in the ``images.txt`` file. The error is given in
187 pixels of reprojection error and is only updated after global bundle adjustment.
188
189
190 ====================
191 Dense Reconstruction
192 ====================
193
194 COLMAP uses the following workspace folder structure::
195
196 +── images
197 │   +── image1.jpg
198 │   +── image2.jpg
199 │   +── ...
200 +── sparse
201 │   +── cameras.txt
202 │   +── images.txt
203 │   +── points3D.txt
204 +── stereo
205 │   +── consistency_graphs
206 │   │   +── image1.jpg.photometric.bin
207 │   │   +── image2.jpg.photometric.bin
208 │   │   +── ...
209 │   +── depth_maps
210 │   │   +── image1.jpg.photometric.bin
211 │   │   +── image2.jpg.photometric.bin
212 │   │   +── ...
213 │   +── normal_maps
214 │   │   +── image1.jpg.photometric.bin
215 │   │   +── image2.jpg.photometric.bin
216 │   │   +── ...
217 │   +── patch-match.cfg
218 │   +── fusion.cfg
219 +── fused.ply
220 +── meshed-poisson.ply
221 +── meshed-delaunay.ply
222 +── textured
223 │ +── mesh.ply
224 │ +── texture.png
225 +── run-colmap-geometric.sh
226 +── run-colmap-photometric.sh
227
228 Here, the ``images`` folder contains the undistorted images, the ``sparse`` folder
229 contains the sparse reconstruction with undistorted cameras, the ``stereo`` folder
230 contains the stereo reconstruction results, ``fused.ply``, ``meshed-poisson.ply``,
231 and ``meshed-delaunay.ply`` are the results of the fusion and meshing procedure,
232 the ``textured`` folder contains the textured mesh (``mesh.ply`` with per-face UV
233 coordinates and ``texture.png`` with the texture atlas) produced by
234 ``mesh_texturer``, and ``run-colmap-geometric.sh`` and
235 ``run-colmap-photometric.sh`` contain example command-line usage to perform the
236 dense reconstruction.
237
238
239 ---------------------
240 Depth and Normal Maps
241 ---------------------
242
243 The depth maps are stored as mixed text and binary files. The text header
244 defines the dimensions of the image in the format ``width&height&channels&``
245 followed by row-major ``float32`` binary data. For depth maps ``channels=1`` and
246 for normal maps ``channels=3``. The depth and normal maps can be conveniently
247 read with Python using pycolmap and
248 with Matlab using the functions in ``scripts/matlab/read_depth_map.m`` and
249 ``scripts/matlab/read_normal_map.m``.
250
251
252 ------------------
253 Consistency Graphs
254 ------------------
255
256 The consistency graph defines, for all pixels in an image, the source images a
257 pixel is consistent with. The graph is stored as a mixed text and binary file,
258 while the text part is equivalent to the depth and normal maps and the binary
259 part is a continuous list of ``int32`` values in the format
260 ``<row><col><N><image_idx1>...<image_idxN>``. Here, ``(row, col)`` defines the
261 location of the pixel in the image followed by a list of ``N`` image indices.
262 The indices are specified w.r.t. the ordering in the ``images.txt`` file.