read_skeleton_file.m
2.88 KB
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
function bodyinfo = read_skeleton_file(filename)
% Reads an .skeleton file from "NTU RGB+D 3D Action Recognition Dataset".
%
% Argrument:
% filename: full adress and filename of the .skeleton file.
%
% For further information please refer to:
% NTU RGB+D dataset's webpage:
% http://rose1.ntu.edu.sg/Datasets/actionRecognition.asp
% NTU RGB+D dataset's github page:
% https://github.com/shahroudy/NTURGB-D
% CVPR 2016 paper:
% Amir Shahroudy, Jun Liu, Tian-Tsong Ng, and Gang Wang,
% "NTU RGB+D: A Large Scale Dataset for 3D Human Activity Analysis",
% in IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016
%
% For more details about the provided data, please refer to:
% https://msdn.microsoft.com/en-us/library/dn799271.aspx
% https://msdn.microsoft.com/en-us/library/dn782037.aspx
fileid = fopen(filename);
framecount = fscanf(fileid,'%d',1); % no of the recorded frames
bodyinfo=[]; % to store multiple skeletons per frame
for f=1:framecount
bodycount = fscanf(fileid,'%d',1); % no of observerd skeletons in current frame
for b=1:bodycount
clear body;
body.bodyID = fscanf(fileid,'%ld',1); % tracking id of the skeleton
arrayint = fscanf(fileid,'%d',6); % read 6 integers
body.clipedEdges = arrayint(1);
body.handLeftConfidence = arrayint(2);
body.handLeftState = arrayint(3);
body.handRightConfidence = arrayint(4);
body.handRightState = arrayint(5);
body.isResticted = arrayint(6);
lean = fscanf(fileid,'%f',2);
body.leanX = lean(1);
body.leanY = lean(2);
body.trackingState = fscanf(fileid,'%d',1);
body.jointCount = fscanf(fileid,'%d',1); % no of joints (25)
joints=[];
for j=1:body.jointCount
jointinfo = fscanf(fileid,'%f',11);
joint=[];
% 3D location of the joint j
joint.x = jointinfo(1);
joint.y = jointinfo(2);
joint.z = jointinfo(3);
% 2D location of the joint j in corresponding depth/IR frame
joint.depthX = jointinfo(4);
joint.depthY = jointinfo(5);
% 2D location of the joint j in corresponding RGB frame
joint.colorX = jointinfo(6);
joint.colorY = jointinfo(7);
% The orientation of the joint j
joint.orientationW = jointinfo(8);
joint.orientationX = jointinfo(9);
joint.orientationY = jointinfo(10);
joint.orientationZ = jointinfo(11);
% The tracking state of the joint j
joint.trackingState = fscanf(fileid,'%d',1);
body.joints(j)=joint;
end
bodyinfo(f).bodies(b)=body;
end
end
fclose(fileid);
end