Introduction: FACE MASK DETECTION & TEMP GATE
The world is fighting with Covid19 pandemic. There are so many essential equipments needed to fight against Corona virus. One of such most essential is Face Mask. Firstly face mask was not mandatory for everyone but as the day progresses scientist and Doctors have recommended everyone to wear face mask. Now To detect whether a person is wearing Face Mask or not, we will use Face Mask Detection Technique. Face Mask Detection Platform utilizes Artificial Network to perceive if a person does/doesn’t wear a mask.,also The temperature will be measured by thermal camera AMG8833
Step 1: Motivation
In the present scenario due to Covid-19, there is no efficient face mask detection applications which are now in high demand for transportation means, densely populated areas, residential districts, large-scale manufacturers and other enterprises to ensure safety.
Step 2: TechStack/framework Used
Step 3: Features
Our face mask detector didn't use any morphed masked images dataset. The model is accurate, and since we used the MobileNetV2 architecture, it’s also computationally efficient and thus making it easier to deploy the model to embedded systems (Raspberry Pi, Google Coral, etc.).
This system can therefore be used in real-time applications which require face-mask detection for safety purposes due to the outbreak of Covid-19. This project can be integrated with embedded systems for application in airports, railway stations, offices, schools, and public places to ensure that public safety guidelines are followed.
Panasonic's AMG8833 Grid-EYE is an 8x8 array of IR thermal sensors. When connected to your microcontroller (or raspberry Pi) it will return an array of 64 individual IR temperature readings over I2C.
Step 4: Dataset
The dataset used can be downloaded here - Click to Download
This dataset consists of 3835 images belonging to two classes: with_mask: 1916 imageswithout_mask: 1919 imagesThe images used were real images of faces wearing masks. The images were collected from the following sources:
Bing Search API (See Python script)
dataset (See here)
Raspberry Pi Thermal Camera (AMG8833)
Step 5: Prerequisites
All the dependencies and required libraries are included in the file requirements.txt See here
Step 6: Installation
1.Clone the repo
$ git clone https://github.com/chandrikadeb7/Face-Mask-Detection.git
2.Change your directory to the cloned repo and create a Python virtual environment named 'test'
$ mkdir test
3.Now, run the following command in your Terminal/Command Prompt to install the libraries required
$ pip3 install -r requirements.txt
Step 7: Working
1.Open terminal. Go into the cloned project directory and type the following command:
$ python3 train_mask_detector.py --dataset dataset
2.To detect face masks in an image type the following command:
$ python3 train_mask_image.py --image images/pic1.jpeg
3.To detect face masks in real-time video streams type the following command:
$ python3 detect_mask_video.py
'for Thermal Camera AMG8833'
4.Install Python Software
sudo apt-get install -y python-scipy python-pygame
sudo pip3 install colour
5.Wiring Up Sensor
With the Pi powered off, we can wire up the sensor to the Pi Cobbler like this:
- Connect Vin to the 3V or 5V power supply (either is fine)
- Connect GND to the ground pin on the Cobbler
- Connect SDA to SDA on the Cobbler
- Connect SCL to SCL on the Cobbler
You can also use direct wires, we happen to have a Cobbler ready. remember you can plug the cobbler into the bottom of the PiTFT to get access to all the pins!
6.Now you should be able to verify that the sensor is wired up correctly by asking the Pi to detect what addresses it can see on the I2C bus:
sudo i2cdetect -y 1
7.Run example code (AMG8833)
"""This example is for Raspberry Pi (Linux) only! It will not work on microcontrollers running CircuitPython!""" import os import math import time import busio import board import numpy as np import pygame from scipy.interpolate import griddata from colour import Color import adafruit_amg88xx i2c_bus = busio.I2C(board.SCL, board.SDA) #low range of the sensor (this will be blue on the screen) MINTEMP = 26. #high range of the sensor (this will be red on the screen) MAXTEMP = 32. #how many color values we can have COLORDEPTH = 1024 os.putenv('SDL_FBDEV', '/dev/fb1') pygame.init() #initialize the sensor sensor = adafruit_amg88xx.AMG88XX(i2c_bus) # pylint: disable=invalid-slice-index points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)] grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j] # pylint: enable=invalid-slice-index #sensor is an 8x8 grid so lets do a square height = 240 width = 240 #the list of colors we can choose from blue = Color("indigo") colors = list(blue.range_to(Color("red"), COLORDEPTH)) #create the array of colors colors = [(int(c.red * 255), int(c.green * 255), int(c.blue * 255)) for c in colors] displayPixelWidth = width / 30 displayPixelHeight = height / 30 lcd = pygame.display.set_mode((width, height)) lcd.fill((255, 0, 0)) pygame.display.update() pygame.mouse.set_visible(False) lcd.fill((0, 0, 0)) pygame.display.update() #some utility functions def constrain(val, min_val, max_val): return min(max_val, max(min_val, val)) def map_value(x, in_min, in_max, out_min, out_max): return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min #let the sensor initialize time.sleep(.1) while True: #read the pixels pixels =  for row in sensor.pixels: pixels = pixels + row pixels = [map_value(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in pixels] #perform interpolation bicubic = griddata(points, pixels, (grid_x, grid_y), method='cubic') #draw everything for ix, row in enumerate(bicubic): for jx, pixel in enumerate(row): pygame.draw.rect(lcd, colors[constrain(int(pixel), 0, COLORDEPTH- 1)], (displayPixelHeight * ix, displayPixelWidth * jx, displayPixelHeight, displayPixelWidth)) pygame.display.update()
Step 8: Results
- Our model gave 93% accuracy for Face Mask Detection after training via tensorflow-gpu==2.0.0
- We got the following accuracy/loss training curve plot