Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/machinevisiontoolbox/ImagePointFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,12 @@ def __str__(self) -> str:
"""

if len(self) == 1:
# p1 and p2 are 1D arrays when there is a single match
p1 = np.ravel(self.p1)
p2 = np.ravel(self.p2)
return (
f"{self.status} {self.distance:6.2f}: ({self.p1[0, 0]:.1f},"
f" {self.p1[1, 0]:.1f}) <--> ({self.p2[0, 0]:.1f}, {self.p2[1, 0]:.1f})"
f"{self.status} {self.distance:6.2f}: ({p1[0]:.1f},"
f" {p1[1]:.1f}) <--> ({p2[0]:.1f}, {p2[1]:.1f})"
)
else:
s = f"{len(self)} matches"
Expand Down
13 changes: 6 additions & 7 deletions tests/test_image_point_features_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,16 @@ def solver(p1, p2, method, **kwargs):


class TestFeatureMatchPrinting:
@pytest.mark.xfail(
strict=True,
raises=IndexError,
reason="str() of a one-match object indexes p1[0, 0], but p1 is 1D "
"when there is a single match",
)
def test_one_match(self, fmatch):
s = str(fmatch[1])
assert "(20.0, 25.0) <--> (30.0, 30.0)" in s
assert s == " 1.00: (20.0, 25.0) <--> (30.0, 30.0)"
assert repr(fmatch[1]) == s

def test_one_match_shows_whether_it_is_an_inlier(self, fmatch):
fmatch._inliers = np.array([True, False, True, True])
assert str(fmatch[0]).startswith("+")
assert str(fmatch[1]).startswith("-")

def test_several(self, fmatch):
assert str(fmatch) == "4 matches"

Expand Down
Loading