基于帧差法的运动目标检测的matlab代码

基于帧差法的运动目标检测的matlab代码
基于帧差法的运动目标检测的matlab代码

mov二avireadCCIMG0003.AVI');

temp二size(mov);

fnum二temp(2);

for i=1:fnum,

strtemp=strcat(i nt2str(i),'.','JPG');

imwrite(mov(i).cdata(:,:,:),strtemp);

en d%%从视频中提出每一帧图像

o=1;

e='.jpg:

for i=1:15

u=o-1;v=o-2;

m=i nt2str(o);

n=i nt2str(u);h=i nt2str(v);

s=strcat(m,e);%%把字符串b与m连接后在连接e得到图像文件存储的位置

m=imread(s);%%从S处把图像读取出来

m=rgb2gray(m);%%将图像M灰度化

m=medfilt2(m,[3,3]);

if(o>=3)

s=strcat( n,e);

n=im read(s);

n=rgb2gray(n);

s=strcat(h,e);

h=imread(s);

h=rgb2gray(h);

n=medfilt2(n,[3,3]);

h=medfilt2(h,[3,3]);

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(c,15);

se90=strel ('line',3,90);se0=strel ('line',3,0);

c=bwmorph(c,'close'); %对上述图像进行形态学闭运算

c=imdilate(c,[se90,se0]);c=bwmorph(c,'close');

c=bwareaopen(c,50);

k=find(abs(j)>=th);

j(k)=1;

k=find(abs(j)

j(k)=0;

j=bwareaopen(j,15);

j=bwmorph(j,'close'); % 对上述图像进行形态学闭运算

j=imdilate(j,[se90,se0]);j=bwmorph(j,'close');

c=bwareaopen(c,50);

c=c&j;c=imerode(c,[se90,se0]);

figure,imshow(c);

a=c;b=c; d=c;f=c;

[m,n]=size(c);

%%行扫描填充

for i=1:m

for j=1:n-1

if a(i,j)>0 a(i,j+1)=1;

end

end

end

for i=1:m

for j=n:-1:2

if b(i,j)>0

b(i,j-1)=1;

end

end

end th=a&b; %%列扫描填充

for i=1:n

for j=1:m-1 if d(j,i)>0 d(j+1,i)=1;

end

end

end

for i=1:n

for j=m:-1:2 if f(j,i)>0 f(j-1,i)=1;

end

end

end

td=d&f;

c=th&td;

end

o=o+1;

相关主题
相关文档
最新文档