Face Mask Detection using Python, Keras, OpenCV and MobileNet | Detect masks real-time video streams
Why Stack Overflow recommends it
Stack Overflow users cite it as the source of the mask-detection code they are running and then debugging, mostly OpenCV and Keras errors when adapting it to webcams or screen capture.
Recommended by 0 people across 0 different months, 2020 to 2021.
What it is
A 27-minute Python tutorial by Balaji Srinivasan that builds a face mask detector with Keras, TensorFlow, MobileNetV2 and OpenCV, then runs it on a live webcam stream. It walks through training the classifier and applying it to real-time video, with the code published on GitHub.
What people said
Cites Abdulrahman Al-Sallum · 2020-12 · Stack Overflow · on “How can I make a delay in python without the camera video get affected and slowed?”
Hope you are doing fine. So my problem or question is actually more complicated than the title but I will try to keep it simple. I have this code that runs on cam ( using OpenCV ) and will detect if a person wearing a mask or not, as far as detection go it performs very well ( I got the code from YouTube : [this video] ). In short I want the program to see if the person(with confidence > 95%) is wearing a mask or not, if he is wearing the mask a pop-up message will appear thanking him then the program will close. In theory I've done all that, The problem is that when the person wears a mask the pop-up message will immediately appear before even the cam catch up ! or if the person isn't wearing a
Cites Jack Nelson · 2021-03 · Stack Overflow · on “When running face recognition OpenCV I get IOerror”
This is the code im trying to run that I found on this video [this video] I have never used OpenCV, and I do not understand the error. The code is designed to detect if someone from a live feed is wearing a mask or not. from tensorflow.keras.applications.mobilenet_v2 import preprocess_input from tensorflow.keras.preprocessing.image import img_to_array from tensorflow.keras.models import load_model from imutils.video import VideoStream import numpy as np import imutils import time import cv2 import os def detect_and_predict_mask(frame, faceNet, maskNet): (h, w) = frame.shape[:2] blob = cv2.dnn.blobFromImage(frame, 1.0, (224, 224), (104.0, 177.0, 123.0)) faceNet.setInput(blob) detections = faceNet.
Cites Jack Nelson · 2021-03 · Stack Overflow · on “When running code I get an opencv cv2 error”
This is the code im trying to run that I found on this video [this video] from tensorflow.keras.applications.mobilenet_v2 import preprocess_input from tensorflow.keras.preprocessing.image import img_to_array from tensorflow.keras.models import load_model from imutils.video import VideoStream import numpy as np import imutils import time import cv2 import os def detect_and_predict_mask(frame, faceNet, maskNet): (h, w) = frame.shape[:2] blob = cv2.dnn.blobFromImage(frame, 1.0, (224, 224), (104.0, 177.0, 123.0)) faceNet.setInput(blob) detections = faceNet.forward() print(detections.shape) faces = [] locs = [] preds = [] # loop over the detections for i in range(0, detections.shape[2]): confidence =
Cites theknig · 2021-04 · Stack Overflow · on “Show Mask Object Detection On Screen instead of Camera”
So I've been following this tutorial [this video] to detect if person wearing mask or not on camera and got everything to work when using the camera by using the following code: vs = cv2.VideoCapture(0) while True: Frame = vs.read() However I want it to find detections on display screen instead of camera so I've changed the above code to the following: bounding_box = {'top': 0, 'left': 0, 'width': 1920, 'height': 1080} sct = mss() while True: sct_img = sct.grab(bounding_box) frame = np.array(sct_img) I am now getting this error error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 4 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes' Here is the full code