-
Notifications
You must be signed in to change notification settings - Fork 0
/
vot.m
178 lines (143 loc) · 4.68 KB
/
vot.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
function [handle, image, region] = vot(format, channels)
% vot Initialize communication and obtain communication structure
%
% This function is used to initialize communication with the toolkit.
%
% The resulting handle is a structure provides several functions for
% further interaction:
% - frame(handle): Get new frame from the sequence.
% - report(handle, region): Report region for current frame and advance.
% - quit(handle): Closes the communication and saves the data.
%
% Input:
% - format (string): Desired region input format.
% - channels (string): Which channels are required by the trackers
% - (default): only color
% - rgbd: color and depth
% - ir: only ir
% - rgbt: color and ir
%
% Output:
% - handle (structure): Updated communication handle structure.
% - image (string): Path to the first image file.
% - region (vector): Initial region encoded as a rectangle or as a polygon.
if nargin < 1
format = 'rectangle';
end
if nargin < 2 || strcmp(channels, 'color')
channels = {'color'};
elseif strcmp(channels, 'rgbd')
channels = {'color', 'depth'};
elseif strcmp(channels, 'ir')
channels = {'ir'};
elseif strcmp(channels, 'rgbt')
channels = {'color', 'ir'};
end
[handle, image, region] = tracker_initialize(format, channels);
handle.frame = @tracker_frame;
handle.report = @tracker_report;
handle.quit = @tracker_quit;
end
function [handle, image, region] = tracker_initialize(format, channels)
% tracker_initialize Initialize communication structure
%
% This function is used to initialize communication with the toolkit.
%
% Input:
% - format (string): Desired region input format: rectangle, polygon or mask.
% - channels (string, cell): Which channels are required by the trackers
%
% Output:
% - handle (structure): Updated communication handle structure.
% - image (string): Path to the first image file.
% - region (vector): Initial region encoded as a rectangle or as a polygon.
if ~ismember(format, {'rectangle', 'polygon', 'mask'})
error('VOT: Illegal region format.');
end;
if ~all(ismember(channels, {'color', 'depth', 'ir'}))
error('VOT: Illegal channel type.');
end;
if ~isempty(getenv('TRAX_MEX'))
addpath(getenv('TRAX_MEX'));
end;
traxserver('setup', format, 'path', 'Channels', channels, 'vot', 'matlab');
[image, region] = traxserver('wait');
handle = struct('trax', true);
if isempty(image) || isempty(region)
tracker_quit(handle);
return;
end;
if iscell(image) && numel(image) == 1
image = image{1}
end;
handle.initialization = region;
end
function [handle, image] = tracker_frame(handle)
% tracker_frame Get new frame from the sequence
%
% This function is used to get new frame from the current sequence
%
% Input:
% - handle (structure): Communication handle structure.
%
% Output:
% - handle (structure): Updated communication handle structure.
% - image (string): Path to image file.
if ~isstruct(handle)
error('VOT: Handle should be a structure.');
end;
if ~isempty(handle.initialization)
traxserver('status', handle.initialization);
handle.initialization = [];
end;
[image, region] = traxserver('wait');
if isempty(image) || ~isempty(region)
handle.quit(handle);
end;
if iscell(image) && numel(image) == 1
image = image{1}
end;
end
function handle = tracker_report(handle, region, confidence)
% tracker_report Report region for current frame and advance
%
% This function stores the region for the current frame and advances
% the internal counter to the next frame.
%
% Input:
% - handle (structure): Communication handle structure.
% - region (vector): Predicted region as a rectangle or a polygon.
% - confidence (float): Optional number that indicates confidence of prediction.
% Can be on arbitrary scale, higher value means more confidence.
%
% Output:
% - handle (structure): Updated communication handle structure.
if isempty(region)
region = 0;
end;
if ~isstruct(handle)
error('VOT: Handle should be a structure.');
end;
if ~isempty(handle.initialization)
handle.initialization = [];
end;
parameters = struct();
if nargin > 2
parameters.confidence = confidence;
end
traxserver('status', region, parameters);
end
function tracker_quit(handle)
% tracker_quit Closes the communication and saves the data
%
% This function closes the communication with the toolkit and
% saves the remaining data.
%
% Input:
% - handle (structure): Communication handle structure.
%
if ~isstruct(handle)
error('VOT: Handle should be a structure.');
end;
traxserver('quit');
end