This project is aimed at creating a real-time face mask detection system using machine learning with Python. It uses OpenCV for image processing, Haar Cascade Classifier for face detection, and a Support Vector Machine (SVC) for classification. The primary objective is to determine whether a person is wearing a mask or not from a webcam feed.
The project is organized into two main parts, implemented in two separate Jupyter notebooks:
In this notebook, we collect data for training and testing the face mask detection model. The following steps are taken:
-
Image Capture: We utilize the computer's webcam to capture continuous images of individuals with and without masks. A total of 1000 images are collected for each category.
-
Data Storage: The captured images are stored as NumPy arrays in two separate files:
with_mask.npy
: Contains images of people wearing masks.without_mask.npy
: Contains images of people without masks.
-
Face Detection: We employ the Haar Cascade Classifier (
haarcascade_frontalface_default.xml
) to detect faces within the images.
In this notebook, we train a Support Vector Machine (SVM) classifier to distinguish between images with masks and images without masks. The process includes the following steps:
-
Data Preparation: We load and preprocess the data from the previously generated NumPy arrays. This includes resizing the images and converting them to grayscale.
-
Dimensionality Reduction: Principal Component Analysis (PCA) is applied to reduce the dimensionality of the image data.
-
Model Training: We train an SVM classifier using the preprocessed data.
-
Real-Time Detection: We create a real-time face mask detection system using the trained SVM model. The webcam feed is processed in real-time, and the system labels the detected faces as either Mask or No Mask
NOTE: In this project I got the accuracy score 1.0 which is the case of overfitting that is not good in the machine learning model. Currently I could not resolve this by doing several trials If you how to do this please suggest me.