这是我自己的跟踪算法
%%******************************************* 实验设置 *********************************************%%
clc;
clear all;
%%******Change 'title' to choose the sequence you wish to run******%%
%title = 'animal';
% title = 'board';
% title = 'car11';
%title = 'caviar';
title = 'faceocc2';
% title = 'girl';
% title = 'jumping';
% title = 'panda';
% title = 'shaking';
% title = 'singer1';
% title = 'stone';
%*************************************************************
addpath('./Affine Sample Functions');
trackparam; % 初始位置和仿射参数
opt.tmplsize = [32 32]; % [高度 宽度] opt:初始参数
sz = opt.tmplsize; %sz: 跟踪框的大小
n_sample = opt.numsample;
param0 = [p(1), p(2), p(3)/sz(2), p(5), p(4)/p(3), 0]; %param: 仿射参数 param0: 最初的仿射参数
p0 = p(4)/p(3); %p0:aspect ratio in the first frame?在第一帧中的从横比?
param0 = affparam2mat(param0); %转换仿射参数?((2x3矩阵))
param = [];
param.est = param0';
%%****************** 为判别分类器获得获得正负模板*******************%%
num_p = 50; % 正模板数量
num_n = 200; % 负模板数量
[A_poso A_nego] = affineTrainG(dataPath, sz, opt, param, num_p, num_n, forMat, p0);
A_pos = A_poso;
A_neg = A_nego;
patchsize = [6 6]; % obtain the dictionary for the SGM?为生成模型获得字典?
patchnum(1) = length(patchsize(1)/2 : 2: (sz(1)-patchsize(1)/2));
patchnum(2) = length(patchsize(2)/2 : 2: (sz(2)-patchsize(2)/2));
Fisize = 50;
[Fio patcho] = affineTrainL(dataPath, param0, opt, patchsize, patchnum, Fisize, forMat);
Fi = Fio;
temp = importdata([dataPath 'datainfo.txt']); %DataInfo: 宽度, 高度, 帧数
num = temp(3); %总的帧数
paramSR.lambda2 = 0; %?optional, elastic-net parameter, 0 by default可选的、弹性网络、默认为0
paramSR.mode = 2; %?(optional, adds positivity constraints on the coefficients, , by default: 2)
alpha_p = zeros(Fisize, prod(patchnum), num); %输出系数?
result = zeros(num, 6);
%%******************************************* 跟踪 *********************************************%%
for f = 1:num
f %框架比
img_color = imread([dataPath int2str(f) forMat]); %载入第一帧
if size(img_color,3)==3
img = rgb2gray(img_color); %将彩色图片转为灰色图片
else
img = img_color; %灰色图片
end
%%----------------- 基于稀疏的判别分类器 (SDC) ----------------%%
gamma = 0.4;
[wimgs Y param] = affineSample(double(img), sz, opt, param); % draw N candidates with particle filter
%得出N个粒子滤波的候选目标
YY = normVector(Y); % 归一化
AA_pos = normVector(A_pos); %归一化正模板
AA_neg = normVector(A_neg); %归一化负模板
%%-----------------% 特征选择 ----------------%%
P = selectFeature(AA_pos, AA_neg, paramSR); % 获得投影矩阵
YYY = P'*YY; % project the original feature space to the selected feature space
%把原特征空间投影到选择特征空间
AAA_pos = P'*AA_pos;
AAA_neg = P'*AA_neg;
paramSR.L = length(YYY(:,1)); % represent each candidate with training template set代表每一个候选训练模板集
%(param.L :optional, maximum number of elements of each decomposition)
paramSR.lambda = 0.01;
beta = mexLasso(YYY, [AAA_pos AAA_neg], paramSR);
beta = full(beta);
rec_f = sum((YYY - AAA_pos*beta(1:size(AAA_pos,2),:)).^2); % the confidence value of each candidate
rec_b = sum((YYY - AAA_neg*beta(size(AAA_pos,2)+1:end,:)).^2);
con = exp(-rec_f/gamma)./exp(-rec_b/gamma);
%%----------------- Collaborative Model ----------------%%
likelihood = con;%似然函数
[v_max,id_max] = max(likelihood);
param.est = affparam2mat(param.param(:,id_max));
result(f,:) = param.est';
displayResult_sf; % 显示在每一帧的跟踪结果
%%----------------- 更新方案 ----------------%%
upRate = 6; %每隔6帧更新负模板集
if rem(f, upRate)==0
[A_neg] = updateDic(dataPath, sz, opt, param, num_n, forMat, p0, f);
end
end
%%******************************************* 保存并显示跟踪结果 *********************************************%%
save([ title '.mat'], 'result');
要怎么才能把这个算法和IVT/IPCA Tracker、L1 Tracker、PN Tracker、VTD Tracker、MIL Tracker、Frag Tracker进行比较显示出这样的效果
Girl_rs_0062.jpg (37.58 KB, 下载次数: 8)
2015-5-22 22:11 上传