Advertisement
Kali_prasad

v3 fmd with gui

Apr 15th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.88 KB | None | 0 0
  1. clc
  2. clear all;
  3. close all;
  4.  
  5. handles.fig=figure;
  6. handles.pb1=uicontrol('style','pushbutton','position',[150 10 80 40],'callback',@start_cb,'string','Start');
  7. handles.pb2=uicontrol('style','pushbutton','position',[250 10 80 40],'callback',@stop_cb,'string','Stop');
  8. handles.pb3=uicontrol('style','pushbutton','position',[350 10 80 40],'callback',@pause_cb,'string','pause');
  9. handles.run=1;
  10. guidata(handles.fig,handles)
  11. function start_cb(hObj,~)
  12. cam=webcam(1);
  13. while true
  14.     handles=guidata(hObj);
  15.     if handles.run==1
  16.     disp('running')
  17.     e=cam.snapshot;
  18.     FDetect=vision.CascadeObjectDetector('Mouth','MergeThreshold',100);
  19.     I=e;
  20.     BB_Mouth=step(FDetect,I);
  21.     imshow(I);
  22.     hold on;
  23.     %%
  24.     FDetect=vision.CascadeObjectDetector('Nose','MergeThreshold',16);
  25.     I=e;
  26.     BB_Nose=step(FDetect,I);
  27.     imshow(I);
  28.     hold on;
  29.     if(sum(sum(BB_Nose))==0 && sum(sum(BB_Mouth))==0)
  30.     FDetect=vision.CascadeObjectDetector('FrontalFaceLBP','MergeThreshold',10);
  31.     BB_Mouth=step(FDetect,I);
  32.     if(sum(sum(BB_Mouth))~=0)
  33.     title('Remove Hand Please');
  34.     defaultString = 'Remove Hand from face.';
  35.     NET.addAssembly('System.Speech');
  36.     obj = System.Speech.Synthesis.SpeechSynthesizer;
  37.     obj.Volume = 100;
  38.     Speak(obj, defaultString);
  39.     else
  40.     title('Mask Present');
  41.     defaultString = 'Thank You for wearing Mask.';
  42.     NET.addAssembly('System.Speech');
  43.     obj = System.Speech.Synthesis.SpeechSynthesizer;
  44.     obj.Volume = 100;
  45.     Speak(obj, defaultString);
  46.     end
  47.     elseif((sum(sum(BB_Nose))~=0 && sum(sum(BB_Mouth))==0)||(sum(sum(BB_Nose))==0 && sum(sum(BB_Mouth))~=0))
  48.    for i=1:size(BB_Nose,1)
  49.    rectangle('Position',BB_Nose(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
  50.    end
  51.    for i=1:size(BB_Mouth,1)
  52.    rectangle('Position',BB_Mouth(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
  53.    end
  54.     title('Please wear mask properly');
  55.     defaultString = 'Please wear mask properly.';
  56.     NET.addAssembly('System.Speech');
  57.     obj = System.Speech.Synthesis.SpeechSynthesizer;
  58.     obj.Volume = 100;
  59.     Speak(obj, defaultString);
  60.     else
  61.    for i=1:size(BB_Nose,1)
  62.    rectangle('Position',BB_Nose(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
  63.    end
  64.    for i=1:size(BB_Mouth,1)
  65.     rectangle('Position',BB_Mouth(i,:),'Linewidth',5,'LineStyle','-','EdgeColor','r');
  66.     end
  67.     title('Please wear Mask');
  68.     defaultString = 'Please wear Mask.';
  69.     NET.addAssembly('System.Speech');
  70.     obj = System.Speech.Synthesis.SpeechSynthesizer;
  71.     obj.Volume = 100;
  72.     Speak(obj, defaultString);
  73.     end
  74.  
  75.     pause(5)
  76.     else
  77.         handles.run=1;
  78.         guidata(hObj,handles)
  79.         disp('paused')
  80.         break
  81.     end
  82. end
  83. end
  84. function stop_cb(hObj,~)
  85. handles.run=0;
  86. guidata(hObj,handles)
  87. clc;
  88. close all;
  89.  
  90. end
  91. function pause_cb(hObj,~)
  92. handles.run=0;
  93. guidata(hObj,handles)
  94. title('Paused');
  95. end
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement