-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectorFigCalibrate.m
187 lines (162 loc) · 5.16 KB
/
projectorFigCalibrate.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
function projectorFigCalibrate(trackableName,host)
% The "projectorFigCalibrate" function this function calibrates the the
% projector to create figures that have the same coordiates as the
% optitrack data points.
%
% SYNTAX:
% projectorFigCalibrate(trackableName,host,figPos)
%
% INPUTS:
% trackableName - (string)
% Name of OptiTrack trackable used for calibration routine. Name must
% match name assigned in OptiTrack's rigid bodies properties.
%
% host - (string)
% IP address or host name of computer running optitrack that is
% streaming data from the VRPN Streaming Engine.
%
% EXAMPLES:
% projectorFigCalibrate('K8','192.168.2.145');
% % Follow instructions on command window.
%
% NOTES:
%
% NECESSARY FILES:
% +trackable
%
% SEE ALSO:
% projectorFigCalibrateTest | projectorFigure
%
% AUTHOR:
% Rowland O'Flaherty (http://rowlandoflaherty.com)
%
% VERSION:
% Created 08-APR-2015
%-------------------------------------------------------------------------------
%% Check Inputs
% Check number of inputs
narginchk(2,2)
% Check input arguments for errorss
assert(ischar(trackableName),...
'projectorFigCalibrate:trackableName',...
'Input argument "trackableName" must be a string')
assert(ischar(host),...
'projectorFigCalibrate:host',...
'Input argument "host" must be a string')
%% Create trackable
T = trackable.trackable(false,trackableName,host);
validTrackable = T.init();
assert(validTrackable,...
'projectorFigCalibrate:trackable',...
'Trackable data not received for trackable: ''%s'' and host: ''%s''.',trackableName,host)
T.orientationGlobalRotation_ = quaternion([0 0 pi])' * T.orientationGlobalRotation_;
T.update();
%% Create figure
close all
figure(1)
clf(1)
set(1,'MenuBar','none')
axH = gca;
set(axH,'Position',[0 0 1 1])
set(axH,'XLimMode','manual')
set(axH,'YLimMode','manual')
set(axH,'XLim',[-1 1])
set(axH,'YLim',[-1 1])
%% Splash info
clc
fprintf('+======================================+\n');
fprintf('| Projector Figure Calibration Routine |\n');
fprintf('+======================================+\n');
fprintf('\n');
fprintf('Drag the figure to projector screen and\n');
fprintf('maximize the figure,\n');
fprintf('then press ENTER.\n');
pause
fprintf('\n');
fprintf('Zoom the projector in until all menus and\n');
fprintf('borders are not visible in the figure,\n');
fprintf('then press ENTER.\n');
pause
fprintf('\n');
%% Get zoom number
zoomNum = nan;
while isnan(zoomNum)
zoomNumStr = input('How many times did you zoom in? ','s');
fprintf('\n');
zoomNum = str2double(zoomNumStr);
if ~isnumeric(zoomNum) || numel(zoomNum) ~= 1 || mod(zoomNum,1) ~= 0 || zoomNum < 0
zoomNum = nan;
fprintf('Invalid entry. Please enter an integer >= 0.\n');
fprintf('\n');
end
end
%% Define markers
marker = struct('colorName',{'red','green','blue','yellow'},...
'color',{'r','g','b','y'},...
'pos',{[-.5 .5], [.5 .5], [.5 -.5], [-.5 -.5]},...
'size',25,...
'coord',nan(2,1));
%% Plot markers
nMarkers = numel(marker);
hold(axH,'on')
for i = 1:nMarkers
mH(i) = hggroup; %#ok<AGROW>
plot(axH,marker(i).pos(1),marker(i).pos(2),'ok',...
'MarkerSize',marker(i).size,'MarkerFaceColor',marker(i).color,'Parent',mH(i))
plot(axH,marker(i).pos(1),marker(i).pos(2),'ok',...
'MarkerSize',10,'MarkerFaceColor','k','Parent',mH(i))
set(mH(i),'Visible','off');
end
hold(axH,'off')
%% Get marker coordinates
for i = 1:nMarkers;
set(mH(i),'Visible','on');
fprintf('Move trackable to %s marker, \n',upper(marker(i).colorName));
fprintf('then press ENTER.\n');
pause
T.update()
marker(i).coord = T.position(1:2);
fprintf('%s marker coordinates: x = %2.3f y = %2.3f\n',...
upper(marker(i).colorName),marker(i).coord(1), marker(i).coord(2));
fprintf('\n');
set(mH(i),'Visible','off');
end
%% Calc axes limits
c = [marker([1 4]).coord];
x(1) = mean(c(1,:));
c = [marker([2 3]).coord];
x(2) = mean(c(1,:));
c = [marker([3 4]).coord];
y(1) = mean(c(2,:));
c = [marker([1 2]).coord];
y(2) = mean(c(2,:));
xLim = [x(1) - (x(2) - x(1))/2, x(1) + 3/2*(x(2) - x(1))];
yLim = [y(1) - (y(2) - y(1))/2, y(1) + 3/2*(y(2) - y(1))];
fprintf('Figure XLim: [%2.4f, %2.4f]\n', xLim(1), xLim(2));
fprintf('Figure YLim: [%2.4f, %2.4f]\n', yLim(1), yLim(2));
fprintf('\n');
%% File struct
projectorFig.xLim = xLim;
projectorFig.yLim = yLim;
projectorFig.marker = marker;
projectorFig.position = get(gcf,'Position');
projectorFig.zoomNum = zoomNum; %#ok<STRNU>
%% Save figure limits
calibrationFileName = 'projectorFigCalData.mat';
save(calibrationFileName,'projectorFig')
fprintf('Calibration file saved to:\n%s\n',fullfile(pwd,calibrationFileName));
fprintf('\n');
%% Set figure limits and replot
cla(axH)
set(axH,'XLim',xLim)
set(axH,'YLim',yLim)
hold(axH,'on')
for i = 1:nMarkers
plot(axH,marker(i).coord(1),marker(i).coord(2),'ok',...
'MarkerSize',marker(i).size,'MarkerFaceColor',marker(i).color)
end
hold(axH,'off')
%% Test info
fprintf('Run "projectorFigCalibrateTest(''%s'',''%s'',''%s'');"\n',trackableName,host,calibrationFileName);
fprintf('function to test calibration.\n\n');
end