-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalibrate_infant.m
140 lines (104 loc) · 4.65 KB
/
Calibrate_infant.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
function [calibPlotData] = Calibrate_infant(Calib,morder,iter,donts,Constants)
global EXPWIN GREY
%CALIBRATE calibrate the eye tracker
% This function is used to set and view the calibration results for the tobii eye tracker.
%
% Input:
% Calib: The calib structure (see CalibParams)
% morder: Order of the calibration point
% iter: 0/1 (0 = A new calibation call, esnure that calibration is not already started)
% (1 = just fixing a few Calibration points)
% donts: Points (with one in the index) that are to be
% recalibrated, 0 else where
% Output:
% calibPlotData: The calibration plot data, specifying the input and output calibration data
calibPlotData = 0;
assert(Calib.points.n >= 2 && length(Calib.points.x)==Calib.points.n, ...
'Err: Invalid Calibration params, Verify...');
%THE MOVIE AND THE FUNCTION THAT RUNS IT (THIS ONE) MUST BE IN THE
%MATLAB WORKING FOLDER. Otherwise Screen(OpenMovie) won't work
%tl x,y br x,y
FixPointVidDir=dir([Constants.calpoint_dir '*.mp4']);
fn=randi(length(FixPointVidDir));
moviename = [Constants.calpoint_dir FixPointVidDir(fn).name];
try
tetio_startCalib;
catch error
disp( 'error')
disp(error.message)
end
try
if iter == 1
tetio_startCalib;
end
movieWidthReduced = Constants.calpoint_size; % movieWidth*0.5;
movieHeightReduced = Constants.calpoint_size; %movieHeight*0.5;
Screen('FillRect',EXPWIN,Calib.bkcolor);
Screen(EXPWIN, 'Flip');
if iter == 1
tetio_startCalib;
end
idx = 0;
validmat = ones(1,Calib.points.n);
%generate validity matrix
if ~isempty(donts)
validmat = zeros(1,Calib.points.n);
for i = 1:length(donts)
validmat(morder==donts(i))=1;
end
end
pause(1);
Screen('FillRect',EXPWIN,Calib.bkcolor);
tic;
%Open movie
movie = 0;
%[ movie duration fps movieWidth movieHeight count aspectRatio] = Screen('OpenMovie', EXPWIN, moviename);
%Screen('PlayMovie', movie, 1,1,1.0);
for i =1:Calib.points.n
vidObj= VideoReader(moviename);
[Y,FS] = audioread(moviename);
idx = idx+1;
if (validmat(i)==0)
continue;
end
%Prepare movie location
sRect (1) = round(Calib.screen.width*Calib.points.x(morder(i))-movieWidthReduced/2);
sRect (2) = round(Calib.screen.height*Calib.points.y(morder(i))-movieHeightReduced/2);
sRect (3) = round(Calib.screen.width*Calib.points.x(morder(i))+movieWidthReduced/2);
sRect (4) = round(Calib.screen.height*Calib.points.y(morder(i))+movieHeightReduced/2);
%sound(Y*Constants.CalVolume,FS)
sound(Y*Constants.CalVolume, FS*((length(Y)/FS)/Constants.CalVideoLength) )
while 1
% Wait for next movie frame, retrieve texture handle to it
%tex = Screen('GetMovieImage', EXPWIN, movie);
tex=Screen('MakeTexture', EXPWIN, vidObj.readFrame);
% Draw the new texture immediately to screen:
if (vidObj.hasFrame)
%Screen('DrawTexture', EXPWIN,tex,[0 0 movieWidth movieHeight],sRect);
Screen('DrawTexture', EXPWIN, tex,[],sRect);
% Update display:
Screen('Flip', EXPWIN);
% Release texture:
Screen('Close', tex);
else
break
end
%calculate appropriate wait time to enforce common length
WaitSecs(1/(round(vidObj.Duration*vidObj.FrameRate)/Constants.CalVideoLength));
end
tetio_addCalibPoint(Calib.points.x(morder(i)),Calib.points.y(morder(i)));
end
Screen('FillRect',EXPWIN,Calib.bkcolor);
Screen(EXPWIN, 'Flip');
close
tetio_computeCalib;
calibPlotData = tetio_getCalibPlotData;
tetio_stopCalib;
catch error
disp( 'error')
disp(error.message)
disp(error.stack(1,1).name)
disp(error.stack(1,1).line)
calibPlotData = 0;
end
return