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 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/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 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)) diff --git a/hloc/visualization.py b/hloc/visualization.py index 3616c0c1..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: @@ -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: 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