cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
3.24k stars 600 forks source link

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

Open mattiasmar opened 5 days ago

mattiasmar commented 5 days ago

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)