mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #27992 from asmorkalov:as/HoughLines_bias
Fixed standard HoughLines output shift for rho. #27992 Closes: https://github.com/opencv/opencv/issues/25038 Replaces: https://github.com/opencv/opencv/pull/25043 Merge with https://github.com/opencv/opencv_extra/pull/1288 The original implementation introduces systematic shift (-rho/2) for odd indexes. Integer division just gives proper rounding. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
adaa369bb1
commit
a31a52adef
@@ -228,7 +228,7 @@ HoughLinesStandard( InputArray src, OutputArray lines, int type,
|
||||
int idx = _sort_buf[i];
|
||||
int n = cvFloor(idx*scale) - 1;
|
||||
int r = idx - (n+1)*(numrho+2) - 1;
|
||||
line.rho = (r - (numrho - 1)*0.5f) * rho;
|
||||
line.rho = (r - (numrho - 1)/2) * rho;
|
||||
line.angle = static_cast<float>(min_theta) + n * theta;
|
||||
if (type == CV_32FC2)
|
||||
{
|
||||
|
||||
@@ -162,7 +162,7 @@ __kernel void get_lines(__global uchar * accum_ptr, int accum_step, int accum_of
|
||||
|
||||
if (index < linesMax)
|
||||
{
|
||||
float radius = (x - (accum_cols - 3) * 0.5f) * rho;
|
||||
float radius = (x - (accum_cols - 3) / 2) * rho;
|
||||
float angle = y * theta;
|
||||
|
||||
lines[index] = (float2)(radius, angle);
|
||||
|
||||
@@ -340,6 +340,69 @@ TEST(HoughLines, regression_21983)
|
||||
EXPECT_NEAR(lines[0][1], 1.57179642, 1e-4);
|
||||
}
|
||||
|
||||
TEST(HoughLines, regression_25038_vertical)
|
||||
{
|
||||
cv::Mat img = cv::Mat::zeros(8, 8, CV_8UC1);
|
||||
img.col(3).setTo(255);
|
||||
|
||||
cv::Mat lines;
|
||||
cv::HoughLines(img, lines, 0.5, CV_PI/4., 2);
|
||||
EXPECT_EQ(1, lines.cols);
|
||||
EXPECT_EQ(1, lines.rows);
|
||||
EXPECT_EQ(2, lines.channels());
|
||||
EXPECT_NEAR(3, lines.at<cv::Vec2f>(0)[0], 1e-5);
|
||||
EXPECT_NEAR(0, lines.at<cv::Vec2f>(0)[1], 1e-5);
|
||||
|
||||
cv::HoughLines(img, lines, 0.05, CV_PI/4., 2);
|
||||
EXPECT_EQ(1, lines.cols);
|
||||
EXPECT_EQ(1, lines.rows);
|
||||
EXPECT_EQ(2, lines.channels());
|
||||
EXPECT_NEAR(3, lines.at<cv::Vec2f>(0)[0], 1e-5);
|
||||
EXPECT_NEAR(0, lines.at<cv::Vec2f>(0)[1], 1e-5);
|
||||
}
|
||||
|
||||
TEST(HoughLines, regression_25038_even)
|
||||
{
|
||||
cv::Mat img = cv::Mat::zeros(8, 8, CV_8UC1);
|
||||
img.col(4).setTo(255);
|
||||
|
||||
cv::Mat lines;
|
||||
cv::HoughLines(img, lines, 0.5, CV_PI/4., 2);
|
||||
EXPECT_EQ(1, lines.cols);
|
||||
EXPECT_EQ(1, lines.rows);
|
||||
EXPECT_EQ(2, lines.channels());
|
||||
EXPECT_NEAR(4, lines.at<cv::Vec2f>(0)[0], 1e-5);
|
||||
EXPECT_NEAR(0, lines.at<cv::Vec2f>(0)[1], 1e-5);
|
||||
|
||||
cv::HoughLines(img, lines, 0.05, CV_PI/4., 2);
|
||||
EXPECT_EQ(1, lines.cols);
|
||||
EXPECT_EQ(1, lines.rows);
|
||||
EXPECT_EQ(2, lines.channels());
|
||||
EXPECT_NEAR(4, lines.at<cv::Vec2f>(0)[0], 1e-5);
|
||||
EXPECT_NEAR(0, lines.at<cv::Vec2f>(0)[1], 1e-5);
|
||||
}
|
||||
|
||||
TEST(HoughLines, regression_25038_horizontal)
|
||||
{
|
||||
cv::Mat img = cv::Mat::zeros(8, 8, CV_8UC1);
|
||||
img.row(3).setTo(255);
|
||||
|
||||
cv::Mat lines;
|
||||
cv::HoughLines(img, lines, 0.5, CV_PI/4., 2);
|
||||
EXPECT_EQ(1, lines.cols);
|
||||
EXPECT_EQ(1, lines.rows);
|
||||
EXPECT_EQ(2, lines.channels());
|
||||
EXPECT_NEAR(3, lines.at<cv::Vec2f>(0)[0], 1e-5);
|
||||
EXPECT_NEAR(CV_PI/2., lines.at<cv::Vec2f>(0)[1], 1e-5);
|
||||
|
||||
cv::HoughLines(img, lines, 0.05, CV_PI/4., 2);
|
||||
EXPECT_EQ(1, lines.cols);
|
||||
EXPECT_EQ(1, lines.rows);
|
||||
EXPECT_EQ(2, lines.channels());
|
||||
EXPECT_NEAR(3, lines.at<cv::Vec2f>(0)[0], 1e-5);
|
||||
EXPECT_NEAR(CV_PI/2., lines.at<cv::Vec2f>(0)[1], 1e-5);
|
||||
}
|
||||
|
||||
TEST(WeightedHoughLines, horizontal)
|
||||
{
|
||||
Mat img(25, 25, CV_8UC1, Scalar(0));
|
||||
|
||||
Reference in New Issue
Block a user