function [precision, fps] = run_tracker(video, kernel_type, feature_type, show_visualization, show_plots)
base_path ='D:\samf data';
base_path =’ '; 引号内是样本储存的地址
if nargin < 1, video = 'choose'; end
if nargin < 2, kernel_type = 'gaussian'; end
if nargin < 3, feature_type = 'hogcolor'; end
if nargin < 4, show_visualization = ~strcmp(video, 'all'); end %比较strcmp中的量,相同就是1,否就是0
if nargin < 5, show_plots = ~strcmp(video, 'all'); end
nargin是输入的参数值的个数
比较strcmp中的量,相同就是1,否就是0
kernel.type = kernel_type;
features.gray = false;
features.hog = false;
features.hogcolor = false;
padding = 1.5; %extra area surrounding the target 目标周围的额外区域
lambda = 1e-4; %regularization 正则化系数λ
output_sigma_factor = 0.1; %spatial bandwidth (proportional to target) 空间带宽(与目标成正比)
以上两段代码片是默认的设置
switch feature_type
case 'gray' %灰度
interp_factor = 0.075; % 时间更新系数(自适应线性插值因子)
kernel.sigma = 0.2; %高斯核带宽
kernel.poly_a = 1; %多项式核可加项
kernel.poly_b = 7; %多项式核指数
features.gray = true;
cell_size = 1;
case 'hog' %梯度直方图
interp_factor = 0.015;
kernel.sigma = 0.5;
kernel.poly_a = 1;
kernel.poly_b = 9;
features.hog = true;
features.hog_orientations = 9;
cell_size = 4;
case 'hogcolor'
interp_factor = 0.01;
kernel.sigma = 0.5;
kernel.poly_a = 1;
kernel.poly_b = 9;
features.hogcolor = true;
features.hog_orientations = 9;
cell_size = 4;
otherwise
error('Unknown feature.')
end
assert(any(strcmp(kernel_type, {'linear', 'polynomial', 'gaussian'})), 'Unknown kernel.')
%assert判断一个表达式是否成立
switch video
case 'choose'
video = choose_video(base_path);
if ~isempty(video)
[precision, fps] = run_tracker(video, kernel_type, ...
feature_type, show_visualization, show_plots);
if nargout == 0 %不要输出精度作为参数
clear precision
end
end
case 'all'
dirs = dir(base_path); %获得指定文件夹下所有的子文件和文件
videos = {dirs.name};
videos(strcmp('.', videos) | strcmp('..', videos) | ...
strcmp('anno', videos) | ~[dirs.isdir]) = [];
videos(strcmpi('Jogging', videos)) = [];
videos(end+1:end+2) = {'Jogging.1', 'Jogging.2'};
all_precisions = zeros(numel(videos),1);
if ~exist('matlabpool', 'file') %exist用于查变量是否存在,存在输出1,否输出0
% 没有并行工具箱,使用简单的“for”来迭代
for k = 1:numel(videos)
[all_precisions(k), all_fps(k)] = run_tracker(videos{k}, ...
kernel_type, feature_type, show_visualization, show_plots);
end
else
%并行评估所有视频的跟踪器
if parpool('size') == 0 %parpool 是并行计算
parpool open;
end
parfor k = 1:numel(videos) %一个并行的for循环
[all_precisions(k), all_fps(k)] = run_tracker(videos{k}, ...
kernel_type, feature_type, show_visualization, show_plots);
end
end
mean_precision = mean(all_precisions); %mean是用来计算平均值的
fps = mean(all_fps);
fprintf('\nAverage precision (20px):% 1.3f, Average FPS:% 4.2f\n\n', mean_precision, fps)
if nargout > 0 %nargout代表输出的参数
precision = mean_precision;
end
isempty判断里面是否为空集,空集输出为0,非空输出为1
case 'benchmark'
%running in benchmark mode - this is meant to interface easily
%with the benchmark's code. 在基准测试模式下运行 - 这意味着可以轻松地与基准测试代码进行交互。
%get information (image file names, initial position, etc) from
%the benchmark's workspace variables 从基准的工作区变量中获取信息(图像文件名、初始位置等
seq = evalin('base', 'subS'); %evalin函数用于引入工作区变量base是工作空间,subs是表达式
target_sz = seq.init_rect(1,[4,3]);
pos = seq.init_rect(1,[2,1]) + floor(target_sz/2); % y = floor(x) 函数将x中元素取整,值y为不大于本身的最小整数。
% 对于复数,分别对实部和虚部取整
img_files = seq.s_frames; %序列帧
video_path = []; %用来储存矩阵或者向量
%call tracker function with all the relevant parameters 使用所有相关参数调用跟踪器函数
[positions,rect_results,t]= tracker(video_path, img_files, pos, target_sz, ...
padding, kernel, lambda, output_sigma_factor, interp_factor, ...
cell_size, features, 0);
%return results to benchmark, in a workspace variable 在工作区变量中将结果返回到基准测试
rects =rect_results;
% [positions(:,2) - target_sz(2)/2, positions(:,1) - target_sz(1)/2];
% rects(:,3) = target_sz(2);
% rects(:,4) = target_sz(1);
res.type = 'rect';
res.res = rects;
assignin('base', 'res', res); %base是工作空间,res是变量名,res是新的值
%assignin与evalin可以实现不同m文件主函数与子函数的工作空间变量的共存
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(video_path, img_files, pos, target_sz, ...
padding, kernel, lambda, output_sigma_factor, interp_factor, ...
cell_size, features, show_visualization);
%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; %numel用于给出图像的像素数
fprintf('%12s - Precision (20px):% 1.3f, FPS:% 4.2f\n', video, precisions(20), fps)
%fprintf可以将数据写入指定的文本文件中
if nargout > 0
%return precisions at a 20 pixels threshold 以 20 像素阈值返回精度
precision = precisions(20);
end
end
end