From e38904f7617c94cae02ff60a450a7b23dc9dbae9 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Sun, 22 Nov 2026 21:20:30 +1000 Subject: [PATCH] fix: draw the orientation hand of a feature in its direction BaseFeature2D.draw(filled=True, hand=True) passed (centre_u, circum_u) and (centre_v, circum_v) to draw_line as its start and end points. That is the convention of Matplotlib's Line2D, which plot() correctly uses, but draw_line takes the two end points, so the hand was a line from (centre_u, circum_u) to (centre_v, circum_v) whatever the orientation. It now passes the centre and the circumference point. The xfail test that recorded the bug is now an ordinary test, and a second test checks a quarter turn. Co-Authored-By: Claude Sonnet 5.5 --- .../ImagePointFeatures.py | 4 ++-- tests/test_image_point_features_extra.py | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/machinevisiontoolbox/ImagePointFeatures.py b/src/machinevisiontoolbox/ImagePointFeatures.py index b50c3dd0..38cd72ab 100644 --- a/src/machinevisiontoolbox/ImagePointFeatures.py +++ b/src/machinevisiontoolbox/ImagePointFeatures.py @@ -1230,8 +1230,8 @@ def draw( ) draw_line( img, - (centre[0], circum[0]), - (centre[1], circum[1]), + centre, + circum, color=handcolor, thickness=handthickness, ) diff --git a/tests/test_image_point_features_extra.py b/tests/test_image_point_features_extra.py index 50f16a71..f3b8537f 100644 --- a/tests/test_image_point_features_extra.py +++ b/tests/test_image_point_features_extra.py @@ -610,17 +610,26 @@ def test_draw_filled_circle(self, canvas, one): assert xs.min() >= 28 and xs.max() <= 52 assert ys.min() >= 28 and ys.max() <= 52 - @pytest.mark.xfail( - strict=True, - reason="draw() passes the x pair and the y pair to draw_line as the " - "start and end points, so the hand is vertical, not along the orientation", - ) def test_draw_hand_points_along_the_orientation(self, canvas, one): one.draw(canvas, filled=True, hand=True, color="r", handcolor="g") ys, xs = np.nonzero(canvas.array[:, :, 1] > 0) - # orientation 0 is along +u, so a horizontal line on row 40 + # orientation 0 is along +u, so a horizontal line on row 40, from the + # centre (40, 40) to the circumference at (50, 40) assert (ys == 40).all() - assert xs.min() >= 40 and xs.max() <= 50 + assert xs.min() == 40 and xs.max() == 50 + + def test_draw_hand_follows_a_quarter_turn(self, canvas): + # orientation 90 degrees is along +v: a vertical line down column 40 + f = SIFTFeature( + [cv2.KeyPoint(40.0, 40.0, 10.0, 90.0, 0.5, 0, 0)], + np.zeros((1, 4), dtype=np.float32), + scale=True, + orient=True, + ) + f.draw(canvas, filled=True, hand=True, color="r", handcolor="g") + ys, xs = np.nonzero(canvas.array[:, :, 1] > 0) + assert (xs == 40).all() + assert ys.min() == 40 and ys.max() == 50 def test_draw_hand_is_drawn(self, canvas, one): one.draw(canvas, filled=True, hand=True, color="r", handcolor="g")