|
| 1 | +# Agisoft Metashape |
| 2 | + |
| 3 | +In order to import the matches and the camera poses into Agisoft Metashape, you must first run a reconstruction with COLMAP or pyCOLMAP (recommended, as it is already integrated into DIM). |
| 4 | +Then, you can export the solution into a [Bundler file format](https://www.cs.cornell.edu/~snavely/bundler/bundler-v0.4-manual.html), which can be imported into Agisoft Metashape. |
| 5 | + |
| 6 | +## Running the reconstruction |
| 7 | + |
| 8 | +To perform an automatic incremental reconstruction with pycolmap, you must first install pycolmap (see [Installation](installation.md)) and then run DIM omitting the `--skip_reconstruction` flag (see [Getting started](getting_started.md)). |
| 9 | + |
| 10 | +```bash |
| 11 | +python main.py --dir ./assets/example_cyprus --pipeline superpoint+lightglue |
| 12 | +``` |
| 13 | + |
| 14 | +This will generate a `reconstruction` folder with the necessary files to import into Agisoft Metashape. |
| 15 | + |
| 16 | +## Importing the solution into Agisoft Metashape |
| 17 | + |
| 18 | +To import the solution into Agisoft Metashape, you have to first load the images into the software (`workflow`-> `add photos`). |
| 19 | + |
| 20 | +Then you can import the solution by importing the camera poses with `File` -> `Import` -> `Import cameras`. |
| 21 | +Here you have to select the `bundler.out` file and the `bundler_list.txt` file, and then click `OK |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +Then you should see the camera poses and the matches between the images. |
| 28 | +Note, that the reconstruction is upside down because the Bunlder format uses a different coordinate system than Agisoft Metashape (with the z axis of the cameras pointing backwards). |
| 29 | +Therefore, you may have to rotate the reconstruction or to use Ground Control Points (GCPs) to georeference the model. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +Opening an image, you can also see the keypoints and the matches between the images. |
| 34 | +Note, that the Bunlder camera model is a simple pinhole camera model, so the radial distortion is not taken into account. |
| 35 | +Therefore, you may see large reprojection errors in the images. |
| 36 | +To fix this, you should import your camera calibration according to the Metashape camera model and run the bundle adjustment (optimization) again. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +## The Bundler file format |
| 42 | + |
| 43 | +The Bundler format is composed of two files: `bundler.out` and `bundler_list.txt`. |
| 44 | + |
| 45 | +The file `bundler.out` contains the camera poses and the matches between the images and it has the following format: |
| 46 | + |
| 47 | +```math |
| 48 | +# Bundle file v0.3 |
| 49 | +<num_cameras> <num_points> |
| 50 | +<camera1> [two integers] |
| 51 | +<camera2> |
| 52 | + ... |
| 53 | +<cameraN> |
| 54 | +<point1> |
| 55 | +<point2> |
| 56 | + ... |
| 57 | +<pointM> |
| 58 | +``` |
| 59 | + |
| 60 | +Where `<camera>` is defined as: |
| 61 | + |
| 62 | +```math |
| 63 | + <f> <k1> <k2> [the focal length, followed by two radial distortion coeffs] |
| 64 | + <R> [a 3x3 matrix representing the camera rotation] |
| 65 | + <t> [a 3-vector describing the camera translation] |
| 66 | +``` |
| 67 | + |
| 68 | +The `<point>` is defined as: |
| 69 | + |
| 70 | +```math |
| 71 | + <position> [a 3-vector describing the 3D position of the point] |
| 72 | + <color> [a 3-vector describing the RGB color of the point] |
| 73 | + <view list> [a list of views the point is visible in] |
| 74 | +``` |
| 75 | + |
| 76 | +The `<view list>` is defined as: |
| 77 | + |
| 78 | +```math |
| 79 | + <track_length> <camera1> <key1> <x> <y> <camera2> <key2> <x> <y> ... |
| 80 | +``` |
| 81 | + |
| 82 | +where `<track_length>` is the number of cameras the point is visible in. |
| 83 | +The list is then followed by the camera index, the keypoint index, and the 2D coordinates of the point in the image. |
| 84 | +Both indices are 0-based. |
| 85 | + |
| 86 | +The pixel positions are floating point numbers in a coordinate system where the origin is the center of the image, the x-axis increases to the right, and the y-axis increases towards the top of the image. Thus, (-w/2, -h/2) is the lower-left corner of the image, and (w/2, h/2) is the top-right corner (where w and h are the width and height of the image). |
| 87 | + |
| 88 | +The Bundler format uses a pinhole camera model; the parameters we estimate for each camera are a focal length (f), two radial distortion parameters (k1 and k2), a rotation (R), and translation (t), as described in the file specification above. The formula for projecting a 3D point X into a camera (R, t, f) is: |
| 89 | + |
| 90 | +```math |
| 91 | + P = R * X + t (conversion from world to camera coordinates) |
| 92 | + p = -P / P.z (perspective division) |
| 93 | + p' = f * r(p) * p (conversion to pixel coordinates) |
| 94 | +``` |
| 95 | + |
| 96 | +Refer to the [Bundler file format](https://www.cs.cornell.edu/~snavely/bundler/bundler-v0.4-manual.html) for more information. |
| 97 | + |
| 98 | +The camera index in `<view list>` is given by the order in which the cameras are listed in the `bundler_list.txt` file, that contains the list of the path of the images used in the reconstruction. |
| 99 | +For example: |
| 100 | + |
| 101 | +```math |
| 102 | +DSC_6470.JPG |
| 103 | +DSC_6474.JPG |
| 104 | +DSC_6472.JPG |
| 105 | +DSC_6475.JPG |
| 106 | +DSC_6469.JPG |
| 107 | +DSC_6467.JPG |
| 108 | +DSC_6466.JPG |
| 109 | +DSC_6473.JPG |
| 110 | +``` |
| 111 | + |
| 112 | +Note, that if the images are not located in the same folder Agisoft Metashape `.psx` file, you must change the paths in the `bundler_list.txt` file before importing the solution into Agisoft Metashape. |
| 113 | +Also, check that the file names in the `bundler_list.txt` file match the actual name of the images (including the extension, with or without capital letters). |
| 114 | + |
| 115 | +An example of the `bundler.out` file is shown below. |
| 116 | + |
| 117 | +<details> |
| 118 | + |
| 119 | +<summary>bundler.out</summary> |
| 120 | + |
| 121 | +``` |
| 122 | +# Bundle file v0.3 |
| 123 | +8 5068 |
| 124 | +1286.7991243248962 0 0 |
| 125 | +0.99996278884580203 -0.0013121224216955584 -0.0085263860149726069 |
| 126 | +-0.0013396167178595475 -0.99999391945312011 -0.0032197024452593013 |
| 127 | +-0.0085221095261131148 0.0032310047256637201 -0.99995846626631835 |
| 128 | +-0.80777295444200337 0.57663840260582766 -0.15525511334915454 |
| 129 | +1286.7991243248962 0 0 |
| 130 | +0.9944298422387321 0.007496545077315649 0.10513368003144505 |
| 131 | +-0.00055919043698891011 -0.99707818214572397 0.076385770893758309 |
| 132 | +0.105399127942814 -0.076019079847643029 -0.99152010737453633 |
| 133 | +-5.1991137793915279 -0.22160254463606963 -0.99094583515584655 |
| 134 | +1286.7991243248962 0 0 |
| 135 | +0.99931655217167026 0.006691041857979663 0.036354621639898832 |
| 136 | +0.0059588178324736507 -0.99977795287841309 0.020212308831227106 |
| 137 | +0.036481790605243467 -0.019981864204930214 -0.99913452750724763 |
| 138 | +-2.688138660837613 0.50323354820091459 0.31616042729962252 |
| 139 | +1286.7991243248962 0 0 |
| 140 | +0.86929247917708286 -0.054902547052811931 0.491239550497794 |
| 141 | +-0.08719186547051487 -0.99526046509080457 0.043060251079238297 |
| 142 | +0.48654718603844849 -0.080264045215458574 -0.86995949262233951 |
| 143 | +-4.2166603261601505 0.19702147201600073 -2.9468777517136671 |
| 144 | +1286.7991243248962 0 0 |
| 145 | +0.99967307085130896 -0.017983902425688095 0.018175001190014438 |
| 146 | +-0.015758916520280036 -0.99313464826656406 -0.11591042646179414 |
| 147 | +0.020134745213698173 0.11558611363823715 -0.99309337041850598 |
| 148 | +1.7882607148764738 2.141918008889161 0.056122945527972187 |
| 149 | +1286.7991243248962 0 0 |
| 150 | +0.85443322001495281 0.036474729613622636 -0.51827933263298509 |
| 151 | +0.069492826027845261 -0.99659260890043411 0.044428808398267128 |
| 152 | +-0.51489282347450027 -0.07397814531765054 -0.85405656390535267 |
| 153 | +4.0136035947712356 -0.24890319703929475 -2.2211101146350618 |
| 154 | +1286.7991243248962 0 0 |
| 155 | +0.9977349416959288 -0.01781447706336892 0.064866251055384697 |
| 156 | +-0.023079383925901007 -0.9964189037647786 0.081343163559071466 |
| 157 | +0.063184872846452397 -0.082655989662913668 -0.99457310400805732 |
| 158 | +4.744331912881119 -0.67485373536633497 0.50235653241970457 |
| 159 | +1286.7991243248962 0 0 |
| 160 | +0.85052582171050761 -0.081299479583431727 0.51961160612820134 |
| 161 | +-0.076379298718601996 -0.99659964940906087 -0.030908599531384154 |
| 162 | +0.52035759755279865 -0.013399008067766919 -0.85384333296681514 |
| 163 | +-2.2708756404217185 0.73112594627182004 -0.97801981077545186 |
| 164 | +-5.3552997586126736 3.9693405899589074 17.493979792539214 |
| 165 | +214 196 176 |
| 166 | +11 0 2597 -460 -250 2 3174 -542 -230 3 2736 -29 -155 4 3531 -250 -282 7 1696 137 -230 0 3358 -465 -253 1 2367 -582 -191 2 3161 -546 -233 3 3431 -33 -156 4 2278 -254 -284 6 2214 33 -227 |
| 167 | +-12.097171629638927 3.302074646768081 30.280100026537617 |
| 168 | +227 202 180 |
| 169 | +2 1 2418 -555 -46 7 4066 113 -101 |
| 170 | +-5.8312471874484419 -1.9822562893941618 14.437672933948106 |
| 171 | +116 80 51 |
| 172 | +3 0 3207 -598 226 2 2420 -722 245 7 3861 35 212 |
| 173 | +0.46832749086366926 4.3310105451941983 16.298232232524828 |
| 174 | +198 180 153 |
| 175 | +... |
| 176 | +``` |
| 177 | + |
| 178 | +</details> |
| 179 | + |
0 commit comments