naver / kapture

kapture is a file format as well as a set of tools for manipulating datasets, and in particular Visual Localization and Structure from Motion data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exporting matches for bundle import

jo-chemla opened this issue · comments

Hi there,
Context: I'm trying to convert a registration stored in the bundle.out to the colmap format, using kapture as an intermediate format.

When loaded into Colmap GUI (File -> New Project and select database colmap.db and input images folder), the resulting colmap registration shows no 3D points in the colmap viewer. This is probably because the intermediate kapture files store no matches so kapture_data.matches is None.

Each point in the bundle.out file stores this info, where view list stores for that keypoint the number of matches and then for each image, <camera> <key> <x> <y> where key is the index of that keypoint in the image features point, and xy its coordinates.

<position>      [a 3-vector describing the 3D position of the point]
<color>         [a 3-vector describing the RGB color of the point]
<view list>     [a list of views the point is visible in]

It would be great for the kapture_import_bundler.py to also export a match list in kapture parlance, made of all pairs within the dataset. The score could be the number of keypoints found for that pair. Would result in this reconstruction/matches/SIFT sample with overlapping files.

Edit:
What I need is actually simply a file pairsfile-path for the kapture_export_colmap.py to export these matches, and my feeling is that this one can be produced using only the content of the bundle.out, by aggregating a counter for each image pair for each observation - but I'm not sure this is the best thing to do as this list will become exponentially large.

--pairsfile-path PAIRSFILE_PATH: 
text file in the csv format; where each line is image_name1, image_name2, score which contains the matches to

Hi,
In kapture-localization, we have a script that can generate a pairsfile from kapture observations.txt file.
If I understand correctly, that's what you want to do. See https://github.com/naver/kapture-localization/blob/main/tools/kapture_compute_observations_pairs.py

after importing from bundler with option --add-reconstruction into kapture, you should be able to run it.

It's quite costly to do, as you said and very specific so I don't think it should be integrated in the import script. Implementation is at https://github.com/naver/kapture-localization/blob/main/kapture_localization/pairing/observations.py#L199.

commented

Hi,

I did not try your workflow, so my answer is not very specific.
But what I can say, is that colmap.db does not contains 3D points.
https://colmap.github.io/database.html

In the colmap dialect, 3D points are part of the "reconstruction".
The reconstruction is composed of 3 files (either bin or txt)

  • cameras.txt
  • images.txt
  • points3D.txt

https://colmap.github.io/format.html#text-format

To visualize 3D points in colmap, you need to import the directory containing the 3 reconstruction files.
If you really needs matches, I recommend following @yocabon instructions.

I hope it helps.

Hi, thanks both for getting back.

Indeed, I assumed the kapture -> colmap import would also be importing matches for speeding up the subsequent processing within colmap. The kapture_compute_observations_pairs.py is indeed what I need for this, implementation seem to be pretty close to what I had in mind.

And indeed, importing colmap reconstruction folder (with all 3 txt files) via File-Import Model within Colmap GUI shows cameras, images, points3D are correctly imported.

A little suggestion, it could be good if the kapture colmap exporter could export these 3 reconstruction files directly in binary form, cameras.bin, images.bin, points3D.bin. This is supported by the colmap read_write_model.py script, so maybe the kapture/converter/colmap/export_colmap.py could as well implement a binary export (probably within this file).

Note for others looking for an alternative, this can as well be done using colmap CLI:

COLMAP.bat model_converter --input_path dataset-colmap\reconstruction-txt --output_path dataset-colmap\reconstruction-bin --output_type BIN

Thanks again for your help.

Out of curiosity, a quick question: is there a utility in the Kapture toolbelt which would let me crop my images (and update the intrinsics/poses from the kapture files accordingly)? Something which would let me crop say 10px all around, or specify a crop amount for each side. Thanks again!

I don't think there is.

Alright thanks for the answer!

In case anyone wants it, here is a quick utility (written with the kapture python module) to handle just that cropping case, cropping input images of a kapture dataset and editing intrinsics accordingly.
If you want to have a look, that's my first time using the kapture module, if there are things that could be written better, please don't hesitate! Also, I can do a PR to add this to the kapture/tools if this makes sense.

Just made to crop by a fixed border_px, an integer amount given in pixels identical for all 4 sides,

  • updating width -= 2 * border_px, same for height
  • substracting that border_px amount from cx, cy, cx -= border_px
  • and editing focal_length by the f *= new_width/old_width ratio

Edit:
Just updated the kapture-cropper script here to also convert to simpler camera sensor models if distortion coefficients are zero.
If this model_simplify and/or the cropper utilities should also be added to kapture/tools in a PR, please do tell me - they can be considered generic enough to be part of it.
Best,

SENSOR_SIMPLIFICATION_TABLE = {
    kapture.CameraType.SIMPLE_RADIAL: (5, kapture.CameraType.SIMPLE_PINHOLE),
    kapture.CameraType.RADIAL: (5, kapture.CameraType.SIMPLE_PINHOLE),
    kapture.CameraType.OPENCV: (6, kapture.CameraType.PINHOLE),
    kapture.CameraType.FULL_OPENCV: (6, kapture.CameraType.PINHOLE),
}
commented

Just added a ref to the script in the doc: 32eca31
Thanks for the contribution.

Good to know, thanks for the addition! The utility is really simple, does both image cropping (and intrinsics edition of cx focal etc), sensor model simplification (if radial distortion coefficients are zero), and scene coordinates rescaling (points3d and cams). If it needs to go somewhere else in the kapture repo, please don't hesitate to reuse!