Debian Codegraph @

doc/database.rst

raw
1 .. _database-format:
2
3 Database Format
4 ===============
5
6 COLMAP stores all extracted information in a single SQLite database file. The
7 database can be accessed with the database management toolkit in the COLMAP GUI,
8 the provided C++ database API (see ``src/colmap/scene/database.h``), or using
9 Python with pycolmap.
10
11 The database contains the following tables:
12
13 - rigs
14 - cameras
15 - frames
16 - images
17 - keypoints
18 - descriptors
19 - matches
20 - two_view_geometries
21
22 To initialize an empty SQLite database file with the required schema, you can
23 either create a new project in the GUI or run the ``colmap database_creator`` command.
24
25
26 Rigs and Sensors
27 ----------------
28
29 The relation between rigs and sensors (cameras, etc.) is 1-to-N with one sensor
30 being chosen as the reference sensor to define the origin of the rig. Each sensor
31 must only be part of one rig.
32
33
34 Rigs and Frames
35 ---------------
36
37 The relation between rigs and frames is 1-to-N, where a frame defines a specific
38 instance of the rig with all or a subset of sensors exposed at the same time.
39
40
41 Cameras and Images
42 ------------------
43
44 The relation between cameras and images is 1-to-N. This has important
45 implications for Structure-from-Motion, since one camera shares the same
46 intrinsic parameters (focal length, principal point, distortion, etc.), while
47 every image has separate extrinsic parameters (orientation and location).
48
49 The intrinsic parameters of cameras are stored as contiguous binary blobs in
50 ``float64``, ordered as specified in ``src/colmap/sensor/models.h``. COLMAP only
51 uses cameras that are referenced by images, all other cameras are ignored.
52
53 The ``name`` column in the images table is the unique relative path in the image
54 folder. As such, the database file and image folder can be moved to different
55 locations, as long as the relative folder structure is preserved.
56
57 When manually inserting images and cameras into the database, make sure
58 that all identifiers are positive and non-zero, i.e. ``image_id > 0``
59 and ``camera_id > 0``.
60
61
62 Keypoints and Descriptors
63 -------------------------
64
65 The detected keypoints are stored as row-major ``float32`` binary blobs, where the
66 first two columns are the X and Y locations in the image, respectively. COLMAP
67 uses the convention that the upper left image corner has coordinate ``(0, 0)`` and
68 the center of the upper left most pixel has coordinate ``(0.5, 0.5)``. If the
69 keypoints have 4 columns, then the feature geometry is a similarity and the
70 third column is the scale and the fourth column the orientation of the feature
71 (according to SIFT conventions). If the keypoints have 6 columns, then the
72 feature geometry is an affinity and the last 4 columns encode its affine shape
73 (see ``src/colmap/feature/types.h`` for details).
74
75 The extracted descriptors are stored as row-major binary blobs, where each row
76 describes the feature appearance of the corresponding entry in the keypoints
77 table. The data type and dimensionality depend on the feature extractor:
78
79 - **SIFT**: ``uint8`` descriptors with 128 dimensions (128 bytes per feature).
80 - **ALIKED**: ``float32`` descriptors with 128 dimensions (512 bytes per feature).
81 - **LOMA_B**: ``float32`` descriptors with 256 dimensions (1024 bytes per
82 feature).
83 - **LOMA_B128**: ``float32`` descriptors with 128 dimensions (512 bytes per
84 feature).
85
86 The ``cols`` column in the descriptors table specifies the number of bytes per
87 descriptor row. For ``uint8`` descriptors, this equals the descriptor dimension.
88 For ``float32`` descriptors, this equals ``4 * dimension``.
89
90 In both tables, the ``rows`` table specifies the number of detected features per
91 image, while ``rows=0`` means that an image has no features. For feature matching
92 and geometric verification, every image must have a corresponding keypoints and
93 descriptors entry. Note that only vocabulary tree matching with fast spatial
94 verification requires meaningful values for the local feature geometry, i.e.,
95 only X and Y must be provided and the other keypoint columns can be set to zero.
96 The rest of the reconstruction pipeline only uses the keypoint locations.
97
98
99 Matches and two-view geometries
100 -------------------------------
101
102 Feature matching stores its output in the ``matches`` table and geometric
103 verification in the ``two_view_geometries`` table. COLMAP only uses the data in
104 ``two_view_geometries`` for reconstruction. Every entry in the two tables stores
105 the feature matches between two unique images, where the ``pair_id`` is the
106 row-major, linear index in the upper-triangular match matrix, generated as
107 follows::
108
109 def image_ids_to_pair_id(image_id1, image_id2):
110 if image_id1 > image_id2:
111 return 2147483647 * image_id2 + image_id1
112 else:
113 return 2147483647 * image_id1 + image_id2
114
115 and image identifiers can be uniquely determined from the ``pair_id`` as::
116
117 def pair_id_to_image_ids(pair_id):
118 image_id2 = pair_id % 2147483647
119 image_id1 = (pair_id - image_id2) / 2147483647
120 return image_id1, image_id2
121
122 The ``pair_id`` enables efficient database queries, as the matches tables may
123 contain several hundred millions of entries. This scheme limits the maximum
124 number of images in a database to 2147483647 (maximum value of signed 32-bit
125 integers), i.e. ``image_id`` must be smaller than 2147483647.
126
127 The binary blobs in the matches tables are row-major ``uint32`` matrices, where
128 the left column are zero-based indices into the features of ``image_id1`` and the
129 second column into the features of ``image_id2``. The column ``cols`` must be 2 and
130 the ``rows`` column specifies the number of feature matches.
131
132 The F, E, H blobs in the ``two_view_geometries`` table are stored as 3x3 matrices
133 in row-major ``float64`` format. The meaning of the ``config`` values are documented
134 in the ``src/colmap/estimators/two_view_geometry.h`` source file.