-
Notifications
You must be signed in to change notification settings - Fork 10
/
optim_MLPnP_GN.m
83 lines (70 loc) · 2.18 KB
/
optim_MLPnP_GN.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
% Steffen Urban email: [email protected]
% Copyright (C) 2016 Steffen Urban
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
% 28.06.2016 Steffen Urban
function [Tout, statistic] = optim_MLPnP_GN(Tinit, points3D, ...
rnull, snull, P, optimFlags)
% homogeneous to minimal
x = [Rodrigues2(Tinit(1:3,1:3))', Tinit(1:3,4)']';
nrL = size(rnull,2);
% redundancy
redundanz = 2*nrL - length(x);
% optim params
epsParam = optimFlags.epsP;
epsFunc = optimFlags.epsF;
% iteration params
cnt = 0;
stop = false;
invKll = P;
while cnt < optimFlags.maxit && stop == 0
[r, J] = residualsAndJacobian(x, rnull, snull, points3D);
% design matrix
N = J.'*invKll*J;
% System matrix
g = J.'*invKll*r;
dx = pinv(N)*g;
if (max(abs(dx)) > 20 || min(abs(dx)) > 1)
break;
end
dl = J*dx(1:end);
if max(abs(dl)) < epsFunc || max(abs(dx(1:end))) < epsParam
x = x-dx;
break;
else
% update parameter vector
x = x-dx;
end
cnt = cnt+1;
end % while loop
% minimal to homogeneous
Tout = [Rodrigues2(x(1:3)) x(4:6)];
% empirical variance factor
resV = r.'*invKll*r;
if redundanz > 0
if redundanz < nrL
s0 = 1;
else
s0 = resV / redundanz;
end
else
s0 = NaN;
end
% variance-covariance matrix
Qxx = pinv(N);
% cofactor matrix of "adjusted observations"
Qldld = J*Qxx*J';
statistic = {resV, r, J, Qxx, s0, Qldld, sqrt(s0.*diag(Qxx))};
end