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

Exception in triangulation: 'pycolmap._core.Rigid3d' object has no attribute 'essential_matrix' #438

Open
mattiasmar opened this issue Nov 26, 2024 · 3 comments · May be fixed by #446
Open

Comments

@mattiasmar
Copy link

In an Ubuntu 22 docker container with COLMAP, PyColmap and HLOC installed from sources like documented below, in the method:

def compute_epipolar_errors(j_from_i: pycolmap.Rigid3d, p2d_i, p2d_j):
    j_E_i = j_from_i.essential_matrix()  

I get the exception:

Exception has occurred: AttributeError
'pycolmap._core.Rigid3d' object has no attribute 'essential_matrix'
  File "/hloc/Hierarchical-Localization/hloc/utils/geometry.py", line 10, in compute_epipolar_errors
    j_E_i = j_from_i.essential_matrix()
  File "/hloc/Hierarchical-Localization/hloc/triangulation.py", line 174, in geometric_verification
    errors0, errors1 = compute_epipolar_errors(
  File "/hloc/Hierarchical-Localization/hloc/triangulation.py", line 253, in main
    geometric_verification(
  ...
AttributeError: 'pycolmap._core.Rigid3d' object has no attribute 'essential_matrix'

Should I use another version of pycolmap (latest sources brings me pycolmap: 3.11.0, colmap: 3.11.0.dev0, Commit 9da34b21 on 2024-11-26 with CUDA)?
Am I using hloc triangulation incorrectly?

I'm using it like this:

    # Step 3: Perform triangulation using the existing camera poses
    triangulation.main(
        reference_model=reconstruction_path,
        sfm_dir = sfm_path,
        image_dir=Path(output_dir),
        pairs=sfm_pairs,
        features=features_path,
        matches=matches_path,
        verbose = True
    )

where all of those paths point to this folder structure:
image

WORKDIR /colmap
RUN git clone https://github.com/colmap/colmap.git 
RUN . /hloc/venv/bin/activate && cd colmap && mkdir build && cd build && cmake .. -GNinja  && ninja && ninja install
# Install the latest version of pycolmap
RUN . /hloc/venv/bin/activate && pip install ruff pyyaml
RUN . /hloc/venv/bin/activate && cd /colmap/colmap && python3 -m pip install ./pycolmap/

WORKDIR /hloc
RUN git clone --recursive https://github.com/cvg/Hierarchical-Localization/
RUN . /hloc/venv/bin/activate &&  cd Hierarchical-Localization/ && python3 -m pip install --upgrade setuptools && python3 -m pip install --no-build-isolation -e .

In debugger I see that this method fails at the first call and the input arguments are

j_from_i: pycolmap.Rigid3d, rotation_xyzw=[0.118801, -0.399306, 0.0515654, 0.907624], translation=[1.80276, 0.0961467, -2.12249])
p2d_j: <class 'numpy.ndarray'>, shape: (74, 2)
p2d_i: <class 'numpy.ndarray'>, shape: (74, 2)
@mattiasmar
Copy link
Author

@sarlinpe This happens every time I call triangulation.main.

triangulation.main(
              reference_model=initial_sfm_model,
              sfm_dir = sfm_path,
              image_dir=Path(output_dir),
              pairs=sfm_pairs,
              features=features_path,
              matches=matches_path,
              verbose = False,
              skip_geometric_verification = False
          )

@mattiasmar
Copy link
Author

May I suggest replacing the line j_E_i = j_from_i.essential_matrix() in compute_epipolar_errors as follows:

def compute_epipolar_errors(j_from_i: pycolmap.Rigid3d, p2d_i, p2d_j):
    # Extract rotation and translation from j_from_i
    R = j_from_i.rotation.matrix()
    t = j_from_i.translation

    # Compute the essential matrix
    t_e = np.array([
        [0, -t[2], t[1]],
        [t[2], 0, -t[0]],
        [-t[1], t[0], 0]
    ])
    j_E_i = t_e @ R
    ...

@shojint
Copy link

shojint commented Dec 12, 2024

Downgrade pycolmap to 3.10.0

@B1ueber2y B1ueber2y linked a pull request Dec 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants