Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc %clears command line window
- clear all; %clears variables
- close all; %closes all figures
- 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);
- NET.addAssembly('System.Speech');
- obj = System.Speech.Synthesis.SpeechSynthesizer;
- obj.Volume = 100;
- % Speak(obj, string);
- end
- function start_cb(hObj,~)
- cam=webcam('Integrated Webcam');
- while true
- if ~isvalid(hObj); break; end
- handles=guidata(hObj);
- if handles.run==1
- disp('running')
- e=cam.snapshot;
- 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_bEyes=step(FDetect,I);
- imshow(I);
- hold on;
- FDetect=vision.CascadeObjectDetector('EyePairSmall','MergeThreshold',1);
- I=e;
- BB_sEyes=step(FDetect,I);
- imshow(I);
- if(sum(sum(BB_bEyes))==0&&sum(sum(BB_sEyes))==0)
- speak('Face not detected');
- elseif(sum(sum(BB_Nose))==0 && sum(sum(BB_Mouth))==0)
- FDetect=vision.CascadeObjectDetector('FrontalFaceLBP','MergeThreshold',10);
- BB_hand=step(FDetect,I);
- if(sum(sum(BB_hand))~=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