OpenTLD源码解析(2)-学习部分分析

1.得到Pattern

上程序,没有什么解释的

bb    = tld.bb(:,I); % current bounding box
img   = tld.img{I}; % current image

% Check consistency -------------------------------------------------------

pPatt  = tldGetPattern(img,bb,tld.model.patchsize); % get current patch
[pConf1,~,pIsin] = tldNN(pPatt,tld); % measure similarity to model

2.确定是否需要学习

上程序,没有什么解释的

if pConf1 < 0.5, disp('Fast change.'); tld.valid(I) = 0; return; end % too fast change of appearance
if var(pPatt) < tld.var, disp('Low variance.'); tld.valid(I) = 0; return; end % too low variance of the patch
if pIsin(3) == 1, disp('In negative data.'); tld.valid(I) = 0; return; end % patch is in negative data

3.产生正样本

正样本数据有两种,一种是Pattern,即pEx,用于计算Conf;另一种是用于检测模块特征向量维数为10,这些数据可以更改

检测模块的模型参数。

overlap  = bb_overlap(bb,tld.grid); % measure overlap of the current bounding box with the bounding boxes [pX,pEx] = tldGeneratePositiveData(tld,overlap,img,tld.p_par_update); % generate positive examples from all
pY       = ones(1,size(pX,2)); % labels of the positive patches

核心函数为tldGeneratePositiveData,以下对其进行分析

tld.p_par_update是控制产生正要本数据的参数

image

idxP = find(overlap > 0.6);

对其进行排序后

bbP  = tld.grid(:,idxP);

bbP0是overlap值最大的一个,由此得到pattern

pEx = tldGetPattern(im1,bbP0,tld.model.patchsize);

检测模块需要的正特征就是overlap值最大的前10个bb,对其抽取特征,再对其循环num_warps次。每次循环根据

image

改变图像。

抽取特征的函数是由c写的,具体参考特征检测部分。

pX  = [pX fern(5,im1,idxP,0)];

pX为10X100的矩阵;

其im1的范围是由以下代码产生的

bbH  = bb_hull(bbP);
cols = bbH(1):bbH(3);
rows = bbH(2):bbH(4);

4.产生负样本

image

for (int i = 0; i < nTREES; i++) {
    int idx = measure_tree_offset(blur,idx_bbox,i);
    tPatt[i] = idx;
    conf += WEIGHT[i][idx];
}
return conf;

负样本

这个是用于更新检测模块参数的数据,选择的标准就是低overlap值和检测模块判断为正样本的数据

idx = overlap < tld.n_par.overlap & tld.tmp.conf >= 1;

 

从检测出来的bb中,挑选出重叠度小于阈值的,用于conf生成

overlap  = bb_overlap(bb,tld.dt{I}.bb);

nEx = tld.dt{I}.patch(:,overlap < tld.n_par.overlap);

 

训练模型

fern(2,[pX tld.tmp.patt(:,idx)],[pY zeros(1,sum(idx))],tld.model.thr_fern,2);

 

% Positive
if y(i) == 1 && conf1 <= tld.model.thr_nn % 0.65
    if isnan(isin(2))
        tld.pex = x(:,i);
        continue;
    end
     %if isin(2) == size(tld.pex,2)
       %tld.pex = [tld.pex x(:,i)];
     %else
     tld.pex = [tld.pex(:,1:isin(2)) x(:,i) tld.pex(:,isin(2)+1:end)]; % add to model
     %end
end

% Negative
if y(i) == 0 && conf1 > 0.5
    tld.nex = [tld.nex x(:,i)];
end

 

 

image

posted @ 2014-02-19 19:44  gghost  阅读(800)  评论(0编辑  收藏  举报