| 1 |
.. _rig-support: |
| 2 |
|
| 3 |
Rig Support |
| 4 |
=========== |
| 5 |
|
| 6 |
COLMAP has native support for modeling sensor rigs during the reconstruction |
| 7 |
process. The sensors in a rig are assumed to have fixed relative poses between |
| 8 |
each other with one reference sensor defining the origin of the rig. A frame |
| 9 |
defines a specific instance of the rig with all or a subset of sensors exposed |
| 10 |
at the same time. For example, in a stereo camera rig, one camera would be |
| 11 |
defined as the reference sensor and have an identity ``sensor_from_rig`` pose, |
| 12 |
whereas the second camera would be posed relative to the reference camera. Each |
| 13 |
frame would then usually be composed of two images as the measurements of both |
| 14 |
of the cameras at the same time. |
| 15 |
|
| 16 |
Workflow |
| 17 |
-------- |
| 18 |
|
| 19 |
By default, when running the standard reconstruction pipeline, each camera is |
| 20 |
modeled with a separate rig and thus each frame contains only a single image. To |
| 21 |
model rigs, the recommended workflow is to organize images by rigs and cameras |
| 22 |
in a folder structure as follows (ensure that images corresponding to the same |
| 23 |
frame have identical filenames across all folders):: |
| 24 |
|
| 25 |
rig1/ |
| 26 |
camera1/ |
| 27 |
image0001.jpg |
| 28 |
image0002.jpg |
| 29 |
... |
| 30 |
camera2/ |
| 31 |
image0001.jpg # same frame as camera1/image0001.jpg |
| 32 |
image0002.jpg # same frame as camera1/image0002.jpg |
| 33 |
... |
| 34 |
... |
| 35 |
rig2/ |
| 36 |
camera1/ |
| 37 |
... |
| 38 |
... |
| 39 |
... |
| 40 |
|
| 41 |
As a next step, we would first extract features using:: |
| 42 |
|
| 43 |
colmap feature_extractor \ |
| 44 |
--image_path $DATASET_PATH/images \ |
| 45 |
--database_path $DATASET_PATH/database.db \ |
| 46 |
--ImageReader.single_camera_per_folder 1 |
| 47 |
|
| 48 |
By default, the resulting database now contains a separate rig for each camera |
| 49 |
and a separate frame for each image. As such, we must adjust the relationships |
| 50 |
in the database with the desired rig configuration. This is done using:: |
| 51 |
|
| 52 |
colmap rig_configurator \ |
| 53 |
--database_path $DATASET_PATH/database.db \ |
| 54 |
--rig_config_path $DATASET_PATH/rig_config.json |
| 55 |
|
| 56 |
where the ``rig_config.json`` could look as follows, if the relative sensor poses |
| 57 |
in the rig are known a priori:: |
| 58 |
|
| 59 |
[ |
| 60 |
{ |
| 61 |
"cameras": [ |
| 62 |
{ |
| 63 |
"image_prefix": "rig1/camera1/", |
| 64 |
"ref_sensor": true |
| 65 |
}, |
| 66 |
{ |
| 67 |
"image_prefix": "rig1/camera2/", |
| 68 |
"cam_from_rig_rotation": [ |
| 69 |
0.7071067811865475, |
| 70 |
0.0, |
| 71 |
0.7071067811865476, |
| 72 |
0.0 |
| 73 |
], |
| 74 |
"cam_from_rig_translation": [ |
| 75 |
0, |
| 76 |
0, |
| 77 |
0 |
| 78 |
] |
| 79 |
} |
| 80 |
] |
| 81 |
}, |
| 82 |
{ |
| 83 |
"cameras": [ |
| 84 |
{ |
| 85 |
"image_prefix": "rig2/camera1/", |
| 86 |
"ref_sensor": true |
| 87 |
}, |
| 88 |
... |
| 89 |
] |
| 90 |
}, |
| 91 |
... |
| 92 |
] |
| 93 |
|
| 94 |
Notice that this modifies the rig and frame configuration in the database, which |
| 95 |
contains the full specification of rigs that we later feed as an input to |
| 96 |
downstream processing steps. |
| 97 |
|
| 98 |
With known calibrated camera parameters, each camera can optionally also have |
| 99 |
specified ``camera_model_name`` and ``camera_params`` fields. |
| 100 |
|
| 101 |
For more fine-grain configuration of rigs and frames, the most convenient option |
| 102 |
is to manually configure the database using pycolmap by either using the |
| 103 |
``apply_rig_config`` function or by individually adding the desired rig and frame |
| 104 |
objects to the reconstruction for the most flexibility. |
| 105 |
|
| 106 |
Next, we run standard feature matching. Note that it is important to configure |
| 107 |
the rigs before sequential feature matching, as images in consecutive frames will |
| 108 |
be automatically matched against each other. |
| 109 |
|
| 110 |
Finally, we can reconstruct the scene using the standard ``mapper`` command with |
| 111 |
the option of keeping the relative poses in the rig fixed using |
| 112 |
``--Mapper.ba_refine_sensor_from_rig 0``. |
| 113 |
|
| 114 |
Unknown rig sensor poses |
| 115 |
------------------------ |
| 116 |
|
| 117 |
If the relative poses of sensors in the rig are not known a priori and we only |
| 118 |
know that a specific set of sensors are rigidly mounted and exposed at the same |
| 119 |
time, one can attempt the following two-step reconstruction approach. Before |
| 120 |
starting, ensure to organize your images as detailed above and perform feature |
| 121 |
extraction with the ``--ImageReader.single_camera_per_folder 1`` option. |
| 122 |
|
| 123 |
Next, reconstruct the scene without rig constraints by modeling each camera as |
| 124 |
its own rig (the default behavior of COLMAP without further configuration). Note |
| 125 |
that this can be a partial reconstruction from a subset of the full set of input |
| 126 |
images. The only requirement is that each camera must have at least one |
| 127 |
registered image in the same frame with a registered image of the reference |
| 128 |
camera. If the reconstruction was successful and the relative poses between |
| 129 |
registered images look roughly correct, we can proceed with the next step. |
| 130 |
|
| 131 |
The ``rig_configurator`` can also work without ``cam_from_rig_*`` transformations. |
| 132 |
By providing an existing (partial) reconstruction of the scene, it can compute |
| 133 |
the average relative rig sensor poses from all registered images:: |
| 134 |
|
| 135 |
colmap rig_configurator \ |
| 136 |
--database_path $DATASET_PATH/database.db \ |
| 137 |
--input_path $DATASET_PATH/sparse-model-without-rigs-and-frames \ |
| 138 |
--rig_config_path $DATASET_PATH/rig_config.json \ |
| 139 |
[ --output_path $DATASET_PATH/sparse-model-with-rigs-and-frames ] |
| 140 |
|
| 141 |
The provided ``rig_config.json`` must simply omit the respective |
| 142 |
``cam_from_rig_rotation`` and ``cam_from_rig_translation`` fields. |
| 143 |
|
| 144 |
Now, we can either run rig bundle adjustment on the (optional) output |
| 145 |
reconstruction with configured rigs and frames:: |
| 146 |
|
| 147 |
colmap bundle_adjuster \ |
| 148 |
--input_path $DATASET_PATH/sparse-model-with-rigs-and-frames \ |
| 149 |
--output_path $DATASET_PATH/bundled-sparse-model-with-rigs-and-frames |
| 150 |
|
| 151 |
or alternatively start the reconstruction process from scratch with rig |
| 152 |
constraints, which may lead to more accurate reconstruction results:: |
| 153 |
|
| 154 |
colmap mapper |
| 155 |
--image_path $DATASET_PATH/images \ |
| 156 |
--database_path $DATASET_PATH/database.db \ |
| 157 |
--output_path $DATASET_PATH/sparse-model-with-rigs-and-frames |
| 158 |
|
| 159 |
|
| 160 |
Example |
| 161 |
------- |
| 162 |
|
| 163 |
The following example shows an end-to-end example for how to reconstruct one of |
| 164 |
the ETH3D rig datasets using COLMAP's rig support:: |
| 165 |
|
| 166 |
wget https://www.eth3d.net/data/terrains_rig_undistorted.7z |
| 167 |
7zz x terrains_rig_undistorted.7z |
| 168 |
|
| 169 |
colmap feature_extractor \ |
| 170 |
--database_path terrains/database.db \ |
| 171 |
--image_path terrains/images \ |
| 172 |
--ImageReader.single_camera_per_folder 1 |
| 173 |
|
| 174 |
The ETH3D dataset conveniently comes with a groundtruth COLMAP reconstruction |
| 175 |
that we use to configure the sensor rig poses as well as camera models using:: |
| 176 |
|
| 177 |
colmap rig_configurator \ |
| 178 |
--database_path terrains/database.db \ |
| 179 |
--rig_config_path terrains/rig_config.json \ |
| 180 |
--input_path terrains/rig_calibration_undistorted |
| 181 |
|
| 182 |
with the ``rig_config.json``:: |
| 183 |
|
| 184 |
[ |
| 185 |
{ |
| 186 |
"cameras": [ |
| 187 |
{ |
| 188 |
"image_prefix": "images_rig_cam4_undistorted/", |
| 189 |
"ref_sensor": true |
| 190 |
}, |
| 191 |
{ |
| 192 |
"image_prefix": "images_rig_cam5_undistorted/" |
| 193 |
}, |
| 194 |
{ |
| 195 |
"image_prefix": "images_rig_cam6_undistorted/" |
| 196 |
}, |
| 197 |
{ |
| 198 |
"image_prefix": "images_rig_cam7_undistorted/" |
| 199 |
} |
| 200 |
] |
| 201 |
} |
| 202 |
] |
| 203 |
|
| 204 |
Notice that we do not specify the sensor poses, because we used an existing |
| 205 |
reconstruction (in this case, the groundtruth but it can also be a |
| 206 |
reconstruction without rig constraints, as explained in the previous section) to |
| 207 |
automatically infer the average rig extrinsics and camera parameters. |
| 208 |
|
| 209 |
Next, we sequentially match the frames, since they were captured as a video:: |
| 210 |
|
| 211 |
colmap sequential_matcher --database_path terrains/database.db |
| 212 |
|
| 213 |
Depending on the accuracy of the provided sensor_from_rig poses, you can optionally |
| 214 |
enable the option `--FeatureMatching.rig_verification 1` or, if you know that the |
| 215 |
sensors within the same frame do not have visual overlap, you can enable the option |
| 216 |
`--FeatureMatching.skip_image_pairs_in_same_frame 1`. |
| 217 |
|
| 218 |
Finally, we reconstruct the scene using the mapper while keeping the groundtruth |
| 219 |
sensor rig poses and camera parameters fixed:: |
| 220 |
|
| 221 |
mkdir -p terrains/sparse |
| 222 |
colmap mapper \ |
| 223 |
--database_path terrains/database.db \ |
| 224 |
--Mapper.ba_refine_sensor_from_rig 0 \ |
| 225 |
--Mapper.ba_refine_focal_length 0 \ |
| 226 |
--Mapper.ba_refine_extra_params 0 \ |
| 227 |
--image_path terrains/images \ |
| 228 |
--output_path terrains/sparse |
| 229 |
|
| 230 |
|
| 231 |
Reconstruction from 360° spherical images |
| 232 |
----------------------------------------- |
| 233 |
|
| 234 |
COLMAP can handle collections of 360° panoramas by rendering virtual pinhole |
| 235 |
images (similar to a cubemap) and treating them as a camera rig. Since the rig |
| 236 |
extrinsics and camera intrinsics are known, the reconstruction process is more |
| 237 |
robust. We provide an example Python script to reconstruct a 360° collection:: |
| 238 |
|
| 239 |
python python/examples/panorama_sfm.py \ |
| 240 |
--input_image_path image_directory \ |
| 241 |
--output_path output_directory |
| 242 |
|
| 243 |
Make sure to use the version of the script that corresponds to the version of |
| 244 |
COLMAP that you are using, as the script at HEAD is not guaranteed to be |
| 245 |
compatible. |
| 246 |
|
| 247 |
The example is a command-line wrapper around ``pycolmap.panorama.reconstruct``. |
| 248 |
Perspective rendering requires the optional ``panorama`` dependencies, which |
| 249 |
can be installed with ``pip install 'pycolmap[panorama]'``. |