조현아

error siba

1 +clear;
2 +
3 +path_name = '/media/hyuna/F4722E97722E5F1C/21.nturgb+d_skeletons/';
4 +fileID = fopen('/media/hyuna/F4722E97722E5F1C/sk.txt','r');
5 +formatSpec = '%s';
6 +sizeA = [20 Inf];
7 +perfect_list = fscanf(fileID,formatSpec,sizeA);
8 +perfect_list = perfect_list.';
9 +fclose(fileID);
10 +
11 +L = length(perfect_list);
12 +
13 +for K = 1:L
14 +
15 + file_name = char(perfect_list(K,:));
16 + name = strcat(path_name,file_name(1:20),'.skeleton');
17 + disp(name);
18 + [token,remainder] = strtok(file_name,'A');
19 +
20 + class = str2num(remainder(2:4));
21 + %class=remainder(2:4);
22 +
23 + if class == 7
24 + bodyinfo = read_skeleton_file(name);
25 + frame_num = size(bodyinfo,2);
26 +
27 +
28 + try
29 + %initialize
30 + cur_subject_x = zeros(frame_num, 25);
31 + cur_subject_y = zeros(frame_num, 25);
32 + cur_subject_z = zeros(frame_num, 25);
33 +
34 + tot_x = zeros(frame_num,25);
35 + tot_y = zeros(frame_num,25);
36 + tot_z = zeros(frame_num,25);
37 +
38 + joint_5 = zeros(1,3);
39 + joint_9 = zeros(1,3);
40 + joint_1 = zeros(1,3);
41 + joint_3 = zeros(1,3);
42 +
43 + %get total joints information
44 + for FN = 1:frame_num
45 + cur_body = bodyinfo(FN).bodies(1);
46 + joints = cur_body.joints;
47 +
48 + for JN = 1:25
49 + tot_x(FN,JN) = joints(JN).x;
50 + tot_y(FN,JN) = joints(JN).y;
51 + tot_z(FN,JN) = joints(JN).z;
52 + end
53 + end
54 +
55 + %Orientation normalization 1 : in space
56 + %get median values
57 + M_x = median(tot_x);
58 + M_y = median(tot_y);
59 + M_z = median(tot_z);
60 +
61 + %set 3 points for make plane
62 + joint_5 = [M_x(5) M_y(5) M_z(5)];
63 + joint_9 = [M_x(9) M_y(9) M_z(9)];
64 + joint_1 = [M_x(1) M_y(1) M_z(1)];
65 + joint_3 = [M_x(3) M_y(3) M_z(3)];
66 +
67 + %find RIGID TRNASFORMATION matrix
68 + d1 = joint_1 - joint_5;
69 + d2 = joint_1 - joint_9;
70 + n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly
71 + u1 = n1/norm(n1);
72 + u2 = [0 0 1];
73 + cs1 = dot(u1,u2)/norm(u1)*norm(u2);
74 + ss1 = sqrt(1-cs1.^2);
75 + v1 = cross(u1,u2)/norm(cross(u1,u2));
76 +
77 + R1 = [v1(1)*v1(1)*(1-cs1)+cs1 v1(1)*v1(2)*(1-cs1)-v1(3)*ss1 v1(1)*v1(3)*(1-cs1)+v1(2)*ss1];
78 + R1(2,:) = [v1(1)*v1(2)*(1-cs1)+v1(3)*ss1 v1(2)*v1(2)*(1-cs1)+cs1 v1(2)*v1(3)*(1-cs1)-v1(1)*ss1];
79 + R1(3,:) = [v1(1)*v1(3)*(1-cs1)-v1(2)*ss1 v1(2)*v1(3)*(1-cs1)+v1(1)*ss1 v1(3)*v1(3)*(1-cs1)+cs1];
80 +
81 + %1-3 number tolls to parallel x axis. Rigid transformation on plane surface
82 + %Z axis coords oyler angle transform
83 +
84 + t = joint_3 - joint_1;
85 + d3 = R1(1,:) * t.';
86 + d3(1,2) = R1(2,:) * t.';
87 + d3(1,3) = R1(3,:) * t.';
88 +
89 + u3 = d3(1:2)/norm(d3(1:2));
90 + v3 = [u3(1) -u3(2)];
91 + v3(2,:) = [u3(2) u3(1)];
92 + u4 = [1 0].';
93 +
94 + csss = v3\u4;
95 + cs2 = csss(1);
96 + ss2 = csss(2);
97 +
98 + R2 = [cs2 -ss2 0];
99 + R2(2,:) = [ss2 cs2 0];
100 + R2(3,:) = [0 0 1];
101 +
102 +
103 + %apply rigid transformation
104 + for FN = 1:frame_num
105 + cur_body = bodyinfo(FN).bodies(1);
106 + joints = cur_body.joints;
107 +
108 + for JN = 1:25
109 + a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].';
110 + b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].';
111 + c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].';
112 +
113 + cur_subject_x(FN,JN) = R2(1,:) * [a b c].';
114 + cur_subject_y(FN,JN) = R2(2,:) * [a b c].';
115 + cur_subject_z(FN,JN) = R2(3,:) * [a b c].';
116 +
117 + end
118 + end
119 +
120 + %orientation normalize 2 in plane surface
121 + if cur_subject_x(1,4) < cur_subject_x(1,1)
122 + cur_subject_x = 0 - cur_subject_x;
123 + end
124 +
125 + if cur_subject_y(1,9) > cur_subject_y(1,5)
126 + cur_subject_y = 0 - cur_subject_y;
127 + end
128 +
129 + % for save origin subjects before data augment
130 + clear_subject_x = cur_subject_x;
131 + clear_subject_y = cur_subject_y;
132 + clear_subject_z = cur_subject_z;
133 +
134 + % Left <-> Right Change : 2option
135 + for LR = 1:2
136 + if LR == 1
137 + augment_y = clear_subject_y;
138 + else
139 + augment_y = 0 - clear_subject_y;
140 + end
141 +
142 + %Height change : 3option
143 + for HE = 1:3
144 + if HE == 1
145 + augment_x = clear_subject_x.* 1.2;
146 + elseif HE==2
147 + augment_x = clear_subject_x.* 1.0;
148 + else
149 + augment_x = clear_subject_x.* 0.8;
150 + end
151 +
152 + %Give Gaussian Random Variable : 0.01 - 6times
153 + for RV = 1:6
154 + %3. Gaussian Random filter 0.1
155 + cur_subject_x = augment_x + 0.01.*randn(frame_num,25);
156 + cur_subject_y = augment_y + 0.01.*randn(frame_num,25);
157 + cur_subject_z = clear_subject_z + 0.01.*randn(frame_num,25);
158 +
159 + % NORMALIZATION
160 + cur_subject_x = cur_subject_x - min(cur_subject_x(:));
161 + max_tall = max(cur_subject_x(:));
162 + cur_subject_x = cur_subject_x ./ max_tall;
163 +
164 + cur_subject_y = cur_subject_y - min(cur_subject_y(:));
165 + cur_subject_y = cur_subject_y ./ max_tall;
166 +
167 + cur_subject_z = cur_subject_z - min(cur_subject_z(:));
168 + cur_subject_z = cur_subject_z ./ max_tall;
169 +
170 +
171 + %Write image
172 + motionpatch = cur_subject_x;
173 + motionpatch(:,:,2) = cur_subject_y;
174 + motionpatch(:,:,3) = cur_subject_z;
175 +
176 + new_file_name = strcat('/home/hyuna/Documents/actionGAN_work/24/24_kicking',file_name(1:20),'_',num2str(LR),num2str(HE),num2str(RV),'.png');
177 + imwrite(motionpatch,new_file_name);
178 +
179 + end
180 + end
181 + end
182 +
183 + catch
184 + name
185 + end
186 + end
187 +end