diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index c89142c553..440fc0a639 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -1844,6 +1844,7 @@ void line( InputOutputArray _img, Point pt1, Point pt2, const Scalar& color, void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, int thickness, int line_type, int shift, double tipLength) { + CV_Assert( tipLength > 0.0 && tipLength <= 1.0 ); CV_INSTRUMENT_REGION(); const double tipSize = norm(pt1-pt2)*tipLength; // Factor to normalize the size of the tip depending on the length of the arrow diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index e7b8f60de1..7982c5d487 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -1128,4 +1128,23 @@ TEST(Drawing, line_connectivity_regression_26413) EXPECT_GT(count4, 15) << "LINE_4 diagonal should have significantly more pixels due to staircase"; } +//This test ensures that the tipLength geometric ratio is strictly bounded within the logical range (0.0, 1.0]. +TEST(Imgproc_Drawing, arrowedLine_tipLength_validation) +{ + // Create a simple miniature canvas for testing. Added cv:: prefix. + cv::Mat img = cv::Mat::zeros(100, 100, CV_8UC3); + cv::Point pt1(10, 10), pt2(90, 90); + + // 1. Validate legal parameters: should not throw any exceptions (Normal cases) + EXPECT_NO_THROW(cv::arrowedLine(img, pt1, pt2, cv::Scalar(255, 255, 255), 1, 8, 0, 0.1)); + EXPECT_NO_THROW(cv::arrowedLine(img, pt1, pt2, cv::Scalar(255, 255, 255), 1, 8, 0, 1.0)); + + // 2. Validate illegal parameters: expect cv::Exception to be thrown (Boundary violations) + // Negative ratio (tipLength <= 0.0) + EXPECT_THROW(cv::arrowedLine(img, pt1, pt2, cv::Scalar(255, 255, 255), 1, 8, 0, -0.5), cv::Exception); + + // Overflow ratio (tipLength > 1.0) + EXPECT_THROW(cv::arrowedLine(img, pt1, pt2, cv::Scalar(255, 255, 255), 1, 8, 0, 1.5), cv::Exception); +} + }} // namespace