cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
2.96k stars 551 forks source link

HLOC camera refinement(poses) of known camera parameters #372

Open ashutoshmishra1014 opened 4 months ago

ashutoshmishra1014 commented 4 months ago

I want to use already known camera parameters(intrinsics+extrinsics) and refine it using HLOC. Could you please guide how to achieve that using the right APIs?

From the documentation it is clear how to specify already known intrinsic and do the refinement during reconstruction but it is not yet clear if one could also specify the extrinsics for each image or not?

It is also not clear how to specify individual intrinsics with the call to reconstruction.main()

sarlinpe commented 4 months ago

If you need to specify both intrinsics and extrinsics, then you can follow the following steps:

  1. Create an empty pycolmap.Reconstruction object with cameras and images but no 3D points.
  2. Run hloc.triangulation starting from this empty reconstruction as reference_model
  3. Optionally run pycolmap.bundle_adjustment to jointly refine the camera parameters and 3D points.
ashutoshmishra1014 commented 4 months ago

Thanks for your response. Where can I find pycolmap documentation to go through the API calls and method signatures?

sarlinpe commented 4 months ago

There is no documentation. Use help(pycolmap) and check examples in the README. Example:

rec = pycolmap.Reconstruction()
camera_id = 1  # increment for each new camera
cam1 = pycolmap.Camera(model='PINHOLE', width=w, height=h, params=params, camera_id=camera_id)
rec.add_camera(cam1)
image_id = 1  # increment for each new image
cam_from_world = pycolmap.Rigid3d(pycolmap.Rotation3d(qvec), tvec)
im1 = pycolmap.Image(image_name, [], cam_from_world, camera_id, image_id)
rec.add_image(im1)
rec.write("path/")
Yizhe-Liu commented 6 days ago

There is no documentation. Use help(pycolmap) and check examples in the README. Example:

rec = pycolmap.Reconstruction()
camera_id = 1  # increment for each new camera
cam1 = pycolmap.Camera(model='PINHOLE', width=w, height=h, params=params, camera_id=camera_id)
rec.add_camera(cam1)
image_id = 1  # increment for each new image
cam_from_world = pycolmap.Rigid3d(pycolmap.Rotation3d(qvec), tvec)
im1 = pycolmap.Image(image_name, [], cam_from_world, camera_id, image_id)
rec.add_image(im1)
rec.write("path/")

That won't work. When we manually add images, they come unregistered, which won't be saved. source

We need to set its registered property to True before adding it to the reconstruction.

im1.registered = True