天天看點

【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真

1.軟體版本

matlab2013b

測試視訊圖檔序列庫

【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真

2.本算法理論知識

TLD是一種對視訊中未知目标進行長期跟蹤而設計的算法結構。它的結構如圖1-1所示

【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真

算法的結構如下:1.關于跟蹤器(tracker),在假設幀與幀之間(目标物體)運動是有限的,并且目标是可見的的情況下,跟蹤器(采用的是光流法)估計目标的運動狀況(即接下來的位置)。但是跟蹤器會在目标跑出攝像頭拍攝範圍時失敗,并且永遠不可能恢複。2.關于檢測器(detector),檢測器對每一幀都獨立的對待,并且對每一幀圖像進行掃描,找出所有過去(算法運作開始後到目前時刻)已經被觀測和學習過和目标具有類似模樣的所在區域(這句翻譯的不好,原文:Detector treats every frame as independent and performs full scanning of the image to localize all appearances that have been observed and learned in the past.)。對于任何的檢測器,都有可能發生兩個類型的錯誤:假的正樣本和假的負樣本。3.關于學習子產品(learning)。學習子產品根據跟蹤子產品的結果對檢測子產品的這兩種錯誤進行評估,并根據評估結果生成訓練樣本對檢測子產品的目标模型進行更新,同時對跟蹤子產品的“關鍵特征點”進行更新,以此來避免以後出現類似的錯誤。

這一部分介紹

TLD

算法的學習子產品,學習子產品(

learning

)通過對視訊的線上處理來提升檢測器(

detector

)的性能。在每一幀裡,我們希望評估目前的檢測器,發現它産生的錯誤(

identify its errors

),不斷更新檢測器以避免将來它再次犯錯。

PN

學習的關鍵思想是檢測器産生的錯誤結果可以被“

P

專家”和“

N

專家”發現和識别。

P

專家識别假的負樣本,

N

專家識别假的正樣本。當然

P

專家和

N

專家本身也會犯錯。然而,

P

專家和

N

專家是互相獨立的,它們可以互相彌補對方發生的錯誤。

P

專家發生的錯誤,

N

專家糾正,反之亦然。

下面對

PN

學習進行标準數學化。

TLD

子產品的詳細;流程框圖如下所示

【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真

•PN學習包含四個部分:(1)一個待學習的分類器;(2)訓練樣本集--一些已知類别标簽的樣本;(3)監督學習--一種從訓練樣本集中訓練分類器的方法;(4)P-N experts--在學習過程中用于産生正(訓練)樣本和負(訓練)樣本的表達函數;

•PN學習最重要的部分是分類器的錯誤估計。關鍵的想法是把假的正樣本和假的負樣本分别獨立的處理。是以,未标記的組會被現有的分類器分為兩類,每一部分由一個獨立的專家分析(P專家或N專家)。

•首先根據一些已有類别标記的樣本,借助監督學習方法來訓練,進而得到一個初始分類器。之後,通過疊代學習,利用上一次疊代得到的分類器對所有的未賦予标簽的樣本資料進行分類,而P-N experts則找出那些錯誤分類的樣本,并依此來對訓練樣本集做出修正,使得下一次疊代訓練之後得到的分類器的性能有所改善。P-experts将那些被分類器标記為負樣本,但根據結構性限制條件應該為正樣本的那些樣本賦予“正”的标簽,并添加到訓練樣本集中;而N-experts則将那些被分類器标記為正樣本,但根據結構性限制條件應該為負樣本的那些樣本賦予“負”的标簽,并添加到訓練樣本集當中;這也就意味着,P-experts增加了分類器的魯棒性,而N-experts則增加了分類器的判别能力。

3.核心代碼

clc;
clear;
close all;
warning off
addpath 'New_function\Tracking\'
addpath 'New_function\detector\'
addpath 'New_function\learn\'
addpath 'tld\initial\'
addpath 'tld\'


isNew    = 1 ;%0為原始TLD,1為改進TLD
isSpeed  = [isNew;isNew;0];%加速,慢速,分别對三個部分,跟蹤,檢測,學習進行加速
CJ       = 2;%設定仿真場景

addpath(genpath('.')); init_workspace; 

opt.source          = struct('camera',0,'input',['input',num2str(CJ),'/'],'bb0',[]); % camera/directory swith, directory_name, initial_bounding_box (if empty, it will be selected by the user)
opt.output          = '_output/'; mkdir(opt.output); % output directory that will contain bounding boxes + confidence

%最小窗,要根據場景的目标大小設定過才,
if CJ == 1
   min_win = 36; % minimal size of the object's bounding box in the scanning grid, it may significantly influence speed of TLD, set it to minimal size of the object
end
if CJ == 2
   min_win = 9; % minimal size of the object's bounding box in the scanning grid, it may significantly influence speed of TLD, set it to minimal size of the object
end
patchsize           = [15 15]; % size of normalized patch in the object detector, larger sizes increase discriminability, must be square
fliplr              = 0; % if set to one, the model automatically learns mirrored versions of the object
maxbbox             = 1; % fraction of evaluated bounding boxes in every frame, maxbox = 0 means detector is truned off, if you don't care about speed set it to 1
update_detector     = 1; % online learning on/off, of 0 detector is trained only in the first frame and then remains fixed
opt.plot            = struct('pex',0,'nex',0,'dt',0,'confidence',1,'target',0,'replace',0,'drawoutput',3,'draw',0,'pts',0,'help', 0,'patch_rescale',1,'save',0); 

% Do-not-change -----------------------------------------------------------

opt.model           = struct('min_win',min_win,'patchsize',patchsize,'fliplr',fliplr,'ncc_thesame',0.95,'valid',0.5,'num_trees',10,'num_features',13,'thr_fern',0.5,'thr_nn',0.65,'thr_nn_valid',0.7);
opt.p_par_init      = struct('num_closest',10,'num_warps',20,'noise',5,'angle',20,'shift',0.02,'scale',0.02); % synthesis of positive examples during initialization
opt.p_par_update    = struct('num_closest',10,'num_warps',10,'noise',5,'angle',10,'shift',0.02,'scale',0.02); % synthesis of positive examples during update
opt.n_par           = struct('overlap',0.2,'num_patches',100); % negative examples initialization/update
opt.tracker         = struct('occlusion',10);
opt.control         = struct('maxbbox',maxbbox,'update_detector',update_detector,'drop_img',1,'repeat',1);

        
% Run TLD -----------------------------------------------------------------
%profile on;
[bb,conf] = tldExample(opt,isNew,isSpeed);
%profile off;
%profile viewer;
centerx=0.5*(bb(1,:)+ bb(3,:));
centery=0.5*(bb(2,:)+ bb(4,:));
% Save results ------------------------------------------------------------
%dlmwrite([opt.output '/tld.txt'],[centerx;centery]');
dlmwrite([opt.output '/tld.txt'],[bb]');
disp('Results saved to ./_output.');
clc;      

4.操作步驟與仿真結論

【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真
【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真
【TLD】改進後的TLD視訊目标跟蹤方法的MATLAB仿真

5.參考文獻