forked from younahjeon/apple_facestim_generation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaceData_readLog.m
80 lines (67 loc) · 2.23 KB
/
faceData_readLog.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
function faceData = faceData_readLog(textData)
% faceData text file has # of lines = # of frames
% each line has four parts
% (1) camera transform
% (2) face transform
% (3) project transform
% (4) image resolution width x height
% (5) vertices
% (6) blendshapes
% and these parts are separated by ~
% a vertex is x,y,z coordinate separated by :
% One vertex and another are also separated by ~
% blendshapes are separated by ~ and blendshapeLocation and its value are
% separated by :
fid = fopen(textData);
faceData = struct;
a = regexp(textData,'.txt','split');
faceData.ID = a{1};
format long
tline = fgetl(fid);
nVertices = 1220; % Apple specific
nBlendShapes = 52; % Apple specific
i = 1;
while ischar(tline)
b = regexp(tline,'~');
% camera Transform
tline_ct = tline(1:b(1)-1);
c = strrep(strrep(tline_ct,'~',' '),':',' ');
ct = sscanf(c,'%f',[4,4]);
faceData.ct{i} = ct;
% face Transform
tline_ft = tline(b(1)+1:b(2)-1);
c = strrep(strrep(tline_ft,'~',' '),':',' ');
ft = sscanf(c,'%f',[4,4]);
faceData.ft{i} = ft;
% projection matrix
tline_p = tline(b(2)+1:b(3)-1);
c = strrep(strrep(tline_p,'~',' '),':',' ');
ft = sscanf(c,'%f',[4,4]);
faceData.pt{i} = ft;
%imageResolution
tline_w = tline(b(3)+1:b(4)-1);
faceData.imageResolution{i} = zeros(1,2);
width = sscanf(tline_w,'%f');
tline_h = tline(b(4)+1:b(5)-1);
height= sscanf(tline_h, '%f');
faceData.imageResolution{i}(1) = width;
faceData.imageResolution{i}(2) = height;
% vertices data start from 5th ~ and end at 5+nVertices ~
tline_vertices = tline(b(5)+1:b(nVertices+5)-1);
c = strrep(strrep(tline_vertices,'~',' '),':',' ');
vertices = sscanf(c,'%f',[3,nVertices]);
faceData.vertices{i} = vertices';
% blendshape data start from 5+nVertices ~
tline_bs = tline(b(nVertices+5)+1:end);
d = regexp(tline_bs,'[\w.-]+','match');
bsLoc = d(1:2:end)';
faceData.blendshape(:,i) = cellfun(@str2num,d(2:2:end))';
tline = fgetl(fid);
i = i+1;
end
% sort blendshape data
% blendshape data can be different session by session
[bsLoc_sorted,I] = sort(bsLoc);
faceData.blendshape = faceData.blendshape(I,:);
faceData.bsLoc = bsLoc_sorted;
end