From f704001eb7f4a382eb6ba6cf93459b2c3ed9e6cd Mon Sep 17 00:00:00 2001 From: Ghazi-raad Date: Tue, 9 Dec 2025 12:59:24 +0000 Subject: [PATCH] Merge pull request #28120 from Ghazi-raad:test/line-connectivity-26413 Test: Add regression test for LINE_4 vs LINE_8 connectivity #28120 Add test to verify correct behavior of LINE_4 (4-connected) and LINE_8 (8-connected) line drawing. This test ensures: - LINE_4 produces staircase pattern (more pixels) for diagonal lines - LINE_8 produces diagonal steps (fewer pixels) - LINE_4 pixels have only horizontal/vertical neighbors (no diagonal-only) Regression test for issue #26413 where LINE_4 and LINE_8 behaviors were swapped. --- modules/imgproc/test/test_drawing.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index 50c146baad..da984058e3 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -1104,4 +1104,28 @@ TEST(Drawing, contours_filled) } } +// Test for LINE_4 vs LINE_8 connectivity behavior +// Regression test for issue #26413 +TEST(Drawing, line_connectivity_regression_26413) +{ + Mat img4(10, 10, CV_8UC1, Scalar(0)); + Mat img8(10, 10, CV_8UC1, Scalar(0)); + + // Draw a diagonal line from (0,0) to (9,9) + // LINE_4 (4-connected) should produce staircase pattern (no diagonals) + // LINE_8 (8-connected) should produce diagonal steps + line(img4, Point(0, 0), Point(9, 9), Scalar(255), 1, LINE_4); + line(img8, Point(0, 0), Point(9, 9), Scalar(255), 1, LINE_8); + + int count4 = countNonZero(img4); + int count8 = countNonZero(img8); + + // LINE_8 for a 10-pixel diagonal should have exactly 10 pixels + EXPECT_EQ(10, count8) << "LINE_8 diagonal from (0,0) to (9,9) should have 10 pixels"; + + // LINE_4 for a 10-pixel diagonal should have approximately 19 pixels + // (needs both horizontal and vertical steps) + EXPECT_GT(count4, 15) << "LINE_4 diagonal should have significantly more pixels due to staircase"; +} + }} // namespace