cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
3.24k stars 600 forks source link

How can I generate SfM model? #301

Closed JSP-ywu closed 1 year ago

JSP-ywu commented 1 year ago

Hi! First, I appreciate for your works. I'm just beginner about this field.

I'm currently researching about the effect of noised camera pose on SfM and relocalization. I already made the GT to noised pose on 7scenes. But I can not find the way to generate SfM model with noised GT. The only thing I can find is just pipeline with image input. Is there the camera pose input in that pipeline?

sarlinpe commented 1 year ago

You can easily load the COLMAP model and perturb the camera poses:

https://github.com/cvg/Hierarchical-Localization/blob/73a3cb0f59659306eb6c15c7213137b2196c5ceb/hloc/pipelines/7Scenes/pipeline.py#L38-L38

rec = pycolmap.Reconstruction("path/to/my/reconstruction/")
for image_id, image in reconstruction.images.items():
  rotvec = np.random.randn(3)
  qvec = pycolmap.rotmat_to_qvec(cv2.Rodrigues(rotvec))
  tvec = np.random.randn(3)
  image.qvec, image.tvec = pycolmap.concatenate_poses(qvec, tvec, image.qvec, image.tvec)
rec.write("path/to/new/reconstruction/")

(up to some typos)

JSP-ywu commented 1 year ago

Thank you for kind response! I'll try it :)