fix getUndistortRectangles to ignore corners

This commit is contained in:
Nishida Daishiro 2025-05-28 18:23:47 +09:00
parent 344f8c6400
commit a63ebb3dd1

View File

@ -1527,7 +1527,7 @@ void cv::getUndistortRectangles(InputArray _cameraMatrix, InputArray _distCoeffs
{
const int N = 9;
int x, y, k;
Mat _pts(1, 4*(N-1), CV_64FC2);
Mat _pts(1, 4*(N-2), CV_64FC2);
Point2d* pts = _pts.ptr<Point2d>();
// generate a grid of points across the image to estimate the distortion deformation
@ -1543,6 +1543,12 @@ void cv::getUndistortRectangles(InputArray _cameraMatrix, InputArray _distCoeffs
// have no influence on the two deformation rectangles that are calculated below
continue;
}
if ((x == 0 || x == N - 1) && (y == 0 || y == N - 1))
{
// skip corners, because undistortPoints is likely to fail and return the same
// value
continue;
}
pts[k++] = Point2d(x * stepX, y * stepY);
}
}
@ -1561,6 +1567,10 @@ void cv::getUndistortRectangles(InputArray _cameraMatrix, InputArray _distCoeffs
{
continue;
}
if ((x == 0 || x == N - 1) && (y == 0 || y == N - 1))
{
continue;
}
Point2d p = pts[k++];
oX0 = MIN(oX0, p.x);