來源:CsdnWujinming 發(fā)布時間:2019-04-26 15:54:58 閱讀量:1311
main_running.m
addpath('./util');%添加util路徑
addpath(('D:\Document\20190415-0422\vlfeat-0.9.20-bin\vlfeat-0.9.20\toolbox'));%添加vlfeat工具路徑
vl_setup%安裝vlfeat
addpath(('./rstEval'));%添加rstEval路徑
addpath(['./trackers/VIVID_Tracker'])
seqs=configSeqs;%讀取測試集序列文件,configSeqs中保存圖片位置等信息
trackers=configTrackers;%讀取跟蹤器信息,包括跟蹤器程序入口
shiftTypeSet = {'left','right','up','down','topLeft','topRight','bottomLeft','bottomRight','scale_8','scale_9','scale_11','scale_12'};%變換類型
evalType='OPE'; %'OPE','SRE','TRE'%評估指標
diary(['./tmp/' evalType '.txt']);
numSeq=length(seqs);%視頻個數(shù)
numTrk=length(trackers);%評估的跟蹤器個數(shù)
finalPath = ['./results/results_' evalType '_CVPR13/'];%結果保存目錄
if ~exist(finalPath,'dir')
mkdir(finalPath);
end
%結果目標是否存在
tmpRes_path = ['./tmp/' evalType '/'];
bSaveImage=0;%跟蹤的圖片是否保存
if ~exist(tmpRes_path,'dir')
mkdir(tmpRes_path);
end
pathAnno = './anno/';%測試的注釋目錄
for idxSeq=1:length(seqs)%對于每個視頻,調(diào)用不同跟蹤器
s = seqs{idxSeq};%保存第i個視頻信息
s.len = s.endFrame - s.startFrame + 1;%視頻總幀數(shù)
s.s_frames = cell(s.len,1);%保存視頻幀圖片地址
nz = strcat('%0',num2str(s.nz),'d'); %number of zeros in the name of image
for i=1:s.len%對于視頻每一幀
image_no = s.startFrame + (i-1);%當前幀索引i
id = sprintf(nz,image_no);
s.s_frames{i} = strcat(s.path,id,'.',s.ext);%第i幀圖片路徑
end
img = imread(s.s_frames{1});%讀取第1幀圖片
[imgH,imgW,ch]=size(img);%圖片寬高
rect_anno = dlmread([pathAnno s.name '.txt']);%當前視頻序列的注釋文件
numSeg = 20;
[subSeqs, subAnno]=splitSeqTRE(s,numSeg,rect_anno);%考慮時間魯棒性,將圖片序列分成20個片段
switch evalType
case 'SRE'%評估空間魯棒性
subS = subSeqs{1};
subA = subAnno{1};
subSeqs=[];
subAnno=[];
r=subS.init_rect;
for i=1:length(shiftTypeSet)
subSeqs{i} = subS;
shiftType = shiftTypeSet{i};
subSeqs{i}.init_rect=shiftInitBB(subS.init_rect,shiftType,imgH,imgW);%將初始框做相應變換
subSeqs{i}.shiftType = shiftType;%記錄變換類型
subAnno{i} = subA;
end
case 'OPE'
subS = subSeqs{1};
subSeqs=[];
subSeqs{1} = subS;
subA = subAnno{1};
subAnno=[];
subAnno{1} = subA;
otherwise
end
for idxTrk=1:numTrk%對所有跟蹤器計算結果
t = trackers{idxTrk};%第t個跟蹤器索引
% validate the results
if exist([finalPath s.name '_' t.name '.mat'])
load([finalPath s.name '_' t.name '.mat']);
bfail=checkResult(results, subAnno);
if bfail
disp([s.name ' ' t.name]);
end
continue;
end
switch t.name
case {'VTD','VTS'}
continue;
end
results = [];
for idx=1:length(subSeqs)
disp([num2str(idxTrk) '_' t.name ', ' num2str(idxSeq) '_' s.name ': ' num2str(idx) '/' num2str(length(subSeqs))])%第idxTrk個跟蹤器在第idxSeq個序列上第idx個片段的跟蹤
rp = [tmpRes_path s.name '_' t.name '_' num2str(idx) '/'];%檢測結果圖片保存路徑
if bSaveImage&~exist(rp,'dir')
mkdir(rp);
end
subS = subSeqs{idx};
subS.name = [subS.name '_' num2str(idx)];
funcName = ['res=run_' t.name '(subS, rp, bSaveImage);'];%調(diào)用跟蹤器命令串
try
switch t.name
case {'VR','TM','RS','PD','MS'}
otherwise
cd(['./trackers/' t.name]);
addpath(genpath('./'))
end
eval(funcName);%解析執(zhí)行調(diào)用跟蹤器命令
switch t.name
case {'VR','TM','RS','PD','MS'}
otherwise
rmpath(genpath('./'))
cd('../../');
end
if isempty(res)
results = [];
break;
end
catch err
disp('error');
rmpath(genpath('./'))
cd('../../');
res=[];
continue;
end
res.len = subS.len;
res.annoBegin = subS.annoBegin;
res.startFrame = subS.startFrame;
switch evalType
case 'SRE'
res.shiftType = shiftTypeSet{idx};
end
results{idx} = res;
end
save([finalPath s.name '_' t.name '.mat'], 'results');%保存結果
end
end