cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
3.1k stars 574 forks source link

Localizing Query and saving its output in bin files #227

Open thealchemist-x opened 2 years ago

thealchemist-x commented 2 years ago

Hi,

Thanks for the support this community has provided. I would like to ask, when I use localize_sfm.main() to find my query within a mapping dataset, how can I save the outputs in a format that can be accessed by colmap-gui? I would like this so that I can visualize the matching results and their correspondences between the query and mapping images.

I would like to generate the files (points3D.bin, images.bin, cameras.bin, database.db) with localize_sfm.main() in the same way as triangulation.main()and reconstruction.main() does for us.

Thanks for your guidance!~

sarlinpe commented 2 years ago

You can read the output text file and create a COLMAP model from scratch using pycolmap:

rec = pycolmap.Reconstruction()
camera_id = 1
cam1 = pycolmap.Camera(model_name, w, h, params, camera_id)
rec.add_camera(cam1)
im1 = pycolmap.Image(image_name, [], tvec, qvec, camera_id, id=1)
rec.add_image(im1)
rec.write("path/")

This could be a useful feature - feel free to open a PR for it.