Real-Time Face Mask Detection using OpenCV and Deep Learning Hruthik S. Upendra1, Shruti Suman2, Sai S. Vishnu3 and Jaya Dharani4 1,2,3,4 Department of ECE, KoneruLakshmaiah Education Foundation, Andhra Pradesh, India. Abstract The outbreak of the COVID-19 pandemic has brought the entire global health system to a standstill. It is now critical to stop the virus from spreading.Wearing a mask, washing our hands frequently, and keeping social distances have all become the main focus around the world. World Health Organization (WHO) highly recommends wearing a mask covering the mouthandnoseto tackle the transmission of the novel coronavirus. In this research study, the Haar-Cascade algorithm, also known as the Voila-Jones algorithm, and OpenCV library classifiers are implemented to find whether someone is wearing a mask or not. The dataset used has 3835 images comprising of human faces with and without masks. The results show that the trained model is 98% accurate in face mask detection. This study is serviceable in real-time applications which stand in need of face mask detection, mainly in densely populated places like educational institutions, airports, and public places. Keywords 1 COVID-19; Coronavirus; Face mask detection; Voila-Jones algorithm; Open Computer Vision (OpenCV); Deep learning. 1. Introduction Covid illness (COVID-19) is an irresistible sickness brought about by extreme intense respiratory condition Covid 2 (SARS-CoV-2). The newfound Covid had influenced everybody across the globe and upset the economy of numerous nations.SARS-CoV-2, according to many studies throughout the world, spreads by air and can easily spread over large distances in poorly ventilated areas and crowded settings. Coronavirus affects various individuals in unexpected ways. The majorityof infected patients will experience mild to severe illness. and recover without hospitalization. Most typical symptoms include fever, dry cough, and tiredness. Other symptoms may include aches and pains, sore throat, diarrhoea, and ability to sense taste and smell. Severe cases may lead to some serious symptoms like shortness of breath, chest pain or pressure and sometimes loss of speech. Typically, it requires 5–6 days for somebody who contracted the infection for side effects to show, but it can take up to as long as 14 days [1]. Besides, even people with no symptoms can transmit the infection which makes it hard to prevent people from getting infected. As directed by World Health Organisation (WHO) wearing a mask and following social distancing plays a key role in preventing massive spread of disease. Many studies have proved that wearing a mask can help prevent virus spread. The effectiveness of wearing N95 mask in preventing virus transmission is 91%, whereas surgical mask has 68% of effectiveness. Wearing mask can reduce the chance of getting disease. Accordingly, the usage of masks and hand sanitizers have demonstrated to be effective in avoiding the spread of the infection. Hence, a face mask detecting system is required which will alert the people International Conference on Emerging Technologies: AI, IoT, and CPS for Science & Technology Applications, September 06–07, 2021, NITTTR Chandigarh, India EMAIL: hruthikhsu07@gmail.com; shrutisuman23@gmail.com; vishnu.yadavalli007@gmail.com; jayadharani245@gmail.com ORCID: 0000-0001-5704-3085; 0000-0002-6631-3486; 0000-0002-1293-4180; 0000-0002-6365-3020 ©2021 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). CEUR Workshop Proceedings (CEUR-WS.org) and helps in preventing the pandemic. We will explore real-time face mask detection using deep learning and OpenCV in this paper. Deep learning is subbranch of machine learning that works with algorithms that are inspired by the human brain. Deep learning helps in breakdown of problems in many fields. Deep learning offer image detection, image classification and Convolutional Neural Networks (CNN). The Convolutional Neural Networks (CNN) are mainly used in computer detection and classification tasks. In this paper Deep learning techniques are used to differentiate faces wearing a mask and not wearing a mask. Convolutional Neural Networks (CNN) are used to include the efficient number of Convolutional Neural Layers for accurate detection. OpenCV is a library of programming functions which mainly aimed at real time computer vision, Machine Learning and Image processing. The computer vision mainly aims at manipulating and retrieve data from a real time source. It can be used in Autonomous driving vehicles. OpenCV is used for detection of faces, objects, and handwritings. It plays a key role in detection of face with and without mask. By summarising we firstly create a CNN for detection of facial images and then employee Deep learning algorithms for detection of faces with and without masks using Tensor flow and Open CV libraries. 2. Background 2.1. OpenCV Open CV is a library of programming functions which is mainly aimed at real-time computer vision, Machine Learning, and Image processing. Initially, OpenCV was written in C++ language and supports multicore processing. These algorithms are also bindings in Python, Java, MATLAB. It mainly focuses on image processing, video capturing, face detection. Open CV has the advantage of hardware acceleration of the underlying heterogeneous compute platform. Open CV has access to nearly 2,500 algorithms for different computer vision techniques. Open CV is a cross-platform library i.e., it can operate on any operating system. 2.2. TensorFlow TensorFlow is an opensource library for machine learning. It is a Python friendly library for numerical computations that makes machine learning easy and faster. TensorFlow is particularly used in training and deployment of deep neural networks. TensorFlow is a symbolic mathematical representation of data flow and differential programming. 2.3. Keras Keras is an open source library for Artificial Neural Networks. It provides a python interface for ANN. It also acts as an interface for Tensor Flow library. Keras is designed to enablequick experimenting with deep neural networks. Keras contains a few Neural organization building squares like layers, targets, actuation, capacities, analyzers, and a large group of apparatuses with picture and text information for the execution of profound neural organization codes. Keras additionally upholds for Convolutional and repetitive neural organizations. It is additionally used to productize the profound learning models on cell phones. 3. Methodology 3.1. Data Collection The first step in detecting face mask is to collect data to train the model for real-time face mask detection. For this, images of people wearing masks and people not wearing masks were required. 3835 images of both wearing mask and without mask were acquired through sources like Google and Bing and through Kaggle datasets and RMFD datasets. The used dataset comprises of 1916 pictures of individuals wearing the veil and 1919 pictures of individuals don't wearing the cover. Figure 1: Sample images of people with and without mask. 3.2. Face Mask Detection The detection of face mask can be described in two steps as follows: 1. Face Recognition and 2. Mask Detection. For implementing face mask recognition, machine learning object detection algorithm called Viola-Jones algorithm and Haar feature-based cascade classifiers are applied using OpenCV. Face detection algorithm was introduced by Paul Viola and Michael Jonesin 2001 in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features”. For real-time face detection to be done in a video, we need to perform face detection for every frame in the video. Face detection is shown in figure3. Figure 2: Face detection. Now, after the detection of face on the image, it is preprocessed and resized to 224x224 pixels dimensions. Further, OpenCV spretrainedHaar course classifiers are utilized for mouth and nose identification which characterizes if an individual is wearing a cover. In the event that the mouth and nose are distinguished, the individual isn't wearing a veil, thus whether a cover is not really set in stone. 4. Results Python programming language is used for implementing the real-time face mask detection using OpenCV and achieved 98% validation accuracy. This is the most noteworthy rate after several tests performed with a batch size 32 and 20 repetitions of Epochs. The results below illustrates the accuracy and loss performance of the trained model. Table 1 Accuracy precision recall f1-score support with_mask 0.98 0.99 0.98 433 without_mask 0.99 0.97 0.98 386 accuracy 0.98 819 macro avg 0.98 0.98 0.98 819 weighted avg 0.98 0.98 0.98 819 Figure 3: Training loss and accuracy during model training. Figure 4: Testing results of mask detection. 5. Conclusion and Future work This paper presents a study on real-time face mask detection using OpenCV and deep learning techniques and based on the results obtained, it is a noteworthy method for easy detection of facemask, however, there are a very few limitations which can be easily overcome in future work. The proposed method is very useful for real-time applications which stand in need of face mask detection, mainly in densely populated places like educational institutions, airports, and public places. In future, using various deep learning techniques and IOT applications we can further implement mask detection along with contactless temperature check, which detects proper wearing of mask and gives entry access only if mask was wore properly and if the body temperature is normal and warns us if mask was not wore properly or no mask was wore and high body temperatures and thus can prevent the indoors spread of the virus and implement the directed safety guidelines for prevention of Covid- 19. 6. References [1] Coronavirus Update (Live) [online]. Available on: https://www.worldometers.info/coronavirus/ last accessed: 17/01/2021. [2] World Health Organization. Accessed on: 21-Jan2021. [Online]. Available on: https://www.who.int/health-topics/coronavirus/ [3] P. Dawson et al., “Loss of Taste and Smell as Distinguishing Symptoms of COVID-19”, Clinical Infectious Diseases June 2020, pp. 1-4, 2020. https://doi.org/10.1093/cid/ciaa799 [4] L. Morawska, “How can airborne transmission of COVID-19 indoors be minimised?”, Environment International vol. 142, September 2020, 105832, pp. 1-7, 2020. https://doi.org/10.1016/j.envint.2020.105832 [5] V. Balachandar et al., “COVID-19: emerging protective measures”, European Review for Medical and Pharmacological Sciences vol. 24 (6), pp. 3422-3425, 2020. https://doi.org/10.26355/eurrev_202003_20713 [6] T. Galbadage, B. Peterson, R. Gunasekera, “Does COVID-19 Spread Through Droplets Alone?”, Frontiers in Public Health, vol. 8, April 2020, pp. 1-4, 2020. https://doi.org/10.3389/fpubh.2020.00163 [7] Z. Wang et al., “Masked Face Recognition Dataset and Application” [preprint], pp. 1-3, 2020. https://arxiv.org/pdf/2003.09093.pdf [8] D. Oran, E. Topol, Prevalence of Asymptomatic SARS-CoV-2 Infection: A Narrative Review, Annals of Internal Medicine, June 2020, pp. 1-7, 2020. https://doi.org/10.7326/M20-3012 [9] Bai Y, Yao L, Wei T, Tian F, Jin DY, Chen L, Wang M. Presumed Asymptomatic Carrier Transmission of COVID-19. JAMA. 2020 Apr 14;323(14):1406-1407. doi: 10.1001/jama.2020.2565. PMID: 32083643; PMCID: PMC7042844 [10] Y. Song et al., “COVID-19 Treatment: Close to a Cure? – A Rapid Review of Pharmacotherapies for the Novel Coronavirus” [preprint], pp. 1-25, 2020. https://doi.org/10.20944/preprints202003.0378.v1 [11] Coronavirus Incubation Period [online]. Available on: https://www.worldometers.info/coronavirus/coronavirusincubationperiod/, last accessed: 23/01/2021. [12] D. Oran, E. Topol, Prevalence of Asymptomatic SARS-CoV-2 Infection: A Narrative Review, Annals of Internal Medicine, June 2020, pp. 1-7, 2020. https://doi.org/10.7326/M20-3012 [13] T. Dbouk, D. Drikakis, “On respiratory droplets and face masks”, Physics of Fluids 32, 063303, pp. 1-11, 2020. https://doi.org/10.1063/5.0015044 [14] P. Viola and M. Jones, "Rapid object detection using a boosted cascade of simple features," Proceedings of the 2001 IEEE Computer Society Conference on Computer Vision and Pattern Recognition. CVPR 2001, Kauai, HI, USA, 2001, pp. I-I, doi: 10.1109/CVPR.2001.990517. [15] Viola, P., Jones, M.J. Robust Real-Time Face Detection. International Journal of ComputerVision 57, 137–154(2004). https://doi.org/10.1023/B:VISI.0000013087.49260.fb [16] Open Computer Vision [Online]. Available on: https://opencv.org/ [17] Yi-Qing Wang, An Analysis of the Viola-Jones Face Detection Algorithm, Image Processing On Line, 4 (2014), pp. 128–148. http://dx.doi.org/10.5201/ipol.2014.104 [18] Yu, P., Zhu, J., Zhang, Z., & Han, Y. (2020). A Familial Cluster of Infection Associated With the 2019 Novel Coronavirus Indicating Possible Person-to-Person Transmission During the Incubation Period. The Journal of infectious diseases, 221(11), 1757–1761. https://doi.org/10.1093/infdis/jiaa077 [19] Chavez S, Long B, Koyfman A, Liang SY. Coronavirus Disease (COVID-19): A primer for emergency physicians. Am J Emerg Med. 2020 Mar 24:S0735-6757(20)30178-9. doi: 10.1016/j.ajem.2020.03.036. Epub ahead of print. PMID: 32265065; PMCID: PMC7102516.