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

답변 (1개)

Tawakal
Tawakal 2013년 10월 13일

0 개 추천

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.

질문:

2013년 9월 2일

댓글:

2019년 6월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by