Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all;
- close all;
- handles.fig=figure;
- handles.pb1=uicontrol('style','pushbutton','position',[150 10 80 40],'callback',@start_cb,'string','Start');
- handles.pb2=uicontrol('style','pushbutton','position',[250 10 80 40],'callback',@stop_cb,'string','Stop');
- handles.pb3=uicontrol('style','pushbutton','position',[350 10 80 40],'callback',@pause_cb,'string','pause');
- handles.run=1;
- guidata(handles.fig,handles)
- function speak(string)
- title(string);
- defaultString = string;
- NET.addAssembly('System.Speech');
- obj = System.Speech.Synthesis.SpeechSynthesizer;
- obj.Volume = 100;
- Speak(obj, defaultString);
- end
- function start_cb(hObj,~)
- cam=webcam(1);
- while true
- if ~isvalid(hObj); break; end
- handles=guidata(hObj);
- if handles.run==1
- disp('running')
- e=cam.snapshot;
- % e=imlocalbrighten(e);
- FDetect=vision.CascadeObjectDetector('Mouth','MergeThreshold',100);
- I=e;
- BB_Mouth=step(FDetect,I);
- imshow(I);
- hold on;
- %%
- FDetect=vision.CascadeObjectDetector('Nose','MergeThreshold',16);
- I=e;
- BB_Nose=step(FDetect,I);
- imshow(I);
- hold on;
- %%
- FDetect=vision.CascadeObjectDetector('EyePairBig','MergeThreshold',1);
- I=e;
- BB_Eyes=step(FDetect,I);
- imshow(I);
- hold on;
- if(sum(sum(BB_Eyes))==0)
- speak('Face not detected');
- elseif(sum(sum(BB_Nose))==0 && sum(sum(BB_Mouth))==0)
- FDetect=vision.CascadeObjectDetector('FrontalFaceLBP','MergeThreshold',10);
- BB_Mouth=step(FDetect,I);
- if(sum(sum(BB_Mouth))~=0)
- speak('Remove Hand from face.');
- else
- speak('Thank You for wearing Mask.');
- end
- elseif((sum(sum(BB_Nose))~=0 && sum(sum(BB_Mouth))==0)||(sum(sum(BB_Nose))==0 && sum(sum(BB_Mouth))~=0))
- for i=1:size(BB_Nose,1)
- rectangle('Position',BB_Nose(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
- end
- for i=1:size(BB_Mouth,1)
- rectangle('Position',BB_Mouth(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
- end
- speak( 'Please wear mask properly.');
- else
- for i=1:size(BB_Nose,1)
- rectangle('Position',BB_Nose(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
- end
- for i=1:size(BB_Mouth,1)
- rectangle('Position',BB_Mouth(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
- end
- speak( 'Please wear Mask.')
- end
- pause(1)
- else
- handles.run=1;
- guidata(hObj,handles)
- disp('paused')
- break
- end
- end
- end
- function stop_cb(hObj,~)
- handles.run=0;
- guidata(hObj,handles)
- close all;
- clc;
- clear all;
- end
- function pause_cb(hObj,~)
- handles.run=0;
- guidata(hObj,handles)
- title('Paused');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement