JeungEunLee

motionpatches : orientation/tall nomalized with median value

No preview for this file type
1 +function bodyinfo = read_skeleton_file(filename)
2 +% Reads an .skeleton file from "NTU RGB+D 3D Action Recognition Dataset".
3 +%
4 +% Argrument:
5 +% filename: full adress and filename of the .skeleton file.
6 +%
7 +% For further information please refer to:
8 +% NTU RGB+D dataset's webpage:
9 +% http://rose1.ntu.edu.sg/Datasets/actionRecognition.asp
10 +% NTU RGB+D dataset's github page:
11 +% https://github.com/shahroudy/NTURGB-D
12 +% CVPR 2016 paper:
13 +% Amir Shahroudy, Jun Liu, Tian-Tsong Ng, and Gang Wang,
14 +% "NTU RGB+D: A Large Scale Dataset for 3D Human Activity Analysis",
15 +% in IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016
16 +%
17 +% For more details about the provided data, please refer to:
18 +% https://msdn.microsoft.com/en-us/library/dn799271.aspx
19 +% https://msdn.microsoft.com/en-us/library/dn782037.aspx
20 +
21 +fileid = fopen(filename);
22 +framecount = fscanf(fileid,'%d',1); % no of the recorded frames
23 +
24 +bodyinfo=[]; % to store multiple skeletons per frame
25 +
26 +for f=1:framecount
27 + bodycount = fscanf(fileid,'%d',1); % no of observerd skeletons in current frame
28 + for b=1:bodycount
29 + clear body;
30 + body.bodyID = fscanf(fileid,'%ld',1); % tracking id of the skeleton
31 + arrayint = fscanf(fileid,'%d',6); % read 6 integers
32 + body.clipedEdges = arrayint(1);
33 + body.handLeftConfidence = arrayint(2);
34 + body.handLeftState = arrayint(3);
35 + body.handRightConfidence = arrayint(4);
36 + body.handRightState = arrayint(5);
37 + body.isResticted = arrayint(6);
38 + lean = fscanf(fileid,'%f',2);
39 + body.leanX = lean(1);
40 + body.leanY = lean(2);
41 + body.trackingState = fscanf(fileid,'%d',1);
42 +
43 + body.jointCount = fscanf(fileid,'%d',1); % no of joints (25)
44 + joints=[];
45 + for j=1:body.jointCount
46 + jointinfo = fscanf(fileid,'%f',11);
47 + joint=[];
48 +
49 + % 3D location of the joint j
50 + joint.x = jointinfo(1);
51 + joint.y = jointinfo(2);
52 + joint.z = jointinfo(3);
53 +
54 + % 2D location of the joint j in corresponding depth/IR frame
55 + joint.depthX = jointinfo(4);
56 + joint.depthY = jointinfo(5);
57 +
58 + % 2D location of the joint j in corresponding RGB frame
59 + joint.colorX = jointinfo(6);
60 + joint.colorY = jointinfo(7);
61 +
62 + % The orientation of the joint j
63 + joint.orientationW = jointinfo(8);
64 + joint.orientationX = jointinfo(9);
65 + joint.orientationY = jointinfo(10);
66 + joint.orientationZ = jointinfo(11);
67 +
68 + % The tracking state of the joint j
69 + joint.trackingState = fscanf(fileid,'%d',1);
70 +
71 + body.joints(j)=joint;
72 + end
73 + bodyinfo(f).bodies(b)=body;
74 + end
75 +end
76 +fclose(fileid);
77 +end
...\ No newline at end of file ...\ No newline at end of file
1 +S001C002P005R002A008
2 +S001C002P006R001A008
3 +S001C003P002R001A055
4 +S001C003P002R002A012
5 +S001C003P005R002A004
6 +S001C003P005R002A005
7 +S001C003P005R002A006
8 +S001C003P006R002A008
9 +S002C002P011R002A030
10 +S002C003P008R001A020
11 +S002C003P010R002A010
12 +S002C003P011R002A007
13 +S002C003P011R002A011
14 +S002C003P014R002A007
15 +S003C001P019R001A055
16 +S003C002P002R002A055
17 +S003C002P018R002A055
18 +S003C003P002R001A055
19 +S003C003P016R001A055
20 +S003C003P018R002A024
21 +S004C002P003R001A013
22 +S004C002P008R001A009
23 +S004C002P020R001A003
24 +S004C002P020R001A004
25 +S004C002P020R001A012
26 +S004C002P020R001A020
27 +S004C002P020R001A021
28 +S004C002P020R001A036
29 +S005C002P004R001A001
30 +S005C002P004R001A003
31 +S005C002P010R001A016
32 +S005C002P010R001A017
33 +S005C002P010R001A048
34 +S005C002P010R001A049
35 +S005C002P016R001A009
36 +S005C002P016R001A010
37 +S005C002P018R001A003
38 +S005C002P018R001A028
39 +S005C002P018R001A029
40 +S005C003P016R002A009
41 +S005C003P018R002A013
42 +S005C003P021R002A057
43 +S006C001P001R002A055
44 +S006C002P007R001A005
45 +S006C002P007R001A006
46 +S006C002P016R001A043
47 +S006C002P016R001A051
48 +S006C002P016R001A052
49 +S006C002P022R001A012
50 +S006C002P023R001A020
51 +S006C002P023R001A021
52 +S006C002P023R001A022
53 +S006C002P023R001A023
54 +S006C002P024R001A018
55 +S006C002P024R001A019
56 +S006C003P001R002A013
57 +S006C003P007R002A009
58 +S006C003P007R002A010
59 +S006C003P007R002A025
60 +S006C003P016R001A060
61 +S006C003P017R001A055
62 +S006C003P017R002A013
63 +S006C003P017R002A014
64 +S006C003P017R002A015
65 +S006C003P022R002A013
66 +S007C001P018R002A050
67 +S007C001P025R002A051
68 +S007C001P028R001A050
69 +S007C001P028R001A051
70 +S007C001P028R001A052
71 +S007C002P008R002A008
72 +S007C002P015R002A055
73 +S007C002P026R001A008
74 +S007C002P026R001A009
75 +S007C002P026R001A010
76 +S007C002P026R001A011
77 +S007C002P026R001A012
78 +S007C002P026R001A050
79 +S007C002P027R001A011
80 +S007C002P027R001A013
81 +S007C002P028R002A055
82 +S007C003P007R001A002
83 +S007C003P007R001A004
84 +S007C003P019R001A060
85 +S007C003P027R002A001
86 +S007C003P027R002A002
87 +S007C003P027R002A003
88 +S007C003P027R002A004
89 +S007C003P027R002A005
90 +S007C003P027R002A006
91 +S007C003P027R002A007
92 +S007C003P027R002A008
93 +S007C003P027R002A009
94 +S007C003P027R002A010
95 +S007C003P027R002A011
96 +S007C003P027R002A012
97 +S007C003P027R002A013
98 +S008C002P001R001A009
99 +S008C002P001R001A010
100 +S008C002P001R001A014
101 +S008C002P001R001A015
102 +S008C002P001R001A016
103 +S008C002P001R001A018
104 +S008C002P001R001A019
105 +S008C002P008R002A059
106 +S008C002P025R001A060
107 +S008C002P029R001A004
108 +S008C002P031R001A005
109 +S008C002P031R001A006
110 +S008C002P032R001A018
111 +S008C002P034R001A018
112 +S008C002P034R001A019
113 +S008C002P035R001A059
114 +S008C002P035R002A002
115 +S008C002P035R002A005
116 +S008C003P007R001A009
117 +S008C003P007R001A016
118 +S008C003P007R001A017
119 +S008C003P007R001A018
120 +S008C003P007R001A019
121 +S008C003P007R001A020
122 +S008C003P007R001A021
123 +S008C003P007R001A022
124 +S008C003P007R001A023
125 +S008C003P007R001A025
126 +S008C003P007R001A026
127 +S008C003P007R001A028
128 +S008C003P007R001A029
129 +S008C003P007R002A003
130 +S008C003P008R002A050
131 +S008C003P025R002A002
132 +S008C003P025R002A011
133 +S008C003P025R002A012
134 +S008C003P025R002A016
135 +S008C003P025R002A020
136 +S008C003P025R002A022
137 +S008C003P025R002A023
138 +S008C003P025R002A030
139 +S008C003P025R002A031
140 +S008C003P025R002A032
141 +S008C003P025R002A033
142 +S008C003P025R002A049
143 +S008C003P025R002A060
144 +S008C003P031R001A001
145 +S008C003P031R002A004
146 +S008C003P031R002A014
147 +S008C003P031R002A015
148 +S008C003P031R002A016
149 +S008C003P031R002A017
150 +S008C003P032R002A013
151 +S008C003P033R002A001
152 +S008C003P033R002A011
153 +S008C003P033R002A012
154 +S008C003P034R002A001
155 +S008C003P034R002A012
156 +S008C003P034R002A022
157 +S008C003P034R002A023
158 +S008C003P034R002A024
159 +S008C003P034R002A044
160 +S008C003P034R002A045
161 +S008C003P035R002A016
162 +S008C003P035R002A017
163 +S008C003P035R002A018
164 +S008C003P035R002A019
165 +S008C003P035R002A020
166 +S008C003P035R002A021
167 +S009C002P007R001A001
168 +S009C002P007R001A003
169 +S009C002P007R001A014
170 +S009C002P008R001A014
171 +S009C002P015R002A050
172 +S009C002P016R001A002
173 +S009C002P017R001A028
174 +S009C002P017R001A029
175 +S009C003P017R002A030
176 +S009C003P025R002A054
177 +S010C001P007R002A020
178 +S010C002P016R002A055
179 +S010C002P017R001A005
180 +S010C002P017R001A018
181 +S010C002P017R001A019
182 +S010C002P019R001A001
183 +S010C002P025R001A012
184 +S010C003P007R002A043
185 +S010C003P008R002A003
186 +S010C003P016R001A055
187 +S010C003P017R002A055
188 +S011C001P002R001A008
189 +S011C001P018R002A050
190 +S011C002P008R002A059
191 +S011C002P016R002A055
192 +S011C002P017R001A020
193 +S011C002P017R001A021
194 +S011C002P018R002A055
195 +S011C002P027R001A009
196 +S011C002P027R001A010
197 +S011C002P027R001A037
198 +S011C003P001R001A055
199 +S011C003P002R001A055
200 +S011C003P008R002A012
201 +S011C003P015R001A055
202 +S011C003P016R001A055
203 +S011C003P019R001A055
204 +S011C003P025R001A055
205 +S011C003P028R002A055
206 +S012C001P019R001A060
207 +S012C001P019R002A060
208 +S012C002P015R001A055
209 +S012C002P017R002A012
210 +S012C002P025R001A060
211 +S012C003P008R001A057
212 +S012C003P015R001A055
213 +S012C003P015R002A055
214 +S012C003P016R001A055
215 +S012C003P017R002A055
216 +S012C003P018R001A055
217 +S012C003P018R001A057
218 +S012C003P019R002A011
219 +S012C003P019R002A012
220 +S012C003P025R001A055
221 +S012C003P027R001A055
222 +S012C003P027R002A009
223 +S012C003P028R001A035
224 +S012C003P028R002A055
225 +S013C001P015R001A054
226 +S013C001P017R002A054
227 +S013C001P018R001A016
228 +S013C001P028R001A040
229 +S013C002P015R001A054
230 +S013C002P017R002A054
231 +S013C002P028R001A040
232 +S013C003P008R002A059
233 +S013C003P015R001A054
234 +S013C003P017R002A054
235 +S013C003P025R002A022
236 +S013C003P027R001A055
237 +S013C003P028R001A040
238 +S014C001P027R002A040
239 +S014C002P015R001A003
240 +S014C002P019R001A029
241 +S014C002P025R002A059
242 +S014C002P027R002A040
243 +S014C002P039R001A050
244 +S014C003P007R002A059
245 +S014C003P015R002A055
246 +S014C003P019R002A055
247 +S014C003P025R001A048
248 +S014C003P027R002A040
249 +S015C001P008R002A040
250 +S015C001P016R001A055
251 +S015C001P017R001A055
252 +S015C001P017R002A055
253 +S015C002P007R001A059
254 +S015C002P008R001A003
255 +S015C002P008R001A004
256 +S015C002P008R002A040
257 +S015C002P015R001A002
258 +S015C002P016R001A001
259 +S015C002P016R002A055
260 +S015C003P008R002A007
261 +S015C003P008R002A011
262 +S015C003P008R002A012
263 +S015C003P008R002A028
264 +S015C003P008R002A040
265 +S015C003P025R002A012
266 +S015C003P025R002A017
267 +S015C003P025R002A020
268 +S015C003P025R002A021
269 +S015C003P025R002A030
270 +S015C003P025R002A033
271 +S015C003P025R002A034
272 +S015C003P025R002A036
273 +S015C003P025R002A037
274 +S015C003P025R002A044
275 +S016C001P019R002A040
276 +S016C001P025R001A011
277 +S016C001P025R001A012
278 +S016C001P025R001A060
279 +S016C001P040R001A055
280 +S016C001P040R002A055
281 +S016C002P008R001A011
282 +S016C002P019R002A040
283 +S016C002P025R002A012
284 +S016C003P008R001A011
285 +S016C003P008R002A002
286 +S016C003P008R002A003
287 +S016C003P008R002A004
288 +S016C003P008R002A006
289 +S016C003P008R002A009
290 +S016C003P019R002A040
291 +S016C003P039R002A016
292 +S017C001P016R002A031
293 +S017C002P007R001A013
294 +S017C002P008R001A009
295 +S017C002P015R001A042
296 +S017C002P016R002A031
297 +S017C002P016R002A055
298 +S017C003P007R002A013
299 +S017C003P008R001A059
300 +S017C003P016R002A031
301 +S017C003P017R001A055
302 +S017C003P020R001A059
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +%your motion_patch location
3 +ori = imread('/home/rfj/바탕화면/actionGAN/motion_patch/S001C001P001R001A020.png');
4 +ori = im2double(ori);
5 +ori = ori(:,:,:);
6 +
7 +dx = [];
8 +dy = [];
9 +dz = [];
10 +
11 +for f = 1:numel(ori(:,1,1))
12 + for j = 1:25
13 + dx = [dx;ori(f,j,1)];
14 + dy = [dy;ori(f,j,2)];
15 + dz = [dz;ori(f,j,3)];
16 + end
17 +end
18 +
19 +a = [1 0 0]; % Red 척추 1,2,3,4,20
20 +b = [0 0 1]; % Blue 오른팔 8,9,10,11,23,24
21 +c = [0 1 0]; % Green왼팔 5,6,7,21,22 (여기서 5번이 빠짐. 넣고싶으면 나중에 24 joint가 아니라 25 joint로 추가)
22 +d = [1 1 0]; % Yellow 오른다리 16,17,18,19
23 +e = [0 1 1]; % Skyblue 왼다리 12,13,14,15
24 +colors = [a;a;a;a;c;c;c;c;b;b;b;b;e;e;e;e;d;d;d;d;a;c;c;b;b];
25 +
26 +scatter3(dx,dy,dz,100,'filled');
27 +
28 +
29 +connecting_joints= ...
30 + [2 1 21 3 21 5 6 7 21 9 10 11 1 13 14 15 1 17 18 19 2 8 8 12 12];
31 +
32 +for jj=1:25:numel(dx)% 1부터 8개씩 numel = 열갯수..?
33 + current = [];
34 + current(:,1) = dy(jj:jj+24) ;
35 + current(:,2) = dz(jj:jj+24) ;
36 + current(:,3) = dx(jj:jj+24) ;
37 +
38 + scatter3(current(:,1),current(:,2),current(:,3),100,colors(:,:),'filled');
39 +
40 + for j =1:25
41 + k=connecting_joints(j);
42 + line([current(j,1) current(k,1)], [current(j,2) current(k,2)] , [current(j,3) current(k,3)])
43 + end
44 +
45 + set(gca,'Xdir','reverse','Ydir','reverse')
46 + xlim([0 1]);
47 + xlabel('x')
48 + ylim([0 1]);
49 + ylabel('y')
50 + zlim([0 1]);
51 + zlabel('z')
52 + drawnow
53 + pause(0.01)
54 +end
1 +
2 +% 맨처음 방향 (frame1) 으로 일괄 orientation normalize
3 +% => 1번프레임이 아니라 프레임들의 중앙값
4 +% 키로 모든방향 normalize
5 +% 노멀라이즈시 최소값 빼는게 아니라 joint1-> 0.5/0.5/0.5로 가도록
6 +% 실험할때 전방향 노멀라이즈도 해봐야겠다..
7 +
8 +clear;
9 +
10 +name = '/home/rfj/바탕화면/skeletones/S001C001P002R002A020.skeleton'
11 +bodyinfo = read_skeleton_file(name);
12 +frame_num = size(bodyinfo,2);
13 +
14 +%initialize
15 +cur_subject_x = zeros(frame_num, 25);
16 +cur_subject_y = zeros(frame_num, 25);
17 +cur_subject_z = zeros(frame_num, 25);
18 +
19 +tot_x = zeros(frame_num,25);
20 +tot_y = zeros(frame_num,25);
21 +tot_z = zeros(frame_num,25);
22 +
23 +joint_5 = zeros(1,3);
24 +joint_9 = zeros(1,3);
25 +joint_1 = zeros(1,3);
26 +joint_3 = zeros(1,3);
27 +
28 +%get total joints information
29 +for FN = 1:frame_num
30 + cur_body = bodyinfo(FN).bodies(1);
31 + joints = cur_body.joints;
32 +
33 + for JN = 1:25
34 + tot_x(FN,JN) = joints(JN).x;
35 + tot_y(FN,JN) = joints(JN).y;
36 + tot_z(FN,JN) = joints(JN).z;
37 + end
38 +end
39 +
40 +%get median values
41 +M_x = median(tot_x);
42 +M_y = median(tot_y);
43 +M_z = median(tot_z);
44 +
45 +%set 3 points for make plane
46 +joint_5 = [M_x(5) M_y(5) M_z(5)];
47 +joint_9 = [M_x(9) M_y(9) M_z(9)];
48 +joint_1 = [M_x(1) M_y(1) M_z(1)];
49 +joint_3 = [M_x(3) M_y(3) M_z(3)];
50 +
51 +%find RIGID TRNASFORMATION matrix
52 +d1 = joint_1 - joint_5;
53 +d2 = joint_1 - joint_9;
54 +n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly
55 +u1 = n1/norm(n1);
56 +u2 = [0 0 1];
57 +cs1 = dot(u1,u2)/norm(u1)*norm(u2);
58 +ss1 = sqrt(1-cs1.^2);
59 +v1 = cross(u1,u2)/norm(cross(u1,u2));
60 +
61 +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];
62 +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];
63 +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];
64 +
65 +%1-3 number tolls to parallel x axis. Rigid transformation on plane surface
66 +%Z axis coords oyler angle transform
67 +
68 +t = joint_3 - joint_1;
69 +d3 = R1(1,:) * t.';
70 +d3(1,2) = R1(2,:) * t.';
71 +d3(1,3) = R1(3,:) * t.';
72 +
73 +u3 = d3(1:2)/norm(d3(1:2));
74 +v3 = [u3(1) -u3(2)];
75 +v3(2,:) = [u3(2) u3(1)];
76 +u4 = [1 0].';
77 +
78 +csss = v3\u4;
79 +cs2 = csss(1);
80 +ss2 = csss(2);
81 +
82 +R2 = [cs2 -ss2 0];
83 +R2(2,:) = [ss2 cs2 0];
84 +R2(3,:) = [0 0 1];
85 +
86 +
87 +%apply rigid transformation
88 +for FN = 1:frame_num
89 + cur_body = bodyinfo(FN).bodies(1);
90 + joints = cur_body.joints;
91 +
92 + for JN = 1:25
93 + a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].';
94 + b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].';
95 + c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].';
96 +
97 + cur_subject_x(FN,JN) = R2(1,:) * [a b c].';
98 + cur_subject_y(FN,JN) = R2(2,:) * [a b c].';
99 + cur_subject_z(FN,JN) = R2(3,:) * [a b c].';
100 +
101 + end
102 +end
103 +
104 +%orientation normalize 2 (with plane surface)
105 +if cur_subject_x(1,4) < cur_subject_x(1,1)
106 + cur_subject_x = 0 - cur_subject_x;
107 +end
108 +
109 +if cur_subject_y(1,9) > cur_subject_y(1,5)
110 + cur_subject_y = 0 - cur_subject_y;
111 +end
112 +
113 +%get current median
114 +CM_x=median(cur_subject_x);
115 +CM_y=median(cur_subject_y);
116 +CM_z=median(cur_subject_z);
117 +
118 +%for transform bellybutton to 0.5,0.5 (Except X) but it doesn't work
119 +belly_button = 0.5 - CM_y(2);
120 +belly_button(2) = 0.5 - CM_z(2);
121 +
122 +% normalize with x... <- HERE! WANT TO PARALLEL TRANSFORM
123 +... but if I plus belly_button for x and y axis , it dosn't work
124 +cur_subject_x = cur_subject_x - min(cur_subject_x(:));
125 +max_tall = max(cur_subject_x(:));
126 +cur_subject_x = cur_subject_x ./ max_tall;
127 +
128 +cur_subject_y = cur_subject_y - min(cur_subject_y(:));
129 +cur_subject_y = cur_subject_y ./ max_tall;
130 +
131 +cur_subject_z = cur_subject_z - min(cur_subject_z(:));
132 +cur_subject_z = cur_subject_z ./ max_tall;
133 +
134 +
135 +% 이미지 저장
136 +motionpatch = cur_subject_x;
137 +motionpatch(:,:,2) = cur_subject_y;
138 +motionpatch(:,:,3) = cur_subject_z;
139 +
140 +new_file_name = strcat('/home/rfj/바탕화면/sample.png');
141 +imwrite(motionpatch,new_file_name);
142 +
143 +
144 +% read image after write
145 +
146 +ori = imread('/home/rfj/바탕화면/sample.png');
147 +ori = im2double(ori);
148 +ori = ori(:,:,:);
149 +
150 +dx = [];
151 +dy = [];
152 +dz = [];
153 +
154 +for f = 1:numel(ori(:,1,1))
155 + for j = 1:25
156 + dx = [dx;ori(f,j,1)];
157 + dy = [dy;ori(f,j,2)];
158 + dz = [dz;ori(f,j,3)];
159 + end
160 +end
161 +
162 +a = [1 0 0]; % Red 척추 1,2,3,4,20
163 +b = [0 0 1]; % Blue 오른팔 8,9,10,11,23,24
164 +c = [0 1 0]; % Green왼팔 5,6,7,21,22 (여기서 5번이 빠짐. 넣고싶으면 나중에 24 joint가 아니라 25 joint로 추가)
165 +d = [1 1 0]; % Yellow 오른다리 16,17,18,19
166 +e = [0 1 1]; % Skyblue 왼다리 12,13,14,15
167 +colors = [a;a;a;a;c;c;c;c;b;b;b;b;e;e;e;e;d;d;d;d;a;c;c;b;b];
168 +
169 +scatter3(dx,dy,dz,100,'filled');
170 +
171 +
172 +connecting_joints= ...
173 + [2 1 21 3 21 5 6 7 21 9 10 11 1 13 14 15 1 17 18 19 2 8 8 12 12];
174 +
175 +for jj=1:25:numel(dx)% 1부터 8개씩 numel = 열갯수..?
176 + current = [];
177 + current(:,1) = dy(jj:jj+24) ;
178 + current(:,2) = dz(jj:jj+24) ;
179 + current(:,3) = dx(jj:jj+24) ;
180 +
181 + scatter3(current(:,1),current(:,2),current(:,3),100,colors(:,:),'filled');
182 +
183 + for j =1:25
184 + k=connecting_joints(j);
185 + line([current(j,1) current(k,1)], [current(j,2) current(k,2)] , [current(j,3) current(k,3)])
186 + end
187 +
188 + set(gca,'Xdir','reverse','Ydir','reverse')
189 + xlim([0 1]);
190 + xlabel('x')
191 + ylim([0 1]);
192 + ylabel('y')
193 + zlim([0 1]);
194 + zlabel('z')
195 + drawnow
196 + pause(0.01)
197 +end
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +%missing file delete
3 +%LOCATION : raw skeletone files
4 +path_name = '/media/rfj/EEA4441FA443E923/nturgb_skeletones/';
5 +file_list = dir(path_name);
6 +L = length(file_list);
7 +
8 +fileID = fopen('/home/rfj/MATLAB/bin/samples_with_missing_skeletons.txt','r');
9 +formatSpec = '%s';
10 +sizeA = [20 Inf];
11 +missing_file_list = fscanf(fileID,formatSpec,sizeA);
12 +missing_file_list = missing_file_list.';
13 +fclose(fileID);
14 +
15 +perfect_list = [];
16 +
17 +for K = 3:L
18 + file_name = char(file_list(K).name);
19 + missing_num = 0;
20 +
21 + for J = 1:length(missing_file_list);
22 + missing_name = missing_file_list(J,:);
23 + if file_name(1:20) == missing_name
24 + missing_num = 1;
25 + end
26 + end
27 +
28 + if missing_num == 0
29 + perfect_list = [perfect_list;file_name];
30 + end
31 +
32 +end
33 +
34 +% make motion patch
35 +
36 +L = length(perfect_list);
37 +
38 +for K = 1:L
39 + file_name = char(perfect_list(K,:));
40 + name = strcat(path_name,file_name(1:20),'.skeleton');
41 + num_body = file_name(22);
42 + BN = str2num(num_body);
43 + [token,remainder] = strtok(file_name,'A');
44 + class = str2num(remainder(2:4));
45 +
46 + if class == 20
47 + bodyinfo = read_skeleton_file(name);
48 + frame_num = size(bodyinfo,2);
49 +
50 + %initialize
51 + cur_subject_x = zeros(frame_num, 25);
52 + cur_subject_y = zeros(frame_num, 25);
53 + cur_subject_z = zeros(frame_num, 25);
54 +
55 + tot_x = zeros(frame_num,25);
56 + tot_y = zeros(frame_num,25);
57 + tot_z = zeros(frame_num,25);
58 +
59 + joint_5 = zeros(1,3);
60 + joint_9 = zeros(1,3);
61 + joint_1 = zeros(1,3);
62 + joint_3 = zeros(1,3);
63 +
64 + try
65 + %get total joints information
66 + for FN = 1:frame_num
67 + cur_body = bodyinfo(FN).bodies(1);
68 + joints = cur_body.joints;
69 +
70 + for JN = 1:25
71 + tot_x(FN,JN) = joints(JN).x;
72 + tot_y(FN,JN) = joints(JN).y;
73 + tot_z(FN,JN) = joints(JN).z;
74 + end
75 + end
76 +
77 + %get median values
78 + M_x = median(tot_x);
79 + M_y = median(tot_y);
80 + M_z = median(tot_z);
81 +
82 +
83 + %set 3 points for make plane
84 + joint_5 = [M_x(5) M_y(5) M_z(5)];
85 + joint_9 = [M_x(9) M_y(9) M_z(9)];
86 + joint_1 = [M_x(1) M_y(1) M_z(1)];
87 + joint_3 = [M_x(3) M_y(3) M_z(3)];
88 +
89 + %find RIGID TRNASFORMATION matrix
90 + d1 = joint_1 - joint_5;
91 + d2 = joint_1 - joint_9;
92 + n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly
93 + u1 = n1/norm(n1);
94 + u2 = [0 0 1];
95 + cs1 = dot(u1,u2)/norm(u1)*norm(u2);
96 + ss1 = sqrt(1-cs1.^2);
97 + v1 = cross(u1,u2)/norm(cross(u1,u2));
98 +
99 + 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];
100 + 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];
101 + 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];
102 +
103 + %1-3 number tolls to parallel x axis. Rigid transformation on plane surface
104 + %Z axis coords oyler angle transform
105 +
106 + t = joint_3 - joint_1;
107 + d3 = R1(1,:) * t.';
108 + d3(1,2) = R1(2,:) * t.';
109 + d3(1,3) = R1(3,:) * t.';
110 +
111 + u3 = d3(1:2)/norm(d3(1:2));
112 + v3 = [u3(1) -u3(2)];
113 + v3(2,:) = [u3(2) u3(1)];
114 + u4 = [1 0].';
115 +
116 + csss = v3\u4;
117 + cs2 = csss(1);
118 + ss2 = csss(2);
119 +
120 + R2 = [cs2 -ss2 0];
121 + R2(2,:) = [ss2 cs2 0];
122 + R2(3,:) = [0 0 1];
123 +
124 +
125 + %apply rigid transformation
126 + for FN = 1:frame_num
127 + cur_body = bodyinfo(FN).bodies(1);
128 + joints = cur_body.joints;
129 +
130 + for JN = 1:25
131 + a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].';
132 + b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].';
133 + c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].';
134 +
135 + cur_subject_x(FN,JN) = R2(1,:) * [a b c].';
136 + cur_subject_y(FN,JN) = R2(2,:) * [a b c].';
137 + cur_subject_z(FN,JN) = R2(3,:) * [a b c].';
138 +
139 + end
140 + end
141 +
142 + %orientation normalize 2 (with plane surface)
143 + if cur_subject_x(1,4) < cur_subject_x(1,1)
144 + cur_subject_x = 0 - cur_subject_x;
145 + end
146 +
147 + if cur_subject_y(1,9) > cur_subject_y(1,5)
148 + cur_subject_y = 0 - cur_subject_y;
149 + end
150 +
151 + %get current median
152 + CM_x=median(cur_subject_x);
153 + CM_y=median(cur_subject_y);
154 + CM_z=median(cur_subject_z);
155 +
156 + %for transform bellybutton to 0.5,0.5 (Except X) but it doesn't work
157 + belly_button = 0.5 - CM_y(2);
158 + belly_button(2) = 0.5 - CM_z(2);
159 +
160 + % normalize with x... <- HERE! WANT TO PARALLEL TRANSFORM
161 + ... but if I plus belly_button for x and y axis , it dosn't work
162 + cur_subject_x = cur_subject_x - min(cur_subject_x(:));
163 + max_tall = max(cur_subject_x(:));
164 + cur_subject_x = cur_subject_x ./ max_tall;
165 +
166 + cur_subject_y = cur_subject_y - min(cur_subject_y(:));
167 + cur_subject_y = cur_subject_y ./ max_tall;
168 +
169 + cur_subject_z = cur_subject_z - min(cur_subject_z(:));
170 + cur_subject_z = cur_subject_z ./ max_tall;
171 +
172 +
173 + % 이미지 저장
174 + motionpatch = cur_subject_x;
175 + motionpatch(:,:,2) = cur_subject_y;
176 + motionpatch(:,:,3) = cur_subject_z;
177 +
178 +
179 + new_file_name = strcat('/home/rfj/바탕화면/motionpatch/',num2str(class),'/',file_name(1:20),'.png');
180 + imwrite(motionpatch,new_file_name);
181 +
182 + catch
183 + name
184 + end
185 +
186 + end
187 +
188 +
189 +
190 +end