Search This Blog

Thursday, 18 November 2021

Mask Detection for COVID-19 disease

Contents:

1) Introduction of the Project
2) Functions and Module Used
3) Software requirements to run the Program
4) Main Program

1) Introduction of the Project

In today’s world, all the things have become
computerized.

As we all know, COVID-19 can spread when
People breathe, talk, cough or sneeze.
Wearing a mask keeps the virus from reaching
Others. It also can stop the virus from reaching
You.

So this program simply Detect all Faces
Camera, then detect Mask on their faces with
The help of Artificial Intelligence (A.1.)
Machine Learning (M.L.).

If someone found without Mask on his/her face
Then “Be Safe Mask not Found” text will be
printed on screen or Custom

required action can be taken by that
Organization who using this Program.

For example: If someone is without Mask then
By using SSH and Arduino this Program will
Close the door or whatever we will set.

2) Functions and Module used:

cv2.VideoCapture(0):

Cv2 is the module for real-time computer vision.
VideoCapture(0) used for capturing frames from
Camera on number (0).

cv2.CascadeClassifier(“Haarcascade.xml”):

This function reads the trained file for
Mask Detection. Haarcascade.xml is the file
contains all Coordinates codings of AI and ML for
Mask Points. We can train this our Own.

cv2.read():

This function reads the frames from Camera
Number (0) which we set above using VideoCapture

detectMultiScale():

This function detect Co-ordinates for Masks which
we trained from above function CascadeClassifer.

cv2.imshow():

This function Displays the Captured Frames which
We captured from cv2.read() function.

3) Software/Hardware Requirements to run the Program:

1) OpenCV-Python, This is Most Important because This is the main library we use in this program
2) Python 3.x, This is required because, I have tested on this only.
3) Pip3, This is required because packages we install will be installed by this program
4) Camera required, We can change this later by using real-time or from saved Image
5) Windows,Linux,Mac any OS support this because python is Cross-Platform
6) NumPy Library, We will not use this library but This will Installed with OpenCV-Python

Files for Downloading:

1) Haarcascade for Mask Trained by Me, Click Here
2) Haarcascade for Face come with OpenCV-Python by default. Click here for Download Manually

4) Main Program:

import cv2
import numpy as np
cam = cv2.VideoCapture(0)

obj = cv2.CascadeClassifier("myhaar.xml")
face = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

while 1:
r,img = cam.read()
img = cv2.flip(img,3)
mask = obj.detectMultiScale(img,1.3,5)
faces = face.detectMultiScale(img,1.3,5)
for (x,y,w,h) in mask:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
cv2.putText(img,"Very Good! Keep it Up",(50,50),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),3,cv2.LINE_AA)
if len(mask) == 0:
print("Mask Not Found! Be Safe from CORONA.")
for (x1,y1,w1,h1) in faces:
cv2.rectangle(img,(x1,y1),(x1+w1,y1+h1),(0,0,255),2)
cv2.putText(img,"Be Safe! Mask Not Found.",(50,50),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),3,cv2.LINE_AA)
cv2.imshow("A",img)
if cv2.waitKey(1) == ord('q'):
break
cv2.destroyAllWindows()


Tutorial:






No comments:

Post a Comment

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...