diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 8db6cc5d8d4c5649c18bb2ff0f28f87893711435..c669f2cdef97c400907a07d127b38d98fe88dec0 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -2086,12 +2086,12 @@ The function finds lines in a set of points using a modification of the Hough tr @param point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. @param lines Output vector of found lines. Each vector is encoded as a vector \f$(votes, rho, theta)\f$. The larger the value of 'votes', the higher the reliability of the Hough line. -@param lines_max Max count of hough lines. +@param lines_max Max count of Hough lines. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough -votes ( \f$>\texttt{threshold}\f$ ) -@param min_rho Minimum Distance value of the accumulator in pixels. -@param max_rho Maximum Distance value of the accumulator in pixels. -@param rho_step Distance resolution of the accumulator in pixels. +votes ( \f$>\texttt{threshold}\f$ ). +@param min_rho Minimum value for \f$\rho\f$ for the accumulator (Note: \f$\rho\f$ can be negative. The absolute value \f$|\rho|\f$ is the distance of a line to the origin.). +@param max_rho Maximum value for \f$\rho\f$ for the accumulator. +@param rho_step Distance resolution of the accumulator. @param min_theta Minimum angle value of the accumulator in radians. @param max_theta Maximum angle value of the accumulator in radians. @param theta_step Angle resolution of the accumulator in radians. diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index b48b7ea13723e99714bf65fa1422aa966758b66e..9ed6cc5c5710a3250c64c721aa3fd51eb4d36777 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -975,7 +975,9 @@ void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, i for(int n = 0; n < numangle; n++ ) { int r = cvRound( point.at(i).x * tabCos[n] + point.at(i).y * tabSin[n] - irho_min); - accum[(n+1) * (numrho+2) + r+1]++; + if ( r >= 0 && r <= numrho) { + accum[(n+1) * (numrho+2) + r+1]++; + } } // stage 2. find local maximums diff --git a/modules/imgproc/test/test_houghlines.cpp b/modules/imgproc/test/test_houghlines.cpp index fca0449b91ad4f508de94819dccf52d6a6187860..e90891274ab58401332ca92dbd26545eb88b7e4d 100644 --- a/modules/imgproc/test/test_houghlines.cpp +++ b/modules/imgproc/test/test_houghlines.cpp @@ -299,6 +299,36 @@ TEST_P(HoughLinesPointSetTest, regression) run_test(); } +TEST(HoughLinesPointSet, regression_21029) +{ + std::vector points; + points.push_back(Point2f(100, 100)); + points.push_back(Point2f(1000, 1000)); + points.push_back(Point2f(10000, 10000)); + points.push_back(Point2f(100000, 100000)); + + double rhoMin = 0; + double rhoMax = 10; + double rhoStep = 0.1; + + double thetaMin = 85 * CV_PI / 180.0; + double thetaMax = 95 * CV_PI / 180.0; + double thetaStep = 1 * CV_PI / 180.0; + + int lines_max = 5; + int threshold = 100; + + Mat lines; + + HoughLinesPointSet(points, lines, + lines_max, threshold, + rhoMin, rhoMax, rhoStep, + thetaMin, thetaMax, thetaStep + ); + + EXPECT_TRUE(lines.empty()); +} + INSTANTIATE_TEST_CASE_P( ImgProc, StandartHoughLinesTest, testing::Combine(testing::Values( "shared/pic5.png", "../stitching/a1.png" ), testing::Values( 1, 10 ), testing::Values( 0.05, 0.1 ),