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

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

Open
SunJ1025 opened this issue May 12, 2024 · 1 comment
Open

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

SunJ1025 opened this issue May 12, 2024 · 1 comment

Comments

@SunJ1025
Copy link

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
Copy link

thuanaislab commented Jun 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants