Introduction: TouchFree: Automated Temperature Checkup and Mask Detection Kiosk

As Countries around the Globe are Reopening, living with the Novel Coronavirus is becoming the new way of life. But to Stop the Spread of the Virus we need to separate people having the Coronavirus from the Rest.

According to the CDC, fever is the leading symptom of the Coronavirus with up to 83% of Symptomatic Patients showing some signs of fever. Many Countries are making Temperature Checkups and Masks mandatory for Schools, Colleges, Offices, and other Workplaces.

Currently, Temperature Checkups are done manually using Contactless Thermometer. Manual Checkups can be Inefficient, Impractical (in places with a large footfall), and Risky.

To solve these problems, I have designed a Kiosk that automates the process of Temperature Checkup by using Facial Landmarking & Contactless IR Temperature Sensor and Mask Detection using Deep Learning Neural Network.

The use of this Kiosk is not limited to Schools, Colleges, Offices, other Workplaces but can also be used at High-Risk Areas like Hospitals. This Device can also be used at Train Stations, Bus Stops, Airports, etc.

My approach for this project was to build a Streamlined Setup process such that anybody without any Prior Experience of Computer Vision or Deep Learning can use this. This is a fully functioning and ready to use Project. I have made this Project highly customizable by adding code files for each and every stand-alone part and the full version. Thus, you may use any of the parts of the project individually.

Explanation

Firstly, the Tensorflow based Deep Learning Neural Network tries to detect if the person is wearing a Mask or not. The System has been made Robust by training it with many different examples to prevent False Positives.

Once, the System has detected the Mask it asks the user to remove the mask so that it can perform Facial Landmarking. The System is using DLIB Module for Facial Landmarking to find the best Spot on the Forehead of the person to take Temperature from.

Then by using PID Control System with Servo Motors, the system tries to align the Selected Spot on the Forehead with the Sensor. Once aligned the system takes Temperature Reading using Contactless IR Temperature Sensor.

If the temperature is within normal Human Body Temperature range it allows the Person to Proceed and sends an email to the Admin with a Picture and other Details like Body Temperature, etc.

Supplies

Hardware

  1. Raspberry Pi Model 2/3/4
  2. Raspberry Pi Camera Module v1/v2
  3. Non-Contact Infrared Temperature Sensor Module (MLX90614)
  4. Official Raspberry Pi Touch Screen (or Generic 3.5 inch Touch Screen) (Optional)
  5. Pan Tilt Kit
  6. SG90 Micro Digital Servo x 2
  7. MicroSD Card
  8. Raspberry Pi Power Adapter

Software

  1. Raspberry Pi OS (Formerly Known as Raspbian)
  2. Tensorflow-2.2.2
  3. OpenCV
  4. DLIB Facial Landmarking

Step 1: Software Setup

Raspberry Pi Setup

1. Download Raspberry Pi Imager for your Operating System from the Raspberry Pi Download Page.

2. Attach the SD card to your computer, Select the Latest Version of Raspberry Pi OS and click Write to flash the OS to your Card.

3. Attach the SD card to the Raspberry Pi, connect it to a monitor, and Power it. Wait for a few minutes until the Raspberry Pi Boots up.

4. Connect your WiFi with your local WiFi Router by clicking the Wifi Icon Upper Right Corner of the Screen and entering your

Raspberry Pi Touch Screen Setup

Note- I have used a generic 3.5 inch Touch Screen. You can use any but the Official Raspberry Pi Touch Screen is Highly Recommended. If you choose to use a 3.5 inch Touch Screen you will have to solder a few Pins.

Follow this to Setup your official Raspberry Pi Touch Screen.

Follow this to Setup Generic 3.5 inch Touch Screen.

Raspberry Pi Camera Setup

Follow this to Setup Official Raspberry Pi Camera v1/ v2.

Enter the following commands in the Terminal one by one to install various Packages and Libraries.

Getting Pi Ready for Installations

Updating the Raspberry Pi OS

$ sudo apt-get update 
$ sudo apt-get upgrade 

Updating pip3

$ pip3 install --upgrade pip3 

Expanding Swap Size and Changing Memory

Note- These need to be changed back after all the installations are Completed.

$ sudo nano /etc/dphys-swapfile 

A new file will open. Navigate to CONF_SWAPSIZE=100 and change it to CONF_SWAPSIZE=1024. Then click Ctr + O, then Enter and then Ctr + X to save the changes.

Then run the following commands to get changes in effect.

$ sudo /etc/init.d/dphys-swapfile stop 
$ sudo /etc/init.d/dphys-swapfile start 

Then,

$ sudo raspi-config 

and Navigate to Advanced Options => Memory Split and change from 128 => 16.

Then Reboot the Raspberry Pi.

Installing Requirements

$ sudo pip3 install numpy 
$ sudo pip3 install scipy 
$ sudo pip3 install scikit-image 
$ sudo pip3 install RPi.GPIO 
$ sudo pip3 install smbus2 
$ sudo pip3 install PyMLX90614 

Installing OpenCV

Installing Important Dependencies for OpenCV

$ sudo apt-get install build-essential cmake unzip pkg-config 
$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev 
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev 
$ sudo apt-get install libxvidcore-dev libx264-dev 
$ sudo apt-get install libgtk-3-dev 
$ sudo apt-get install libcanberra-gtk* 
$ sudo apt-get install libatlas-base-dev gfortran 
$ sudo apt-get install python3-dev 

Instaling OpenCV

$ sudo apt-get install python3-opencv 

Installing TensorFlow

Note- The Model was trained on Tensorflow-2.2, if you are using any other versions of Tensorflow it may cause some problems.

$ sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev gcc gfortran python-dev libgfortran5 \ libatlas3-base libatlas-base-dev libopenblas-dev libopenblas-base libblas-dev \ liblapack-dev cython libatlas-base-dev openmpi-bin libopenmpi-dev python3-dev 
$ sudo pip3 install keras_applications==1.0.8 --no-deps 
$ sudo pip3 install keras_preprocessing==1.1.0 --no-deps 
$ sudo pip3 install h5py==2.9.0 
$ sudo pip3 install pybind11 
$ pip3 install -U --user six wheel mock 
$ wget "https://raw.githubusercontent.com/PINTO0309/Tensorflow-bin/master/tensorflow-2.2.0-cp37-cp37m-linux_armv7l_download.sh" 
$ ./tensorflow-2.2.0-cp37-cp37m-linux_armv7l_download.sh 
$ sudo pip3 uninstall tensorflow 
$ sudo -H pip3 install tensorflow-2.2.0-cp37-cp37m-linux_armv7l.whl 

Check the Installations

$ python3 
>>> import tensorflow 
>>> tensorflow.__version__
2.2.0 
>>> exit() 

If you get no error in this step, it means you have successfully installed Tensorflow.

Installing DLIB

$ pip3 install dlib 

Check the Installations

$ python3 
>>> import dlib 
>>> exit() 

If you get no error in this step, it means you have successfully installed DLIB.

Changing Swap Size and Changing Memory back

$ sudo nano /etc/dphys-swapfile 

A new file will open. Navigate to CONF_SWAPSIZE=1024 and change it to CONF_SWAPSIZE=100. Then click Ctr + O, then Enter and then Ctr + X to save the changes.

Then run the following commands to get changes in effect.

$ sudo /etc/init.d/dphys-swapfile stop 
$ sudo /etc/init.d/dphys-swapfile start 

Then,

$ sudo raspi-config 

and Navigate to Advanced Options => Memory Split and change from 16 => 128.

Then Reboot the Raspberry Pi.

Downloading the Code

$ mkdir covid 
$ cd covid 
$ git clone  https://github.com/saksham2001/Covid-Project 

Environment Variables Setup

$ sudo nano /etc/profile 

This will open a file, at the end of the file add the following lines if you want to get email alerts

export SEND_EMAIL="TRUE" 
export EMAIL_ID="your-email-id@something.com" 
Use your Email ID instead of "your-email-id@something.com"
export EMAIL_PWD="your-email-password" 
Use your Email Password instead of "your-email-password"
export COUNTER_ID=0 

Email Setup

To use the email Alert Service you will need a Gmail Account and you will need to Allow Less Secure Apps. Or, if you use 2 Factor Authentication then you might need to create an App Password.

Step 2: Hardware Setup

Attach the Servos X and the Sensor Y as Given in the Circuit Diagram. All the Connections can be made as per the diagram. The Camera has to be connected to the Camera Connector and Raspberry Pi Display can be connected to the Display Connector. If you are using a Generic 3.5 inch Touch Screen, you can connect the screen to the required GPIOs. The GPIOs connecting to Servos will still be free, but you will need to solder to get 5v and SDA, SCL pins for the Sensor.

Note- Servo X is the Servo which moves Right-Left. Servo Y is the Servo which moves Up-Down.

Sensor Setup

After connecting the Sensor, run the following command

$ sudo su -c 'echo "Y" > /sys/module/i2c_bcm2708/parameters/combined'
$ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Copy the port name (5a in this case)

$ cd ~/covid
$ nano app.py

Then change 5A in the given line

sensor = MLX90614(bus, address=0x5A)
$ cd ~/covid
$ nano temp_checker.py

Again change 5A in the given line

sensor = MLX90614(bus, address=0x5A)

Step 3: Testing

$ cd ~
$ cd covid

Running the Complete Application

$ python3 app.py

Running Application without Pan and Tilt Module

$ python3 no_pan.py

Running only the Temperature Checkup Code

$ python3 temp_check.py

Running only the Mask Detection Code

$ python3 mask_detection.py

Running only the Email Sending Code

$ python3 email_sender.py

Step 4: Building Enclosure and Camera-Sensor Enclosure

You can 3D Print the Enclosure using the files given below or else you can make Your own Makeshift Enclosure using Cardboard, Wood, etc.

I have 3D Printed this enclosure made by Stephen Wilson for my 3.5 inch Touch Screen Display.

If you are using the Official Raspberry Pi Display try finding Enclosures on Thingiverse. I liked this one a lot but have not tested it out.

For the Camera-Sensor Enclosure, I have custom made them so that the Camera and Sensor can align. If you want to change the enclosure, you might need to change the alignment point in the Code.

Note- These Cases are for Raspberry Pi 2/3 and will not work with Pi 4. For Pi 4 you will need to find a different Case. The files attached below for the Camera-Sensor Enclosure do not have any screw holes for the sensor (As the sensor comes in Many Shapes and Sizes). If you want to have Screw Holes feel free to edit these files.

Step 5: Debugging Problems

What should I do If the Mask Detection is not Working properly?

The Mask Detection Model has been trained with Synthetic Data in a very Limited Lighting Conditions and with a limited Face Mask Colours. If the model is not working well with your conditions you might need to retrain the model according to the instructions given below.

Note- This might be tricky if you get stuck at any step feel free to contact me!

  1. Take Some Pictures on Your Raspberry Pi with mask and without a mask using the command- $ raspistill -o image-name.jpg Change the image-name every time you click an image.
  2. Go to the Google Collab Notebook here and Duplicate it. Change the Runtime Type in Runtime => Change Runtime Type to GPU.
  3. Then in your notebook Run the first 4 Cells. This will create two folders in files with mask and without mask. Add the images taken by you to these folders and run all other Cells.
  4. Then a new model will be created as mask_detector.h5. Download this model and replace the old model in covid => models on your Raspberry Pi with it.

What should I do if the Temperature Checkup is not Working?

The Temperature Checkup requires proper lighting. Make sure you have proper lighting and that your Servos are working well.

First Time Author Contest

Participated in the
First Time Author Contest