-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_cali_mat.m
77 lines (67 loc) · 2.39 KB
/
gen_cali_mat.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
camera_res_w = 1000;
camera_res_h = 1000;
%camera_fov_deg_w = 53.1301024;
%camera_fov_deg_h = 53.1301024;
camera_fov_deg_w = 40;
camera_fov_deg_h = 40;
CamRotateXDeg = -25;
CamRotateYDeg = -25;
proj_spacing = 0.36;
proj_num_x = 32;
proj_num_y = 32;
fn = 'calibration_parameters_04.mat';
camera_extrinsic_matrix = [ ...
1, 0, 0, 0; ...
0, 1, 0, 0; ...
0, 0, -1, 13.7374; ...
0, 0, 0, 1
];
CamRotateXRad = deg2rad(CamRotateXDeg);
CamRotateYRad = deg2rad(CamRotateYDeg);
camera_extrinsic_matrix = [ ...
1, 0, 0, 0; ...
0, cos(CamRotateXRad), sin(CamRotateXRad), 0; ...
0, -sin(CamRotateXRad), cos(CamRotateXRad), 0; ...
0, 0, 0, 1 ...
] * camera_extrinsic_matrix;
camera_extrinsic_matrix = [ ...
cos(CamRotateYRad), 0, sin(CamRotateYRad), 0; ...
0, 1, 0, 0; ...
-sin(CamRotateYRad), 0, cos(CamRotateYRad), 0; ...
0, 0, 0, 1 ...
] * camera_extrinsic_matrix;
camera_extrinsic_matrix = inv(camera_extrinsic_matrix);
camera_extrinsic_matrix = camera_extrinsic_matrix(1:3,:);
projector_extrinsic_matrix = [ ...
1, 0, 0, 0; ...
0, 1, 0, 0; ...
0, 0, 1, 0; ...
0, 0, 0, 1
];
projector_extrinsic_matrix = inv(projector_extrinsic_matrix);
projector_extrinsic_matrix = projector_extrinsic_matrix(1:3,:);
camera_w = 2 * tan(camera_fov_deg_w * pi / 360.0);
camera_h = 2 * tan(camera_fov_deg_h * pi / 360.0);
camera_flip_y = [ ...
1, 0, 0; ...
0, -1, 0; ...
0, 0, 1; ...
];
camera_intrinsic_matrix = [ ...
(camera_res_w-1)/camera_w, 0, (camera_res_w+1)*0.5; ...
0, (camera_res_h-1)/camera_h, (camera_res_h+1)*0.5; ...
0, 0, 1 ...
];
camera_intrinsic_matrix = camera_intrinsic_matrix * camera_flip_y;
% intrinsic_matrix converts real coordinate(x,y only) to code
projector_intrinsic_matrix = [ ...
proj_spacing, 0, -(proj_num_x*proj_spacing-1)/2; ...
0, proj_spacing, -(proj_num_x*proj_spacing-1)/2; ...
0, 0, 1 ...
]; % this is code to real coordinate
projector_intrinsic_matrix = inv(projector_intrinsic_matrix);
save(fn, ...
'projector_intrinsic_matrix', ...
'projector_extrinsic_matrix', ...
'camera_intrinsic_matrix', ...
'camera_extrinsic_matrix')