Advertisement
Kali_prasad

fmd v6 with less line codes

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