Italian Trulli

Source code of software that detects not wearing a mask – Python

COVID calms down in Vietnam, but there are still complicated developments in many other places. To be safe, the simplest and most effective way to prevent it is to wear a mask.

In fact, there are places to remind people to wear masks, some places to not, so having an automatic reminder device will help a higher percentage of people wearing masks. This article shares source code written in Python that can detect people without masks.

Source code written in Python, using Tensorflow to detect whether people in or out are wearing masks.

1. Working principle

Step 1: detect faces in image

This step detects both face with and without mask, then crop and go to step 2. This step uses LBP cascade to detect, this method is quite old but still effective.

Step 2: face classification to know if a mask is worn

This step classifies (classification) to detect which face belongs to which case:

  • Mask: wearing a mask
  • No mask: not wearing a mask
  • Wrong: wear a mask that covers your nose or mouth
  • Hand: cover the mask with your hand
  • Nothing: because step 1 wrongly detected the area without face

Wearing & wearing right

Not wearing

Wrong (open nose)

In the above classes only Mask  is valid, the remaining cases need to be reminded to wear a mask. For classification we use Mobile Net model for training and predicting.

2. Download the source code

Source code is uploaded to GitHub, after pulling / downloading the source code, you need to install it to be able to run.

  • Install Python 3.7.3 x64
  • Install required packages with the command: pip3 install -r requirements.txt
  • Run file

If successful, the program will display the image from the webcam and draw a face on it. You can add more code to make the program more complete such as sounding reminders, recognizing people not wearing masks, etc.

Download Link: #zaRyK6OtmIS8bSxksXBHVilXHc2xvn65X7sh-1lM3IE

Article Reference:

Contents (Nội dung)