Friday 30 August 2013

I'm in a video image smoke detection

I'm in a video image smoke detection

This code must detect smoke in the video, will activate the warning
system, but the problem is that all the videos warns, even those who do
not smoke. Can someone help me to fix it?
vid=uigetfile;
vid=mmreader(vid);
numFrames = vid.NumberOfFrames;
n=numFrames;
for i =1:n
frames = read(vid,i);
imwrite(frames,[int2str(i) '.jpg']);
end
frm1=rgb2gray(imread('1.jpg'));
for j=1:n
frm2=([num2str(j),'.jpg']);
p1=(imread(frm2,'jpg'));
p2=(rgb2gray(p1));
res=abs(double(p2)-double(frm1));
astn=get(handles.edt,'string');
astn=str2num(astn);
ast=res<astn;
bw=bwareaopen(ast,500);
R=p1(:,:,1);
G=p1(:,:,2);
B=p1(:,:,3);
xr=R(bw);
r=mean(xr);
xg=G(bw);
g=mean(xg);
xb=B(bw);
b=mean(xb);
avg=(r+b+g);
S=(abs(r-avg)+abs(b-avg)+abs(g-avg))/3;
if (S>200)
set(handles.text1,'visible','on');
beep
subplot(211)
h1 = image;
axis ij
imshow(p1,h1);
pause(0.5);
set(handles.text1,'visible','off');
pause(0.5);
end;
end

No comments:

Post a Comment