-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslCalib.m
49 lines (44 loc) · 1.66 KB
/
slCalib.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
% generate the following data
% wPlaneCol, wPlaneRow, Nc, Oc
% load(sprintf('%s/calib_cam_proj.mat', calibDir));
% Determine mapping from projector pixels to optical rays.
% Note: Ideally, the projected images should be pre-warped to
% ensure that projected planes are actually planar.
c = 1:nx_proj;
r = 1:ny_proj;
[C,R] = meshgrid(c,r);
np = pixel2ray([C(:) R(:)]',fc_proj,cc_proj,kc_proj,alpha_c_proj);
np = Rc_1_proj'*(np - Tc_1_proj*ones(1,size(np,2)));
Np = zeros([ny_proj nx_proj 3]);
Np(:,:,1) = reshape(np(1,:),ny_proj,nx_proj);
Np(:,:,2) = reshape(np(2,:),ny_proj,nx_proj);
Np(:,:,3) = reshape(np(3,:),ny_proj,nx_proj);
P = -Rc_1_proj'*Tc_1_proj;
% Estimate plane equations describing every projector column.
% Note: Resulting coefficient vector is in camera coordinates.
wPlaneCol = zeros(nx_proj,4);
for i = 1:nx_proj
wPlaneCol(i,:) = ...
fitPlane([P(1); Np(:,i,1)],[P(2); Np(:,i,2)],[P(3); Np(:,i,3)]);
%figure(4); hold on;
%plot3(Np(:,i,1),Np(:,i,3),-Np(:,i,2),'r-');
%drawnow;
end
% Estimate plane equations describing every projector row.
% Note: Resulting coefficient vector is in camera coordinates.
wPlaneRow = zeros(ny_proj,4);
for i = 1:ny_proj
wPlaneRow(i,:) = ...
fitPlane([P(1) Np(i,:,1)],[P(2) Np(i,:,2)],[P(3) Np(i,:,3)]);
%figure(4); hold on;
%plot3(Np(i,:,1),Np(i,:,3),-Np(i,:,2),'g-');
%drawnow;
end
% Pre-compute optical rays for each camera pixel.
for i = 1:length(fc_cam)
c = 1:nx_cam{i};
r = 1:ny_cam{i};
[C,R] = meshgrid(c,r);
Nc{i} = Rc_1_cam{1}*Rc_1_cam{i}'*pixel2ray([C(:) R(:)]'-1,fc_cam{i},cc_cam{i},kc_cam{i},alpha_c_cam{i});
Oc{i} = Rc_1_cam{1}*Rc_1_cam{i}'*(-Tc_1_cam{i}) + Tc_1_cam{1};
end