Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to the new pycolmap interface #446

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hloc/localize_inloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion hloc/localize_sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 20 additions & 2 deletions hloc/pipelines/7Scenes/create_gt_sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hloc/utils/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions hloc/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading