From 9f5155b45673c08c7aed3a2c24117b9048ce32a0 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Thu, 12 Dec 2024 16:51:27 +0100 Subject: [PATCH 1/6] Adapt to the new pycolmap inteface --- hloc/localize_sfm.py | 2 +- hloc/utils/geometry.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hloc/localize_sfm.py b/hloc/localize_sfm.py index 1be6349a..315cf90e 100644 --- a/hloc/localize_sfm.py +++ b/hloc/localize_sfm.py @@ -58,7 +58,7 @@ def __init__(self, reconstruction, config=None): def localize(self, points2D_all, points2D_idxs, points3D_id, query_camera): points2D = points2D_all[points2D_idxs] points3D = [self.reconstruction.points3D[j].xyz for j in points3D_id] - ret = pycolmap.absolute_pose_estimation( + ret = pycolmap.estimate_and_refine_absolute_pose( points2D, points3D, query_camera, diff --git a/hloc/utils/geometry.py b/hloc/utils/geometry.py index 5995cccd..f11729b7 100644 --- a/hloc/utils/geometry.py +++ b/hloc/utils/geometry.py @@ -7,7 +7,7 @@ def to_homogeneous(p): def compute_epipolar_errors(j_from_i: pycolmap.Rigid3d, p2d_i, p2d_j): - j_E_i = j_from_i.essential_matrix() + j_E_i = pycolmap.essential_matrix_from_pose(j_from_i) l2d_j = to_homogeneous(p2d_i) @ j_E_i.T l2d_i = to_homogeneous(p2d_j) @ j_E_i dist = np.abs(np.sum(to_homogeneous(p2d_i) * l2d_i, axis=1)) From fb394633ef8d03b3f07b0beea399b5e21626af31 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Thu, 12 Dec 2024 16:55:05 +0100 Subject: [PATCH 2/6] update --- hloc/localize_inloc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hloc/localize_inloc.py b/hloc/localize_inloc.py index acda7520..d8790b88 100644 --- a/hloc/localize_inloc.py +++ b/hloc/localize_inloc.py @@ -110,7 +110,7 @@ def pose_from_cluster(dataset_dir, q, retrieved, feature_file, match_file, skip= "height": height, "params": [focal_length, cx, cy], } - ret = pycolmap.absolute_pose_estimation(all_mkpq, all_mkp3d, cfg, 48.00) + ret = pycolmap.estimate_and_refine_absolute_pose(all_mkpq, all_mkp3d, cfg, 48.00) ret["cfg"] = cfg return ret, all_mkpq, all_mkpr, all_mkp3d, all_indices, num_matches From 1d14d71fbb053634493cf326a8ad2bf9fbe01789 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Thu, 12 Dec 2024 17:35:39 +0100 Subject: [PATCH 3/6] inliers to inlier_mask --- hloc/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hloc/visualization.py b/hloc/visualization.py index 3616c0c1..c83bffee 100644 --- a/hloc/visualization.py +++ b/hloc/visualization.py @@ -110,7 +110,7 @@ def visualize_loc_from_log( # select the first, largest cluster if the localization failed loc = loc["log_clusters"][loc["best_cluster"] or 0] - inliers = np.array(loc["PnP_ret"]["inliers"]) + inliers = np.array(loc["PnP_ret"]["inlier_mask"]) mkp_q = loc["keypoints_query"] n = len(loc["db"]) if reconstruction is not None: From f91076ba309e2b83b5a2b29a8d656c26e55c1f7d Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Fri, 13 Dec 2024 07:58:43 +0100 Subject: [PATCH 4/6] specify minimum pycolmap version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 609c61fb..8a958217 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ matplotlib plotly scipy h5py -pycolmap>=0.6.0 +pycolmap>=3.11.1 kornia>=0.6.11 gdown lightglue @ git+https://github.com/cvg/LightGlue From dfe106a93264cd168b633b2186c013bcc8403eba Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Mon, 16 Dec 2024 09:28:17 +0100 Subject: [PATCH 5/6] fix long-term broken interface --- hloc/pipelines/7Scenes/create_gt_sfm.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hloc/pipelines/7Scenes/create_gt_sfm.py b/hloc/pipelines/7Scenes/create_gt_sfm.py index 95dfa461..6aa90ab3 100644 --- a/hloc/pipelines/7Scenes/create_gt_sfm.py +++ b/hloc/pipelines/7Scenes/create_gt_sfm.py @@ -11,7 +11,16 @@ def scene_coordinates(p2D, R_w2c, t_w2c, depth, camera): assert len(depth) == len(p2D) - p2D_norm = np.stack(pycolmap.Camera(camera._asdict()).image_to_world(p2D)) + pycolmap_camera = pycolmap.Camera( + { + "camera_id": camera.id, + "model": camera.model, + "width": camera.width, + "height": camera.height, + "params": camera.params, + } + ) + p2D_norm = pycolmap_camera.cam_from_img(p2D) p2D_h = np.concatenate([p2D_norm, np.ones_like(p2D_norm[:, :1])], 1) p3D_c = p2D_h * depth[:, None] p3D_w = (p3D_c - t_w2c) @ R_w2c @@ -52,7 +61,16 @@ def project_to_image(p3D, R, t, camera, eps: float = 1e-4, pad: int = 1): p3D = (p3D @ R.T) + t visible = p3D[:, -1] >= eps # keep points in front of the camera p2D_norm = p3D[:, :-1] / p3D[:, -1:].clip(min=eps) - p2D = np.stack(pycolmap.Camera(camera._asdict()).world_to_image(p2D_norm)) + pycolmap_camera = pycolmap.Camera( + { + "camera_id": camera.id, + "model": camera.model, + "width": camera.width, + "height": camera.height, + "params": camera.params, + } + ) + p2D = pycolmap_camera.img_from_cam(p2D_norm) size = np.array([camera.width - pad - 1, camera.height - pad - 1]) valid = np.all((p2D >= pad) & (p2D <= size), -1) valid &= visible From 13cfc88b37c4401fa5b74895ceba692334914574 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Wed, 25 Dec 2024 22:55:43 +0100 Subject: [PATCH 6/6] reconstruction.reg_image_ids() becomes set rather than list --- hloc/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hloc/visualization.py b/hloc/visualization.py index c83bffee..a8ffd9a3 100644 --- a/hloc/visualization.py +++ b/hloc/visualization.py @@ -17,7 +17,7 @@ def visualize_sfm_2d( reconstruction = pycolmap.Reconstruction(reconstruction) if not selected: - image_ids = reconstruction.reg_image_ids() + image_ids = list(reconstruction.reg_image_ids()) selected = random.Random(seed).sample(image_ids, min(n, len(image_ids))) for i in selected: