Advertisement
Kali_prasad

v5 fmd with ipcam

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