Skip to content

Instantly share code, notes, and snippets.

@RITIK-12
Created September 20, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RITIK-12/bcb89d844120441675738e92716c4226 to your computer and use it in GitHub Desktop.
Save RITIK-12/bcb89d844120441675738e92716c4226 to your computer and use it in GitHub Desktop.
print("Starting video stream")
vs = VideoStream(src=0).start()
time.sleep(2.0)
# looping over the frames from the video stream
while True:
# grab the frame from the threaded video stream and resize it to have a maximum width of 800 pixels
frame = vs.read()
frame = imutils.resize(frame, width=800)
# detect faces in the frame and determine if they are wearing a face mask or not
(locs, preds) = detect_and_predict_mask(frame, faceNet, maskNet)
# loop over the detected face locations and their corresponding locations
for (box, pred) in zip(locs, preds):
# unpack the bounding box and predictions
(startX, startY, endX, endY) = box
(mask, withoutMask) = pred
# determine the class label and color we'll use to draw the bounding box and text
label = "Mask" if mask > withoutMask else "No Mask"
color = (0, 255, 0) if label == "Mask" else (0, 0, 255)
# include the probability in the label
label = "{}: {:.2f}%".format(label, max(mask, withoutMask) * 100)
# display the label and bounding box rectangle on the output frame
cv2.putText(frame, label, (startX, startY - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2)
cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2)
# showing the output frame
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
cv2.destroyAllWindows()
vs.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment