cvg / Hierarchical-Localization

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

AttributeError: 'pycolmap.Camera' object has no attribute 'id' #393

Open SunJ1025 opened 1 month ago

SunJ1025 commented 1 month ago

Thanks for your Great Work! when I'm trying to use the 7scenes pipline with commond:

python3 -m hloc.pipelines.7Scenes.pipeline --use_dense_depth

The following error occurred:

 File "/home/sun/Documents/feat2map-main/third_party/Hierarchical-Localization/hloc/pipelines/7Scenes/create_gt_sfm.py", line 56, in project_to_image
    p2D = np.stack(pycolmap.Camera(camera._asdict()).world_to_image(p2D_norm))
AttributeError: 'pycolmap.Camera' object has no attribute 'id'

I used pycomap==0.6.0, do you know how to solve it? Thanks in advance.

thuanaislab commented 1 month ago

you can solve this problem by change the way calculating the p2D as follow:

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
    K = np.array([[camera.params[0], 0, camera.params[2]],
                  [0, camera.params[1], camera.params[3]],
                  [0, 0, 1]])
    p2D_homogeneous = p3D[:, :-1] / p3D[:, -1:].clip(min=eps)
    p2D_homogeneous = np.concatenate([p2D_homogeneous, np.ones((p2D_homogeneous.shape[0], 1))], axis=1)
    p2D = p2D_homogeneous @ K.T
    size = np.array([camera.width - pad - 1, camera.height - pad - 1])
    valid = np.all((p2D[:, :2] >= pad) & (p2D[:, :2] <= size), -1)
    valid &= visible
    return p2D[valid, :2], valid