Merge pull request #26988 from DanBmh:opt_undistort

Optimize undistort points #26988

Skips unnecessary rotation with identity matrix if no R or P mats are given.

---------

Co-authored-by: Daniel <daniel@mail.de>
This commit is contained in:
Daniel Bermuth 2025-03-03 15:16:09 +01:00 committed by GitHub
parent a62b78d6e3
commit 8a24d41b54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 8 deletions

View File

@ -478,10 +478,18 @@ void cv::fisheye::undistortPoints( InputArray distorted, OutputArray undistorted
if ((converged || !isEps) && !theta_flipped)
{
Vec2d pu = pw * scale; //undistorted point
Vec2d fi;
// reproject
Vec3d pr = RR * Vec3d(pu[0], pu[1], 1.0); // rotated point optionally multiplied by new camera matrix
Vec2d fi(pr[0]/pr[2], pr[1]/pr[2]); // final
if (!R.empty() || !P.empty())
{
// reproject
Vec3d pr = RR * Vec3d(pu[0], pu[1], 1.0); // rotated point optionally multiplied by new camera matrix
fi = Vec2d(pr[0]/pr[2], pr[1]/pr[2]); // final
}
else
{
fi = pu;
}
if( sdepth == CV_32F )
dstf[i] = fi;

View File

@ -488,11 +488,14 @@ static void cvUndistortPointsInternal( const CvMat* _src, CvMat* _dst, const CvM
}
}
double xx = RR[0][0]*x + RR[0][1]*y + RR[0][2];
double yy = RR[1][0]*x + RR[1][1]*y + RR[1][2];
double ww = 1./(RR[2][0]*x + RR[2][1]*y + RR[2][2]);
x = xx*ww;
y = yy*ww;
if( matR || matP )
{
double xx = RR[0][0]*x + RR[0][1]*y + RR[0][2];
double yy = RR[1][0]*x + RR[1][1]*y + RR[1][2];
double ww = 1./(RR[2][0]*x + RR[2][1]*y + RR[2][2]);
x = xx*ww;
y = yy*ww;
}
if( dtype == CV_32FC2 )
{