239 |
jakw |
1 |
% undistortPointsFast2 - Fast undistortion of image points.
|
|
|
2 |
%
|
|
|
3 |
% Performs a single inversion of the distortion model considering radial
|
|
|
4 |
% distortion only.
|
|
|
5 |
%
|
|
|
6 |
% Based on SIUndistortPoints by Morten Hannemose.
|
|
|
7 |
% Adapted to conventions of Matlab CV Toolbox structs.
|
|
|
8 |
|
|
|
9 |
function points = undistortPointsFast(points, cameraParams)
|
|
|
10 |
|
|
|
11 |
assert(size(points,2)==2,'points must be Nx2');
|
|
|
12 |
|
|
|
13 |
pp = cameraParams.PrincipalPoint;
|
|
|
14 |
f = cameraParams.FocalLength;
|
|
|
15 |
ks = cameraParams.RadialDistortion;
|
|
|
16 |
|
|
|
17 |
points(:,1) = (points(:,1)-pp(1));
|
|
|
18 |
points(:,2) = (points(:,2)-pp(2));
|
|
|
19 |
|
|
|
20 |
Rd2 = (points(:,1)/f(1)).^2+(points(:,2)/f(2)).^2;
|
|
|
21 |
l1 = ks(1)*Rd2;
|
|
|
22 |
l2 = ks(2)*Rd2.^2;
|
|
|
23 |
|
|
|
24 |
% Perform 4 Newton steps
|
|
|
25 |
|
|
|
26 |
xn = 1;
|
|
|
27 |
% for i=1:4
|
|
|
28 |
% xn = xn - (xn.^5.*l2+l1.*xn.^3+xn-1)./(5*xn.^4.*l2+3*l1.*xn.^2+1);
|
|
|
29 |
% end
|
|
|
30 |
for i=1:4
|
|
|
31 |
xn = (5-xn.*(4+2*l1.*xn.^2))./(5*((3*l1+5*l2.*xn.^2).*xn.^2+1))+4/5*xn;
|
|
|
32 |
end
|
|
|
33 |
|
|
|
34 |
points(:,1) = points(:,1).*xn+pp(1);
|
|
|
35 |
points(:,2) = points(:,2).*xn+pp(2);
|