-
Notifications
You must be signed in to change notification settings - Fork 14
/
vot.m
141 lines (113 loc) · 3.52 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
function [handle, image, region] = vot(format)
% 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.
%
% 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
[handle, image, region] = tracker_initialize(format);
handle.frame = @tracker_frame;
handle.report = @tracker_report;
handle.quit = @tracker_quit;
end
function [handle, image, region] = tracker_initialize(format)
% tracker_initialize Initialize communication structure
%
% This function is used to initialize communication with the toolkit.
%
% Input:
% - format (string): Desired region input format.
%
% 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'})
error('VOT: Illegal region format.');
end;
if ~isempty(getenv('TRAX_MEX'))
addpath(getenv('TRAX_MEX'));
end;
traxserver('setup', format, 'path');
[image, region] = traxserver('wait');
handle = struct('trax', true);
if isempty(image) || isempty(region)
tracker_quit(handle);
return;
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;
end
function handle = tracker_report(handle, region)
% 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.
%
% 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;
traxserver('status', region);
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