diff --git a/src/machinevisiontoolbox/ImagePointFeatures.py b/src/machinevisiontoolbox/ImagePointFeatures.py index b50c3dd0..4a4fd1fa 100644 --- a/src/machinevisiontoolbox/ImagePointFeatures.py +++ b/src/machinevisiontoolbox/ImagePointFeatures.py @@ -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" diff --git a/tests/test_image_point_features_extra.py b/tests/test_image_point_features_extra.py index 50f16a71..5d54446d 100644 --- a/tests/test_image_point_features_extra.py +++ b/tests/test_image_point_features_extra.py @@ -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"