smoke detection, fix problem

hi, this code must detect smoke in the video and alarm will active, but the warning active for all videos, even the videos do not smoke. how do i 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+g+b)/3;
S=(abs(r-avg)+abs(b-avg)+abs(g-avg))/3;
if (S<astn)
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

Answers (1)

Tawakal
Tawakal on 13 Oct 2013
Dear Ehsan I think it will be good if you post the videos that has been used in the code as well along with the complete code (means GUI).Only after that anyone will be able to help you.

Asked:

on 2 Sep 2013

Commented:

on 25 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!