top of page

Face Mask Detection: AI Systems for Detecting Face Coverings in Real-time

Updated: Oct 21, 2023


Face Mask Detection is a computer vision task that uses machine learning algorithms, particularly deep learning models, to determine whether individuals in digital images or real-time video feeds are wearing face masks. Given the global COVID-19 pandemic, the demand for such solutions surged, as wearing masks became a key preventive measure against the spread of the virus.

Applications of Face Mask Detection:

  1. Public Transport Systems: To ensure passengers on buses, trains, and metros are adhering to mask mandates, automated face mask detection systems can monitor compliance.

  2. Retail and Shopping Centers: Automated systems can be deployed at store entrances to ensure customers entering the premises are wearing masks.

  3. Airports: In addition to regular security checks, travelers can be monitored for mask compliance, which is crucial given the dense crowds and global nature of air travel.

  4. Hospitals and Clinics: While healthcare workers are typically diligent about wearing masks, a detection system can serve as an additional measure to ensure compliance and reduce the risk of transmission.

  5. Schools and Educational Institutions: As schools reopen, ensuring students, faculty, and staff adhere to mask guidelines is essential.

  6. Workplaces: Offices that mandate mask-wearing can use these systems to ensure employees comply, especially in common areas.

  7. Public Gatherings and Events: For events that allow a limited audience with mask mandates, such as sports events or concerts, organizers can use mask detection systems for surveillance.

  8. Government Buildings and Institutions: These places often witness a large number of visitors daily, making mask compliance monitoring vital.

  9. Smart City Surveillance: Cities can integrate mask detection into their existing surveillance systems to monitor mask compliance in public spaces.

  10. Access Control: In buildings or specific areas where mask-wearing is mandatory, access can be granted or denied based on whether a person is wearing a mask or not.


class FaceMaskDetector:
    A class to detect and predict face masks in video streams.

        args (dict): Parsed arguments.
        faceNet (cv2.dnn_Net): The OpenCV DNN face detection model.
        maskNet (tensorflow Model): The trained face mask detection model.

    def __init__(self):
        Initializes and loads the face and mask detection models.

    def detect_and_predict_mask(self, frame):
        Detect faces in the frame and predict if they are wearing masks.

            frame (numpy.ndarray): The frame from the video stream.

            tuple: A tuple containing lists of face locations and their corresponding mask predictions.

    def run(self):
        Starts the video stream, detects faces, predicts masks, and displays the results.
if __name__ == "__main__":
    detector = FaceMaskDetector()


The FaceMaskDetector class is designed to detect and predict face masks in video streams.


  • args: A dictionary containing parsed arguments, which may include settings like paths to model files or other configurations.

  • faceNet: Represents the face detection model from OpenCV's Deep Neural Network (DNN) module. This is responsible for identifying faces in the video stream.

  • maskNet: Refers to a trained face mask detection model (likely built using TensorFlow or a similar framework). Its role is to predict if a detected face is masked.

Initialization Method (__init__): The constructor of the class, which gets called upon instantiation. The primary function here would be to load the necessary models for face detection and mask prediction.

Detection and Prediction Method (detect_and_predict_mask): Accepts a video frame as input and conducts two primary tasks:

  1. Detect Faces: Using the face detection model, it identifies faces within the frame.

  2. Predict Masks: For each face detected, it predicts if the person is wearing a mask.

This method returns the locations of detected faces in the frame along with the mask predictions for each face.

Run Method (run): The primary execution loop of the application. It's expected to continually capture frames from a video source, run the detection and prediction on each frame, and display the results to the user, highlighting faces and indicating if they are masked or not.

Main Execution: When the script is directly run, an instance of the FaceMaskDetector class is created. Following this, the run method is called, which kickstarts the mask detection process on the video stream.

The image above depicts a model predicting people with masks and people without masks.

We have provided only the code template. For a complete implementation, contact us.

If you require assistance with the implementation of the topic mentioned above, or if you need help with related projects, please don't hesitate to reach out to us.
6 views0 comments

Recent Posts

See All


bottom of page