Advertisement
Kali_prasad

fmd with gui

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