資源簡介
基于幀差法的運動目標檢測的matlab代碼,先讀取avi視頻,提取每幀圖片,進行目標跟蹤。
代碼片段和文件信息
mov=aviread(‘nomal.avi‘);
temp=size(mov);?
fnum=temp(2);
for?i=1:fnum
????strtemp=strcat(int2str(i)‘.‘‘JPG‘);
????imwrite(mov(i).cdata(:::)strtemp);
end%%??從視頻中提出每一幀圖像
o=1;
e=‘.jpg‘;
for?i=1:15
????u=o-1;v=o-2;
????m=int2str(o);
????n=int2str(u);h=int2str(v);
????s=strcat(me);%%把字符串b與m連接后在連接e得到圖像文件存儲的位置
????m=imread(s);%%從S處把圖像讀取出來
????m=rgb2gray(m);%%將圖像M灰度化
???
m=medfilt2(m[33]);
if(o>=3)
????????s=strcat(ne);
????????n=imread(s);
????????n=rgb2gray(n);
????????s=strcat(he);
????????h=imread(s);
????????h=rgb2gray(h);
????????
????????n=medfilt2(n[33]);
????????h=medfilt2(h[33]);
????????q=im2double(m);%%將圖像數組轉換為double型
????????w=im2double(n);?g=im2double(h);
????????c=q-w;j=w-g;
????????
????????th=10/255;
????????
????????k=find(abs(c)>=th);
????????c(k)=1;
????????k=find(abs(c) ????????c(k)=0;??
????????c=bwareaopen(c15);
??????????
????????se90=strel?(‘line‘390);se0=strel?(‘line‘30);
???????
????????c=bwmorph(c‘close‘
評論
共有 條評論