-
Notifications
You must be signed in to change notification settings - Fork 7
/
Compute3D.m
executable file
·90 lines (61 loc) · 2.13 KB
/
Compute3D.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
83
84
85
86
87
88
89
90
function [Xc,Xp] = Compute3D(xc,xp,R,T,fc,fp,cc,cp,kc,kp,alpha_c,alpha_p);
% [Xc,Xp] = Compute3D(xc,xp,R,T,fc,fp,cc,cp,kc,kp,alpha_c,alpha_p);
%
% Reconstruction of the 3D structure of the striped object.
%
% Xc : The 3D coordinates of the points in the camera reference frame
% Xp : The 3D coordinates of the points in the projector reference frame
%
% xc, xp: Camera coordinates and projector coordinates from ComputeStripes
% R,T : rigid motion from camera to projector: Xp = R*Xc + T
% fc,fp : Camera and Projector focal lengths
% cc,cp : Camera and Projector center of projection
% kc,kp : Camera and Projector distortion factors
% alpha_c, alpha_p: skew coefficients for camera and projector
%
% The set R,T,fc,fp,cc,cp and kc comes from the calibration.
% Intel Corporation - Dec. 2003
% (c) Jean-Yves Bouguet
if nargin < 12,
alpha_p = 0;
if nargin < 11,
alpha_c = 0;
end;
end;
Np = size(xc,2);
xc = normalize_pixel(xc,fc,cc,kc,alpha_c);
xp = (xp - cp(1))/fp(1);
xp_save = xp; % save the real distorted x - coordinates + alpha'ed
if (norm(kp) == 0)&(alpha_p == 0),
N_rep = 1;
else
N_rep = 5;
end;
% xp is the first entry of the undistorted projector coordinates (iteratively refined)
% xc is the complete undistorted camera coordinates
for kk = 1:N_rep,
R2 = R([1 3],:);
if length(T) > 2,
Tp = T([1 3]); % The old technique for calibration
else
Tp = T; % The new technique for calibration (using stripes only)
end;
% Triangulation:
D1 = [-xc(1,:);xc(1,:).*xp(1,:);-xc(2,:);xc(2,:).*xp(1,:);-ones(1,Np);xp(1,:)];
D2 = R2(:)*ones(1,Np);
D = sum(D1.*D2);
N1 = [-ones(1,Np);xp(1,:)];
N2 = -sum(N1.*(Tp*ones(1,Np)));
Z = N2./D;
Xc = (ones(3,1)*Z).*[xc;ones(1,Np)];
% reproject on the projetor view, and apply distortion...
Xp = R*Xc + T*ones(1,Np);
xp_v = [Xp(1,:)./Xp(3,:); Xp(2,:)./Xp(3,:)];
xp_v(1,:) = xp_v(1,:) + alpha_p * xp_v(2,:);
xp_dist = apply_distortion(xp_v,kp);
%norm(xp_dist(1,:) - xp_save)
xp_dist(1,:) = xp_save;
xp_v = comp_distortion(xp_dist,kp);
xp_v(1,:) = xp_v(1,:) - alpha_p * xp_v(2,:);
xp = xp_v(1,:);
end;