summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/fact/factor.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/factor.m50
1 files changed, 50 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m b/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m
new file mode 100755
index 0000000..635c29a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m
@@ -0,0 +1,50 @@
1%
2% Usage:
3%
4% [R,t,S] = factor(W)
5%
6% Function to factor a matrix of input data (W) into the camera
7% rotation matrix (R), translation (t), and the shape matrix (S).
8% Three-dimensional version. Failure of normalization results in
9% empty R and S.
10
11function [R,t,S] = factor(W)
12
13pts = size(W,2);
14t = W*ones(pts,1)/pts;
15W = W - t*ones(1,pts);
16
17% Use SVD to factor W.
18 [a,b,c] = svd(W,0);
19
20smallb = b(1:3,1:3); % Since W is rank 3, b has only three meaningful values
21sqrtb = sqrt(smallb);
22Rhat = a(:,1:3) * sqrtb;
23Shat = sqrtb * c(:,1:3)';
24
25G = findG(Rhat);
26
27if size(G,1) == 0,
28R = [];
29S = [];
30else
31 R = Rhat*G;
32 S = inv(G)*Shat;
33
34 % rotation matrix that aligns the reference frame with the first camera
35 F = size(R,1)/2;
36 R1 = R(1,:);
37 R1 = R1/norm(R1);
38 R2 = R(F+1,:);
39 R2 = R2/norm(R2);
40 R3 = cross(R1,R2);
41 R3 = R3/norm(R3);
42 P = [R1; R2; R3];
43 P = P';
44
45 R = R*P;
46 S = inv(P)*S;
47end
48
49
50