cvg / Hierarchical-Localization

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

Fix score reversal issue when matches are reversed #421

Closed Joe-CB closed 2 months ago

Joe-CB commented 2 months ago

Fix score reversal issue when matches are reversed

Issue

In the original implementation, when the matches are reversed (reverse=True), the matches array is flipped, but the corresponding scores array is not. This can cause the scores to mismatch with the reversed matches.

Solution

The proposed change adds a line to flip the scores array in the same way the matches array is flipped when reverse=True.

Code Change


if reverse:
    matches = np.flip(matches, -1)
    scores = np.flip(scores)  # Flip scores to maintain correspondence with matches
sarlinpe commented 2 months ago

matches is an Nx2-dimensional array. Swapping the images requires swapping the last dimension. scores is an N-dimensional array and doesn't need any swapping. We are swapping the order of the images, not of the points.