-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalignMeanShape.m
40 lines (33 loc) · 1.41 KB
/
alignMeanShape.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
function [mean_shape_arr, def_vectors_arr, img_coords_arr] = alignMeanShape(seq, frm, id, label_dir, mean_shape_file, def_vector_file)
% label_dir directory path must be relative to './devkit/matlab' directory
ry_arr = [];
mean_shape_arr = zeros(36, 3, numel(seq));
def_vectors_arr = zeros(42, 108, numel(seq));
K = [
721.53, 0, 609.55;
0, 721.53, 172.85;
0, 0, 1;
];
img_coords_arr = zeros(36, 2, numel(seq));
[B, ~] = mobili(seq, frm, id, label_dir);
offset_angle = pi/2;
tracklet_data = getTracklets(seq, frm, id, label_dir);
ry_arr = [ry_arr; tracklet_data(:, 8) + offset_angle];
init_mean_shape = readmatrix(mean_shape_file);
mean_shape = init_mean_shape;
mean_shape = reorientMeanShape(scaleMeanShape(mean_shape));
def_vectors = reorientDeformationVectors(def_vector_file, init_mean_shape);
for i=1:numel(ry_arr)
rot_matrix = [cos(ry_arr(i)), 0, sin(ry_arr(i)); 0, 1, 0; -sin(ry_arr(i)), 0, cos(ry_arr(i))];
mean_rot = mean_shape * rot_matrix';
mean_trans = mean_rot + B(i, :);
mean_shape_arr(:, :, i) = mean_trans;
def_vectors_rot = zeros(42, 108);
for j=1:3:106
def_vectors_rot(:, j:j+2) = def_vectors(:, j:j+2) * rot_matrix';
end
def_vectors_arr(:, :, i) = def_vectors_rot;
img_coords = mean_trans * K';
img_coords_arr(:, :, i) = [img_coords(:, 1) ./ img_coords(:, 3), img_coords(:, 2) ./ img_coords(:, 3)];
end
end