-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_functions.m
130 lines (101 loc) · 3.85 KB
/
basic_functions.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
%% To begin with
% This file introduces all the functionalities. Each block
% introduces one function.
%% Set current working path !!!
cd path\of\the\current\mfile
% add functions path
addpath(fullfile(pwd, 'funcs'));
%% Load posture data of one task
% I copied one file to current folder for demo purpose.
% To access all data, you should download all using
% the link on my github page.
% Note that the 'file_dir' should be the directory of .mat file.
close all; clc;
% Choose marker data directory
file_dir=uigetdir(pwd, 'Choose Where You Dnowloaded the Marker Data (e.g., xx\working_posture_trc_mat\). ');
% file_dir='\data\working_posture_trc_mat'; % data directory
% Demo file name: 'sub07_09_01_trc.mat'.
sub_id=7; task_id=9; task_iid=1; % task_iid is the trial number
% get all posture data from one task
pose_st=get_one_task(sub_id, task_id, task_iid, file_dir);
pose_st=pose_st.xyz_all;
% The first cell is frame id
frame_id=pose_st{1};
fprintf("Number of frames: %d\n", max(frame_id));
% The second cell is frame time for each frame
frame_time=pose_st{2};
fprintf("Length of the task: %f s\n", max(frame_time));
% summary
% The third cell is the marker data struct
marker_st=pose_st{3};
marker_name=marker_st(:,1); % marker name
% disp(marker_name');
marker_xyz=marker_st(:,2); % xyz data for each marker
% coloumn: 3 (xyz) * 37 (number of markers)
% row: number of frames
% E.g., to get marker data of forehead marker (FH)
FH_xyz=marker_xyz{1};
%% Load one frame from video
% Similar to previous bloack,
% I copied one video file to current folder for demo purpose.
% To access all data, you should download all using
% the link on my github page.
% Note that the 'file_dir' should be the directory of .avi file.
% Choose video data directory
file_dir=uigetdir(pwd, 'Choose Where You Dnowloaded the video Data (e.g., xx\working_posture_video\). ');
% file_dir='\data\working_posture_video';
% Demo file name: 'sub07_09_01.avi'.
sub_id=7; task_id=9; task_iid=1;
% get the frame
frame_id=3;
video_struct=get_one_frame(sub_id, task_id, task_iid, frame_id, ...
file_dir);
% show the frame
imshow(video_struct.frame);shg;
%% visualize one pose
% Now, after running the previous two blocks, you should have
% loaded the video and marker files.
% This block visualize the pose throgh connecting all markers.
close all;
% Visualize the 'nf' th frame
nf=10;
vis_pose_37(marker_xyz, nf);
% Play all frames of current task
vis_pose_37(marker_xyz);
%% load marker .trc file of box
% Demo file name: 'sub07_09_01_box_trc.mat'.
sub_id=7; task_id=9; task_iid=1;
% create file path
% Choose box marker data directory
file_dir=uigetdir(pwd, 'Choose Where You Dnowloaded the Marker Data (e.g., xx\box_trc\). ');
box_file_dir=fullfile(file_dir, ['sub', num_to_2char(sub_id)]);
box_file_name=[['sub', num_to_2char(sub_id)],'_',...
num_to_2char(task_id), '_', num_to_2char(task_iid),...
'_box_trc.mat'];
box_file_path=fullfile(box_file_dir, box_file_name);
% load
box_marker_st=load(box_file_path);
box_marker_st=box_marker_st.box_xyz_all;
% summary
% The third cell is the marker data struct
disp(box_marker_st{3}(:,1));
box_marker_xyz=box_marker_st{3}(:,2); % xyz for each marker
%% load shelf and chair.trc file of box
% note that the shelf and chair were fixed
% Choose box marker data directory
file_dir=uigetdir(pwd, 'Choose Where You Dnowloaded the Marker Data (e.g., xx\virtual_trc\). ');
% create file path
chair_file_path=fullfile(file_dir, '\chair_virtual_trc.mat');
shelf_file_path=fullfile(file_dir, '\shelf_virtual_trc.mat');
% load
chair_marker_st=load(chair_file_path);
shelf_marker_st=load(shelf_file_path);
chair_marker_st=chair_marker_st.chair_xyz_all;
shelf_marker_st=shelf_marker_st.shelf_xyz_all;
% summary
% marker name
disp(chair_marker_st(:,1));
disp(shelf_marker_st(:,1));
% marker xyz
chair_marker_xyz=chair_marker_st(:,2);
shelf_marker_xyz=shelf_marker_st(:,2);