조현아

7_throw_filter_1

1 +
2 +% 맨처음 방향 (frame1) 으로 일괄 orientation normalize
3 +% => 1번프레임이 아니라 프레임들의 중앙값
4 +% 키로 모든방향 normalize
5 +% 노멀라이즈시 최소값 빼는게 아니라 joint1-> 0.5/0.5/0.5로 가도록
6 +% 실험할때 전방향 노멀라이즈도 해봐야겠다..
7 +path_name ='/home/hyuna/Documents/actionGAN_work/7_cleansed_skeleton/';
8 +dinfo=dir('/home/hyuna/Documents/actionGAN_work/7_cleansed_skeleton/*.skeleton');
9 +%txt=fullfile(dir_to_search, '*.skeleton');
10 +%dinfo=dir(txt);
11 +count=[0,0,0];
12 +label=-1;
13 +for d = 1: length(dinfo)
14 + file_name = dinfo(d).name;
15 + % disp(name);
16 +
17 + name = strcat(path_name,file_name(1:20),'.skeleton');
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 + else
28 + continue;
29 + end
30 +
31 + if isempty(bodyinfo) || isempty(bodyinfo(1).bodies())
32 + disp("empty body");
33 + newdir='/home/hyuna/Documents/actionGAN_work/7_emptybody.txt';
34 +
35 + txtfile=fopen(newdir,'a');
36 + fprintf(txtfile, file_name(1:20));
37 + fprintf(txtfile, '\n');
38 + fclose(txtfile);
39 + count(1)=count(1)+1;
40 + continue;
41 + end
42 +
43 +
44 + %initialize
45 + cur_subject_x = zeros(frame_num, 25);
46 + cur_subject_y = zeros(frame_num, 25);
47 + cur_subject_z = zeros(frame_num, 25);
48 +
49 + tot_x = zeros(frame_num,25);
50 + tot_y = zeros(frame_num,25);
51 + tot_z = zeros(frame_num,25);
52 +
53 + joint_5 = zeros(1,3);
54 + joint_9 = zeros(1,3);
55 + joint_1 = zeros(1,3);
56 + joint_3 = zeros(1,3);
57 +
58 +
59 +
60 + %get total joints information
61 + for FN = 1:frame_num
62 +
63 + cur_body = bodyinfo(FN).bodies(1);
64 + joints = cur_body.joints;
65 +
66 + for JN = 1:25
67 + tot_x(FN,JN) = joints(JN).x;
68 + tot_y(FN,JN) = joints(JN).y;
69 + tot_z(FN,JN) = joints(JN).z;
70 + end
71 + end
72 +
73 + %Orientation normalization 1 : in space
74 + %get median values
75 + M_x = median(tot_x);
76 + M_y = median(tot_y);
77 + M_z = median(tot_z);
78 +
79 + %set 3 points for make plane
80 + joint_5 = [M_x(5) M_y(5) M_z(5)];
81 + joint_9 = [M_x(9) M_y(9) M_z(9)];
82 + joint_1 = [M_x(1) M_y(1) M_z(1)];
83 + joint_3 = [M_x(3) M_y(3) M_z(3)];
84 +
85 + %find RIGID TRNASFORMATION matrix
86 + d1 = joint_1 - joint_5;
87 + d2 = joint_1 - joint_9;
88 + n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly
89 + u1 = n1/norm(n1);
90 + u2 = [0 0 1];
91 + cs1 = dot(u1,u2)/norm(u1)*norm(u2);
92 + ss1 = sqrt(1-cs1.^2);
93 + v1 = cross(u1,u2)/norm(cross(u1,u2));
94 +
95 + 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];
96 + 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];
97 + 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];
98 +
99 + %1-3 number tolls to parallel x axis. Rigid transformation on plane surface
100 + %Z axis coords oyler angle transform
101 +
102 + t = joint_3 - joint_1;
103 + d3 = R1(1,:) * t.';
104 + d3(1,2) = R1(2,:) * t.';
105 + d3(1,3) = R1(3,:) * t.';
106 +
107 + u3 = d3(1:2)/norm(d3(1:2));
108 + v3 = [u3(1) -u3(2)];
109 + v3(2,:) = [u3(2) u3(1)];
110 + u4 = [1 0].';
111 +
112 + csss = v3\u4;
113 + cs2 = csss(1);
114 + ss2 = csss(2);
115 +
116 + R2 = [cs2 -ss2 0];
117 + R2(2,:) = [ss2 cs2 0];
118 + R2(3,:) = [0 0 1];
119 +
120 +
121 + %apply rigid transformation
122 + for FN = 1:frame_num
123 + cur_body = bodyinfo(FN).bodies(1);
124 + joints = cur_body.joints;
125 +
126 + for JN = 1:25
127 + a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].';
128 + b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].';
129 + c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].';
130 +
131 + cur_subject_x(FN,JN) = R2(1,:) * [a b c].';
132 + cur_subject_y(FN,JN) = R2(2,:) * [a b c].';
133 + cur_subject_z(FN,JN) = R2(3,:) * [a b c].';
134 +
135 + end
136 + end
137 +
138 + %orientation normalize 2 (with plane surface)
139 + if cur_subject_x(1,4) < cur_subject_x(1,1)
140 + cur_subject_x = 0 - cur_subject_x;
141 + end
142 +
143 + if cur_subject_y(1,9) > cur_subject_y(1,5)
144 + cur_subject_y = 0 - cur_subject_y;
145 + end
146 +
147 + % for save origin subjects before data augment
148 + clear_subject_x = cur_subject_x;
149 + clear_subject_y = cur_subject_y;
150 + clear_subject_z = cur_subject_z;
151 +
152 +
153 + % patch_num*25
154 + % reds(head-spine) shoud be parallel to z
155 + % 4 3 21 2 1
156 + red=[4,3,21,2,1];
157 + max_t=[];
158 +
159 + echo off;
160 + for j = 1: length(red)-1
161 + theta_per_patch=[]
162 + for patch = 1:frame_num
163 + u = [clear_subject_x(patch, red(j+1))-clear_subject_x(patch, red(j)),clear_subject_y(patch, red(j+1))-clear_subject_y(patch, red(j)),clear_subject_z(patch, red(j+1))-clear_subject_z(patch, red(j))];
164 + % v = axis z
165 + v = [0,0,1];
166 + % angle between [vector joint to joint] and [axis z]
167 + theta = atan2(norm(cross(u,v)),dot(u,v));
168 + %if theta > 90
169 + %theta = theta - 90;
170 + %end
171 +
172 + %print all the theta and max of it.
173 + %disp(theta);
174 +
175 + theta_per_patch=[theta_per_patch, theta];
176 + end
177 + % maximum theta for each bones through all the patches
178 + % max_t[4]
179 + max_t = [max_t,max(theta_per_patch)];
180 + clear theta_per_patch;
181 +
182 + end
183 + %disp("max");
184 + %disp(max_t);
185 + % usually 1.6<max angle<=1.8
186 +
187 + if max_t(max_t>1.8) %bad
188 + label=0;
189 + else
190 + label=1;
191 + end
192 +
193 + % green, blue(arms) should be located in almost the same position at the
194 + % beginning and end of motion.
195 + green=[5,6,7,8,23,22];
196 + blue=[9,10,11,12,25,24];
197 +
198 + %print a distance between starting and ending coords
199 + g_distance = []
200 + for j = 1: length(green)
201 + x_=clear_subject_x(1, green(j))-clear_subject_x(frame_num, green(j));
202 + y_=clear_subject_y(1, green(j))-clear_subject_y(frame_num, green(j));
203 + z_=clear_subject_z(1, green(j))-clear_subject_z(frame_num, green(j));
204 + d=sqrt(x_*x_+y_*y_+z_*z_);
205 + g_distance=[g_distance,d];
206 + end
207 + disp(file_name(1:20));
208 + disp(g_distance);
209 +
210 + b_distance = []
211 + for j = 1: length(blue)
212 + x_=clear_subject_x(1, blue(j))-clear_subject_x(frame_num, blue(j));
213 + y_=clear_subject_y(1, blue(j))-clear_subject_y(frame_num, blue(j));
214 + z_=clear_subject_z(1, blue(j))-clear_subject_z(frame_num, blue(j));
215 + d=sqrt(x_*x_+y_*y_+z_*z_);
216 + b_distance=[b_distance,d];
217 + end
218 + disp(b_distance);
219 +
220 + % only use just 2 joints at the tip of arms(hands)
221 + g_end=g_distance(end-1:end);
222 + b_end=b_distance(end-1:end);
223 + if g_end(g_end>0.7) %bad
224 + label=0;
225 + else
226 + label=1;
227 + end
228 +
229 + if b_end(b_end>0.7) %bad
230 + label=0;
231 + else
232 + label=1;
233 + end
234 +
235 +
236 + % save good and bad examples seperately
237 + newdir='';
238 + if label==0 % bad
239 + newdir='/home/hyuna/Documents/actionGAN_work/7_arms_bad.txt';
240 + count(2)=count(2)+1;
241 + else
242 + newdir='/home/hyuna/Documents/actionGAN_work/7_arms_good.txt';
243 + count(3)=count(3)+1;
244 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/7_arms_cleansed_skeleton');
245 + end
246 +
247 + txtfile=fopen(newdir,'a');
248 + fprintf(txtfile, file_name(1:20));
249 + fprintf(txtfile, '\n');
250 + fclose(txtfile);
251 +
252 +
253 +end
254 +
255 +% number of [emptybody, bad, good]
256 +disp(count);
257 +
258 +
259 +
This file is too large to display.
1 +S001C001P007R001A007
2 +S001C002P007R001A007
3 +S001C003P003R002A007
4 +S002C001P008R001A007
5 +S002C001P013R001A007
6 +S002C001P013R002A007
7 +S002C002P008R001A007
8 +S002C002P013R001A007
9 +S002C002P013R002A007
10 +S002C002P014R002A007
11 +S002C003P003R002A007
12 +S002C003P008R001A007
13 +S002C003P012R001A007
14 +S002C003P013R001A007
15 +S002C003P013R002A007
16 +S003C003P017R001A007
17 +S004C001P020R002A007
18 +S004C002P020R001A007
19 +S004C002P020R002A007
20 +S004C003P007R001A007
21 +S005C001P017R002A007
22 +S005C002P017R002A007
23 +S005C003P017R002A007
24 +S006C001P008R001A007
25 +S006C002P017R002A007
26 +S006C003P017R002A007
27 +S007C001P016R001A007
28 +S007C001P016R002A007
29 +S007C001P027R002A007
30 +S007C002P016R001A007
31 +S007C002P016R002A007
32 +S007C003P016R001A007
33 +S008C001P025R002A007
34 +S008C001P035R002A007
35 +S008C002P035R001A007
36 +S008C002P035R002A007
37 +S008C003P035R001A007
38 +S009C001P016R001A007
39 +S009C002P016R001A007
40 +S009C003P016R001A007
41 +S010C001P013R002A007
42 +S010C002P013R002A007
43 +S012C001P037R001A007
44 +S012C001P037R002A007
45 +S012C002P037R001A007
46 +S012C002P037R002A007
47 +S012C003P037R001A007
48 +S012C003P037R002A007
49 +S013C001P007R001A007
50 +S013C001P016R002A007
51 +S013C001P019R001A007
52 +S013C001P037R001A007
53 +S013C001P037R002A007
54 +S013C002P007R001A007
55 +S013C002P019R001A007
56 +S013C002P037R001A007
57 +S013C002P037R002A007
58 +S013C003P007R001A007
59 +S013C003P016R002A007
60 +S013C003P017R001A007
61 +S013C003P018R001A007
62 +S013C003P019R001A007
63 +S013C003P037R001A007
64 +S013C003P037R002A007
65 +S014C001P007R001A007
66 +S014C001P037R002A007
67 +S014C002P007R001A007
68 +S014C002P037R002A007
69 +S014C003P007R001A007
70 +S014C003P008R001A007
71 +S014C003P037R001A007
72 +S014C003P037R002A007
73 +S015C001P007R001A007
74 +S015C001P016R001A007
75 +S015C001P019R001A007
76 +S015C001P019R002A007
77 +S015C001P037R002A007
78 +S015C002P007R002A007
79 +S015C002P016R001A007
80 +S015C002P019R002A007
81 +S015C003P016R001A007
82 +S015C003P016R002A007
83 +S015C003P017R002A007
84 +S015C003P019R002A007
85 +S015C003P037R002A007
86 +S016C001P007R001A007
87 +S016C001P008R001A007
88 +S016C001P019R001A007
89 +S016C001P019R002A007
90 +S016C001P039R002A007
91 +S016C002P019R001A007
92 +S016C002P019R002A007
93 +S016C002P039R001A007
94 +S016C002P039R002A007
95 +S016C002P040R001A007
96 +S016C003P007R002A007
97 +S016C003P019R001A007
98 +S017C001P003R001A007
99 +S017C001P016R001A007
100 +S017C001P016R002A007
101 +S017C001P020R001A007
102 +S017C001P020R002A007
103 +S017C002P003R002A007
104 +S017C002P007R002A007
105 +S017C002P009R001A007
106 +S017C002P009R002A007
107 +S017C002P016R001A007
108 +S017C002P016R002A007
109 +S017C002P020R001A007
110 +S017C002P020R002A007
111 +S017C003P003R002A007
112 +S017C003P009R001A007
113 +S017C003P016R001A007
114 +S017C003P017R002A007
115 +S017C003P020R001A007
This diff is collapsed. Click to expand it.