資源簡介
均值漂移目標跟蹤算法,選定目標后,一直跟蹤目標
代碼片段和文件信息
function?TargetTracking()
%?第一幀用鼠標選擇要跟蹤的物體
%?人為選擇要跟蹤的目標,雙擊后開始跟蹤
original=imread(‘Car_Data/car001.bmp‘);
figure(1)imshow(original);
[temprect]=imcrop(original);
[ab]=size(temp);
%目標中心坐標
y(1)=a/2;
y(2)=b/2;
m_wei=zeros(ab);%權值矩陣
h=y(1)^2+y(2)^2?;%帶寬
%?計算權值矩陣
for?i=1:a
????for?j=1:b
????????dist=(i-y(1))^2+(j-y(2))^2;
????????m_wei(ij)=1-dist/h;?
????end
end
%?歸一化系數
C=1/sum(sum(m_wei));
%計算目標權值直方圖
hist1=zeros(14096);
for?i=1:a
????for?j=1:b???
????????quantify=fix(double(temp(ij))/16);
????????q_temp=quantify*16;
????????hist1(q_temp+1)=?hist1(q_temp+1)+m_wei(ij);%計算直方圖統計中每個像素點占的權重
????end
end
hist1=hist1*C;
rect(3)=ceil(rect(3));%向離它最近的大整數圓整
rect(4)=ceil(rect(4));
jishu=0;
%?讀取序列圖像
?for?i=1:100;
???????Im=imread([‘Car_Data/car‘fullname(i)‘.bmp‘]);?
???????jishu=jishu+1;
???????num=0;
???????Y=[22];
???????tic
???????%?mean?shift迭代
????while((Y(1)^2+Y(2)^2>0.5)?&&?num<20)???%迭代條件
????????num=num+1;
???????temp1=imcrop(Imrect);?
???????%?計算侯選區域直方圖???????????????????????????????????????????????????????????????????????????????????????????????????????
???????hist2=zeros(14096);
???????for?i=1:a
?????????for?j=1:b
????????????quantify1=fix(double(temp1(ij))/16);
????????????q_temp1(ij)=quantify1*256;
????????????hist2(q_temp1(ij)+1)=?hist2(q_temp1(ij)+1)+m_wei(ij);
?????????end
???????end
???????hist2=hist2*C;
???????w=weights(hist1hist2);
????????%變量初始化
????????sum_w=0;
????
評論
共有 條評論