-
Notifications
You must be signed in to change notification settings - Fork 11
/
run_tracker_demo.m
159 lines (123 loc) · 5.87 KB
/
run_tracker_demo.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
% Robust Visual Tracking via Hierarchical Convolutional Features
% Chao Ma, Jia-Bin Huang, Xiaokang Yang, and Ming-Hsuan Yang
% IEEE Transactions on Pattern Analysis and Machine Intellegince
function [precision, fps] = run_tracker_demo(video, show_visualization, show_plots)
% run_HCFTstar_demo:
% process a sequence using HCFTstar (Correlation filter tracking with convolutional features)
%
% Input:
% - video: sequence name
% - show_visualization: whether to show results
% - show_plots: whether to show tracking precision
% Output:
% - precision: tracking results with bounding boxes over time
% - fps: tracking results with FPS
%
% It is provided for educational/researrch purpose only.
% If you find the software useful, please consider cite our paper.
dbstop if error;
%path to the OTB videos (you'll be able to choose one with the GUI).
base_path ='./OTB_dataset';
close all;
addpath('utility','train');
% Path to MatConvNet. Please run external/matconvnet/vl_compilenn.m to
% set up the MatConvNet
addpath './matconvnet/matlab'
vl_setupnn();
% Where the 'imagenet-vgg-verydeep-19.mat' file is
addpath './vgg_model'
addpath(genpath('edgesbox'));
addpath(genpath('piotr_toolbox'));
addpath(genpath('Diagnose'))
% Default settings
if nargin < 1, video = 'choose'; end
if nargin < 2, show_visualization = ~strcmp(video, 'all'); end
if nargin < 3, show_plots = ~strcmp(video, 'all'); end
% Extra area surrounding the target
padding = struct('generic', 1.8, 'large', 1, 'height', 0.4);
lambda = 1e-4; % Regularization parameter (see Eqn 3 in our paper)
output_sigma_factor = 0.1; % Spatial bandwidth (proportional to the target size)
interp_factor = 0.01; % Model learning rate (see Eqn 6a, 6b)
cell_size = 4; % Spatial cell size
config.kernel_sigma = 1;
config.motion_thresh= 0.181; %0.25 for singer2 0.32;%0.15
config.appearance_thresh=0.38; %0.38
config.features.hog_orientations = 9;
config.features.cell_size = 4; % size of hog grid cell
config.features.window_size = 6; % size of local region for intensity historgram
config.features.nbins=8;
global enableGPU;
enableGPU = true;
switch video
case 'choose'
% Ask the user for selecting the video, then call self with that video name.
% matlabpool open local 8;
video = choose_video(base_path);
if ~isempty(video)
% Start tracking
[precision, fps] = run_tracker_demo(video, show_visualization, show_plots);
if nargout == 0 % Don't output precision as an argument
clear precision
end
end
case 'all'
%all videos, call self with each video name.
%only keep valid directory names
dirs = dir(base_path); videos = {dirs.name};
videos(strcmp('.', videos) | strcmp('..', videos) | ...
strcmp('anno', videos) | ~[dirs.isdir]) = [];
% Note: the 'Jogging' sequence has 2 targets, create one entry for each.
% we could make this more general if multiple targets './top-down/'per video
% becomes a common occurence.
%=========================================================================
% Uncomment following scripts if you test on the entire bechmark
% videos(strcmpi('Jogging', videos)) = [];
% videos(end+1:end+2) = {'Jogging.1', 'Jogging.2'};
%
% videos(strcmpi('Skating2', videos))=[];
% videos(end+1:end+2)={'Skating2.1', 'Skating2.2'};
%=========================================================================
all_precisions = zeros(numel(videos),1); % to compute averages
all_fps = zeros(numel(videos),1);
%poolobj = gcp;
poolobj=gcp('nocreate');
parfor k = 1:numel(videos)
%if exist([result_path videos{k} '.mat'],'file'), continue; end
[prec, all_fps(k)] = run_tracker_demo(videos{k}, show_visualization, show_plots);
all_precisions(k) = prec;
end
delete(poolobj);
%compute average precision at 20px, and FPS
mean_precision = mean(all_precisions);
fps = mean(all_fps);
fprintf('\nAverage precision (20px):% 1.3f, Average FPS:% 4.2f\n\n', mean_precision, fps)
save([result_path 'average' '.mat'],'mean_precision');
if nargout > 0
precision = mean_precision;
end
otherwise
% We were given the name of a single video to process.
% get image file names, initial state, and ground truth for evaluation
[img_files, pos, target_sz, ground_truth, video_path] = load_video_info(base_path, video);
% Call tracker function with all the relevant parameters
% [positions, time] = tracker_ensemble(video_path, img_files, pos, target_sz, ...
% padding, lambda, output_sigma_factor, interp_factor, ...
% cell_size, show_visualization);
[positions, time,rect_position] = tracker_HCFTstar(video_path, img_files, pos, target_sz, ...
padding, lambda, output_sigma_factor, interp_factor, ...
cell_size, show_visualization,config); %tracker_ensemble_RPnew1
% Calculate and show precision plot, as well as frames-per-second
precisions = precision_plot(positions, ground_truth, video, show_plots);
fps = numel(img_files) / time;
results.type = 'rect';
results.res = rect_position;%each row is a rectangle
results.len = size(precisions,1);
results.fps = fps;
fprintf('%12s - Precision (20px):% 1.3f, FPS:% 4.2f\n', video, precisions(20), fps)
precision=precisions(20);
if nargout > 0
%return precisions at a 20 pixels threshold
precision = precisions(20);
end
end
end