-
大小: 8.86MB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-10-12
- 語言: 其他
- 標(biāo)簽: 均值漂移??目標(biāo)跟蹤??
資源簡介
用均值漂移算法實現(xiàn)目標(biāo)跟蹤,均值漂移算法是一種基于核函數(shù)估計的無參數(shù)算法,它無需估計整個區(qū)間的概率密度也無需知道區(qū)間內(nèi)樣本的分布情況,由于其具有較低的計算量,且計算速度快,抗干擾能力強在解決計算機視覺領(lǐng)域尤其是目標(biāo)跟蹤方面表現(xiàn)出了良好的魯棒性和實時性。

代碼片段和文件信息
%配套論文《基于MeanShift算法的目標(biāo)跟蹤算法研究》?P28-29
function?[]?=?select()
close?all;
clear?all;
%%%%%%%%%%%%%%%%%%根據(jù)一幅目標(biāo)全可見的圖像圈定跟蹤目標(biāo)%%%%%%%%%%%%%%%%%%%%%%%
I=imread(‘result72.jpg‘);
figure(1);
imshow(I);
[temprect]=imcrop(I);
[abc]=size(temp);? %a:rowb:col
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%計算目標(biāo)圖像的權(quán)值矩陣%%%%%%%%%%%%%%%%%%%%%%%
y(1)=a/2;
y(2)=b/2;
tic_x=rect(1)+rect(3)/2;
tic_y=rect(2)+rect(4)/2;
m_wei=zeros(ab);%權(quán)值矩陣
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;?%epanechnikov?profile
????end
end
C=1/sum(sum(m_wei));%歸一化系數(shù)
%計算目標(biāo)權(quán)值直方圖qu
%hist1=C*wei_hist(tempm_weiab);%target?model
hist1=zeros(14096);
for?i=1:a
????for?j=1:b
????????%rgb顏色空間量化為16*16*16?bins
????????q_r=fix(double(temp(ij1))/16);??%fix為趨近0取整函數(shù)
????????q_g=fix(double(temp(ij2))/16);
????????q_b=fix(double(temp(ij3))/16);
????????q_temp=q_r*256+q_g*16+q_b;????????????%設(shè)置每個像素點紅色、綠色、藍(lán)色分量所占比重
????????hist1(q_temp+1)=?hist1(q_temp+1)+m_wei(ij);????%計算直方圖統(tǒng)計中每個像素點占的權(quán)重
????end
end
hist1=hist1*C;
rect(3)=ceil(rect(3));
rect(4)=ceil(rect(4));
%%%%%%%%%%%%%%%%%%%%%%%%%讀取序列圖像
myfile=dir(‘D:\matlab7\work\mean?shift\image\*.jpg‘);
lengthfile=length(myfile);
for?l=1:lengthfile
????Im=imread(myfile(l).name);
????num=0;
????Y=[22];
????
????
????%%%%%%%mean?shift迭代
????while((Y(1)^2+Y(2)^2>0.5)&num<20)???%迭代條件
????????num=num+1;
????????temp1=imcrop(Imrect);
????????%計算侯選區(qū)域直方圖
????????%hist2=C*wei_hist(temp1m_weiab);%target?candidates?pu
????????hist2=zeros(14096);
????????for?i=1:a
????????????for?j=1:b
????????????????q_r=fix(double(temp1(ij1))/16);
????????????????q_g=fix(double(temp1(ij2))/16);
????????????????q_b=fix(double(temp1(ij3))/16);
????????????????q_temp1(ij)=q_r*256+q_g*16+q_b;
????????????????hist2(q_temp1(ij)+1)=?hist2(q_temp1(ij)+1)+m_wei(ij);
????????????end
????????end
????????hist2=hist2*C;
????????figure(2);
????????subplot(121);
????????plot(hist2);
????????hold?on;
????????
????????w=zeros(14096);
????????for?i=1:4096
????????????if(hist2(i)~=0)?%不等于
????????????????w(i)=sqrt(hist1(i)/hist2(i));
????????????else
????????????????w(i)=0;
????????????end
????????end
????????
????????
????????
????????%變量初始化
????????sum_w=0;
????????xw=[00];
????????for?i=1:a;
????????????for?j=1:b
????????????????sum_w=sum_w+w(uint32(q_temp1(ij))+1);
????????????????xw=xw+w(uint32(q_temp1(ij))+1)*[i-y(1)-0.5j-y(2)-0.5];
????????????end
????????end
????????Y=xw/sum_w;
????????%中心點位置更新
????????rect(1)=rect(1)+Y(2);
????????rect(2)=rect(2)+Y(1);
????end
????
????
????%%%跟蹤軌跡矩陣%%%
????tic_x=[tic_x;rect(1)+rect(3)/2];
????tic_y=[tic_y;rect(2)+rect(4)/2];
????
????v1=rect(1);
????v2=rect(2);
????v3=rect(3);
????v4=rect(4);
????%%%顯示跟蹤結(jié)果%%%
????subplot(122);
????imshow(uint8(Im));
????title(‘目標(biāo)跟蹤結(jié)果及其運動軌跡‘);
????hold?on;
????plot([v1v1+v3][v2v2][v1v1][v2v2+v4][v1v1+v3][v2+v
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????53586??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result100.jpg
?????文件??????53682??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result101.jpg
?????文件??????51480??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result73.jpg
?????文件??????52668??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result74.jpg
?????文件??????53206??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result75.jpg
?????文件??????53078??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result76.jpg
?????文件??????53577??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result77.jpg
?????文件??????54160??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result78.jpg
?????文件??????53735??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result79.jpg
?????文件??????53948??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result80.jpg
?????文件??????54540??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result81.jpg
?????文件??????54054??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result82.jpg
?????文件??????52994??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result83.jpg
?????文件??????49604??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result84.jpg
?????文件??????50696??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result85.jpg
?????文件??????51384??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result86.jpg
?????文件??????52733??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result87.jpg
?????文件??????52758??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result88.jpg
?????文件??????53308??2014-06-11?23:19??Meanshift\Meanshift\matlab\image\result89.jpg
?????文件??????53722??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result90.jpg
?????文件??????53366??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result91.jpg
?????文件??????53468??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result92.jpg
?????文件??????54035??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result93.jpg
?????文件??????52586??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result94.jpg
?????文件??????52189??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result95.jpg
?????文件??????49294??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result96.jpg
?????文件??????51386??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result97.jpg
?????文件??????52663??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result98.jpg
?????文件??????53380??2014-06-11?23:14??Meanshift\Meanshift\matlab\image\result99.jpg
?????文件???????3310??2014-06-12?11:29??Meanshift\Meanshift\matlab\meanshift.m
............此處省略37個文件信息
- 上一篇:銷售系統(tǒng)web
- 下一篇:《深入淺出Node.js》(高清版)
評論
共有 條評論