Introduction:
As Covid-19 arises, one problem we all face is entering places but still being close to people. A face mask detection camera could allow people, such as students and teachers in school, to make sure to put on their masks when entering the places keeping the environment we live in safe and healthy.
Driven Question:
How can we use computer vision to mitigate spread of Coronavirus?
Purpose & Goal:
Our Purpose & Goal is to write a code that helps the camera scan an individuals face and determine if they are wearing a mask and help reduce possible covid-19 cases.
Hypothesis:
I believe that writing and editing a code using the "open cv" and multiple other codes in the library can provide an efficient code that detects an individuals face and one that detects their nose, if it is covered or not, can help reduce possible covid-19 cases.
Materials:
Webcam
Laptop
Python
Pycharm
Face Mask
Procedure:
Prepare Materials & Start research on open cv
Install python – Download the latest version for your computer. www.python.org/downloads
Install Pycharm – Download the latest version for your computer www.jetbrains.com/pycharm/download
Install OpenCV and Numpy Packages by using pip install library. Run this pip command in your terminal: –pip install OpenCV-python numpy
Requirements for Face Recognition Project
Create a new folder
Download the haarcascade_frontalface_default_default.xml file into your folder
Copy your image for detection faces into the folder
Create a python file for detecting faces. (Open the Pycharm program, Create a new python project and save it to your folder)
Start code and import the files from the library
Make sure program works and if not, debug and redo until code works
1- What are the requirements for building a facemask detection project.
In order for our mask detector model to work, it needs images of faces. For this, we will detect the frames with faces using the methods as shown in the first section and then pass them to our model after preprocessing them. So let us first import all the libraries we need.
2- How to install OpenCV in Python
OpenCV is an open-source Python library, which used to understand the content of the digital images. The CV is the abbreviation form of computer vision. It extracts the description from the real-time image or digital image, which may be an object, a text description, and so on. We can perform many tasks using the OpenCV library such as face detection, face recognition, blob detection, edge detection, image filter, template matching, etc. To work with the OpenCV, we need to install it in our Python environment.
3- How to identify faces?
We will use the haar cascade classifier in this project. Haar-cascade classifier is an Object Detection Algorithm used to identify faces in an image or a real-time video. The algorithm uses edge or line detection features proposed by Viola and Jones in their research paper “Rapid Object Detection using a Boosted Cascade of Simple Features” published in 2001. The algorithm is given a lot of positive images consisting of faces, and a lot of negative images not consisting of any face to train on them. The model created from this training is available at the OpenCV
4- What is the Process for the Project?
The main process during the project was importing the library items to the coding platform, I used Pycharm, and later writing the code. For the code we used an array of variables to instruct the computer to understand the human face, focusing on the nostrils and the mouth. Later we created a track box which would change color if the nostrils were detected telling the users they are not wearing a mask and staying the blue color when the user is wearing the mask. Finally we added a cleaner surrounding and a notification box so that the app nice to the user. Conclusively the use of previous AI projects and the python library tremendously helped in creating a projecting like Face Mask Detection.
My Code:
#import libraries
import cv2
import os
#Credit realpython.com
#start webcam
cap=cv2.VideoCapture(0)
# Capture frame-by-frame
# Convert into grayscale
# Create Cascade Classifiers
while True:
ret,frame=cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.putText(frame,"face", (x, y - 10),
cv2.FONT_HERSHEY_DUPLEX,0.5, (194, 231, 26), 1)
cv2.rectangle(frame, (x, y), (x+w, y+h), (194, 231, 26), 2)
# Display the resulting frame
cv2.imshow("frame",frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break;
cap.release()
cv2.destroyAllWindows()