Вы находитесь на странице: 1из 76

Faculty of Computers and Information

Suez University

Artificial Intelligence Based Student


Attendance Using Face Recognition
GRADUATION PROJECT 2019/ 2020
SUPERVISED BY: DR. WAEL FAWAZ ABDELRAHIM
Contents
Contents ……………………………………………………………………………….0

Abstract ………………………………………………………………………………..3

INTRODUCTION ........................................................................................................... 6

1.1 Introduction ....................................................................................................... 7

1.2 Background about used technologies and domain definition .......................... 8

1.3 Problem Statement ..........................................................................................10

1.4 Aims and Objectives .......................................................................................... 7

1.5 Expected outcome ........................................................................................... 12

System Analysis .......................................................................................................... 13

2.1 System definition: ............................................................................................. 14

2.2 UML Analysis: ................................................................................................... 15

2.3 Requirements: ................................................................................................. 22

2.4 Functional Requirements: ............................................................................... 22

2.5 Nonfunctional Requirements:......................................................................... 22

Development ............................................................................................................. 24

3.1 Development Requirements ........................................................................... 25

3.2 Coding:.............................................................................................................. 31

Design ……………………………………………………………….………………..49

Application Screening: .......................................................................................... 50

Conclusion and Future work ..................................................................................... 68

5.1 Conclusion:....................................................................................................... 69

1|Page
5.2 Future work: .................................................................................................... 70

Appendixes……………………………………………………………………………72

Acknowledgement ................................................................................................. 3

Screens and Figures .............................................................................................. 73

References…………… ............................................................................................. 75

2|Page
Acknowledgement

We would like to express our heartiest thanks and


Excellency to the Almighty for giving us the opportunity to
make the great things for organizations.

We are really grateful and wish our sincere regards to our


honorable Dr.Wael Fawaz Abdelrahim, Assistant Professor,
Department of Computer Science, Faculty of computers and
Information, Suez University. The deep Knowledge& keen
interest of our supervisor in the field of “Face detection and
Recognition” to carry out this project. His endless patience,
scholarly guidance, continual encouragement, constant and
energetic supervision, constructive criticism, valuable
advice, reading many inferior drafts and correcting them at
all stage have made it possible to complete this project.

I would like to thank our entire varsity mate in Daffodil


International University, who took part in this discuss while
completing the project work.

Finally, I must acknowledge with due respect the constant


support of our parents.

3|Page
Team Members

AMIRA MOHAMED GALAL #1

IBRAHIM METAWEE IBRAHIM #2

MARIAM ABDELTAWAB ABDELAZIZ #3

NAIRA MOHAMMED MADANEY #4

SAHAR MOHAMMED MUSTAFA #5

4|Page
Abstract

Human face detection and recognition is an important technology


used in various applications such as video monitor system. This
software is about the biometric attendance management. The
automatic attendance management will replace the manual method,
which takes a lot of time consuming and difficult to maintain. There
are many biometric processes, in that face recognition is the best
method. In this paper we are going to describe the attendance
without human interference. In this method the camera is fixed in the
classroom and it will capture the image, the faces are detected and
then it is recognized with the database and finally the attendance is
marked. If the student attendance is finally made a report is sent to
the class teacher with his lecture attendees and absents. After the
students’ database is collected, it includes name of the students, their
images and ID number. It carries an entry in log report of every student
of each course and generates a pdf report of the attendance of the
student. There are various methods for comparing the faces. The
Eigen face is the one of the methods. Eigen faces is set of Eigen vectors
which are used in computer vision problem of face recognition.

5|Page
CHAPTER 1

INTRODUCTION

6|Pa ge
CHAPTER 1: Introduction

1.1 Introduction
The main objective of this project is to develop face recognition based,
automated student attendance system.
In order to achieve better performance, the test images and training
images of the proposed approach are limited to frontal and upright
facial images that consists of a single face only. The test images and
training images must be captured by using the same device to ensure
no quality difference. In addition, the students have to register in the
database to be recognized.
The enrolment can be done on the spot through the user-friendly
interface.

1.2 Aims and Objectives


The objective of this project is to develop face recognition
based automated student attendance system. Expected
achievements:
• To detect the face segment from the video frame.
• To extract the useful features from the face detected.

• To classify the features in order to recognize the face


detected.

7|P age
CHAPTER 1: Introduction
• To record the attendance of the identified student.

1.3 Background about technologies we use and domain


definition
Face recognition is crucial in our daily life in order to identify family,
friends or someone we are familiar with. We might not perceive that
several steps have actually been taken in order to identify human
faces. Human intelligence allows us to receive information and
interpret the information in the recognition process. We receive
information through the image projected into our eyes, by the retina,
specifically in the form of light.
Light is a form of electromagnetic waves which are radiated from a
source onto an object and projected to human vision. (Robinson-
Riegler, G., & Robinson-Riegler, B. 2008) mentioned that after visual
processing done by the human visual system, we classify shape, size,
contour and the texture of the object in order to analyze the
information. The analyzed information will be compared to other
representations of objects or faces that exist in our memory to
recognize.
In fact, it is a hard challenge to build an automated system having the
same capability as a human to recognize faces. However, we need
large memory to recognize different faces, for example, in the
Universities, there are a lot of students with different race and gender,
it is impossible to remember every face of the individuals without
making mistakes.

8|Page
CHAPTER 1: Introduction
In order to overcome human limitations, computers with almost
limitless memory, high processing speed and power are used in face
recognition systems. The human face is a unique representation of
individual identity. “Thus, face recognition is defined as a biometric
method in which identification of an individual is performed by
comparing real-time capture image with stored images in the
database of that person” (Margaret Rouse, 2012) Nowadays, face
recognition system is prevalent due to its simplicity and awesome
performance. For instance, airport protection systems and FBI use
face recognition for criminal investigations by tracking suspects,
missing children and drug activities (Robert Silk, 2017). Apart from
that, Facebook which is a popular social networking website
implement face recognition to allow the users to tag their friends in
the photo for entertainment purposes (Sidney Fussell, 2018).
Furthermore, Intel Company allows the users to use face recognition
to get access to their online account (Reichert, C., 2017). Apple allows
the users to unlock their mobile phone, iPhone X by using face
recognition (deAgonia, M., 2017).
The work on face recognition began in 1960. Woody Bledsoe, Helen
Chan Wolf and Charles Bisson had introduced a system which required
the administrator to locate eyes, ears, nose and mouth from images.
The distance and ratios between the located features and the
common reference points are then calculated and compared. The
studies are further enhanced by Goldstein, Harmon, and Lesk in 1970
by using other features such as hair color and lip thickness to
automate the recognition. In 1988, Kirby and Sirovich first suggested
principle component analysis (PCA) to solve face recognition problem.
Many studies on face

9|Pa ge
CHAPTER 1: Introduction
recognition were then conducted continuously until today (Ashley
DuVal, 2012)

1.4 Problem Statement


Traditional student attendance marking technique is often
facing a lot of trouble. The face recognition student
attendance system emphasizes its simplicity by eliminating
classical student attendance marking technique such as calling
student names or checking their identification cards. Which
not only disturb the teaching process but also causes
distraction for students during exam sessions. Apart from
calling names, attendance sheet is passed around the
classroom during the lecture sessions. The lecture class
especially the class with a large number of students might find
it difficult to have the attendance sheet being passed around
the class. Thus, face recognition student attendance system is
proposed in order to replace the manual signing of the
presence of students which are burdensome and causes
students get distracted in order to sign for their attendance.
Furthermore, the face recognition based automated student
attendance system is able to overcome the problem of
fraudulent approach and lecturers does not have to count the
number of students several times to ensure the presence of
the students.

10 | P a g e
CHAPTER 1: Introduction
The paper proposed by Zhao, W et al. (2003) has listed the
difficulties of facial identification. One of the difficulties of
facial identification is the identification between known and
unknown images. In addition, paper proposed by Pooja G.R et
al. (2010) found out that the training process for face
recognition student attendance system is slow and time-
consuming. In addition, the paper proposed by Priyanka Wagh
et al. (2015) mentioned that different lighting and head poses
are often the problems that could degrade the performance
of face recognition-based student attendance system. Hence,
there is a need to develop a real time operating student
attendance system which means the identification process
must be done within defined time constraints to prevent
omission. The extracted features from facial images which
represent the identity of the students have to be consistent
towards a change in background, illumination, pose and
expression. High accuracy and fast computation time will be
the evaluation points of the performance.

11 | P a g e
CHAPTER 1: Introduction

1.5 Expected outcome


After completing the project, We will be able to detect face
and recognize persons individually in real time. We can use it
for Auto Attendance for Students, Teacher, and Employees at
any organization. Any organization can enhance their security
system with this project!

12 | P a g e
CHAPTER 2

System Analysis

13 | P a g e
CHAPTER 2: System Analysis

2.1 System definition


Our System is partitioned into four parts as follow:
• Image Acquisition:
The system consists of a webcam that captures the image
of the classroom and sends it to the image pre-processing
module. Then that image is sent for face detection.
• Feature Extraction:
Feature extraction is done to distinguish faces of
different students using SIFT algorithm. In this phase
eyes, nose and mouth are recognized and extracted.
• Face Recognition:
The face image is then compared with the stored images.
If the face image matches a stored image and so, the face
is recognized. Then, for that particular student the
attendance is recorded.
• Administration Recognition:
The image of staff is captured, and pre-processing is done
using SIFT algorithm and then compared with stored
image in database. If matched, then attendance in the
excel format is forwarded to staff email-id.

14 | P a g e
CHAPTER 2: System Analysis

2.2 UML Analysis


Data Flow Diagram (DFD):
A data flow diagram (DFD) is a graphical representation
of the "flow" of data through an information system and
modelling its process aspects. A DFD is often used as a
preliminary step to create an overview of the system
without going into great detail.

Figure 1 DFD- Level 0

Figure 2 DFD- Level 1

15 | P a g e
CHAPTER 2: System Analysis

Figure 3 DFD- Level 2


Use Case Diagram:
A use case diagram at its simplest is a representation of a
user's interaction with the system that shows the
relationship between the user and the different use cases
in which the user is involved. A use case diagram can
identify the different types of users of a system and the
different use cases.

16 | P a g e
CHAPTER 2: System Analysis

Figure 4 Use Case for System

Figure 5 Use Case for Image Processing

17 | P a g e
CHAPTER 2: System Analysis
Activity Diagram:
Activity diagrams are graphical representations of
workflows of stepwise activities and actions with support
for choice, iteration and concurrency. In the Unified
Modelling Language, activity diagrams are intended to
model both computational and organizational processes.

18 | P a g e
CHAPTER 2: System Analysis

Figure 6 Activity Diagram

19 | P a g e
CHAPTER 2: System Analysis
State Diagram:
A state diagram is a type of diagram used to describe the
behavior of systems. They require that the system
described is composed of a finite number of states;
sometimes, this is indeed the case, while at other times
this is a reasonable abstraction.

Figure 7 State Diagram

2.3 Database Design


Entity Relationship Diagram (ERD):
An entity–relationship model describes interrelated
things of interest in a specific domain of knowledge. A
basic ER model is composed of entity types and specifies
relationships that can exist between entities.

20 | P a g e
CHAPTER 2: System Analysis

Figure 8 ERD

21 | P a g e
CHAPTER 2: System Analysis

2.4 Requirements
Requirement is very important part of developing any system.
There are two types of requirement on software
development. One is functional requirement, and another is
non-functional requirement.
Functional requirements are kind of requirements which is
focus on those activity which can easily perform by the system.
Non-functional requirements are something that can make
system efficient.

2.5 Functional Requirements


There are several functional requirements on this project. Like
establish input device, detecting face, collecting model data,
creating the dataset, train the data set and all of them were
cleared and discussed through UML Diagrams.

2.6 Nonfunctional Requirements


Non-functional requirements help to increase the efficiency of
the system. Like camera, storage for dataset, enough memory,
high speed processor, how much user friendly the system is.
Non-functional requirements are so important for the system to
give an efficient output on time. e.g. Features of the face and
will be stored in the database instead of the whole image
because it will use less memory and processing will be fast.

22 | P a g e
CHAPTER 2: System Analysis
2.1.1 Security
The computer that runs the program will have its own
security. Only the System Admin will log in to the system
and view the users. Only a faculty professor or teaching
assistant will login to the system with his/her username
and password. The person whose face recognized will
access to view the system functions.
2.1.2 Maintainability
As a tool to obtain the ease of maintainability UML
Diagrams were used in the development process as
guides.
2.1.3 Portability
To ensure portability, the application is developed in
python framework and implemented as web application.

23 | P a g e
CHAPTER 3

Development

24 | P a g e
CHAPTER 3: Development

3.1 Development Requirements


3.1.1 Face Detection:
A face detector will tell the system, whether there is a face
or not on the screen. Face detection can be done by few
parameters. Most of the face detection algorithms are follow
Viola Jones object detection framework, and it’s based on Haar
Cascades.
In this project I implement HAAR CLASSIFIER. The Haar Classifier
is a machine learning based approach, an algorithm created by
Paul Viola and Michael Jones; which are trained from many
positive images (with faces) and negatives images (without
faces).

3.1.2 Understanding Haar Cascade


The Haar feature starts scanning the image for the detection
of the face from the top left corner and ends the face detection
process bottom right corner of the image. The image is scanned
several times through the haar like features in order to detect the
face from an image.
To compute the rectangle features rapidly integral image concept
is used. It need only four values at the corners of the rectangle for
the calculation of sum of all pixels inside any given rectangle. In an
integral image the value at pixel (x,y) is the sum of pixels above
and to the left of (x,y). Sum of all pixels value in rectangle.

25 | P a g e
CHAPTER 3: Development

One Haar feature is however not enough as there are several


features that could match it. A single classifier therefore isn ’t
enough to match all the features of a face, it is called a “weak
classifier. ” Haar cascades, the basis of Viola Jones detection
framework therefore consist of a series of weak classifiers whose
accuracy is at least 50% correct. If an area passes a single classifier,
it moves to the next weak classifier and so on, otherwise, the area
does not match.
It ’ s inappropriate to detect a face with using only one Haar
feature. Every imported image has to go through every feature to
detect face. To get more accurate result in detection process, the
imported

26 | P a g e
CHAPTER 3: Development
image has to fulfill several criteria or has to pass through the
several Haar features.

Figure 9 Haar Cascade flow chart

3.1.3 Integral Image

The Integral image also known as the “summed area table”


developed in 1984 came in to widespread use in 2001 with the Haar
cascades. A summed area table is created in a single pass. This
makes the Haar cascades fast, since the sum of any region in the
image can be computed using a single formula.
The integral image computes a value at each pixel (x, y) that is the
sum of the pixel values above and to the left of (x, y), inclusive.
This can quickly be computed in one pass through the image.

27 | P a g e
CHAPTER 3: Development
Let A, B, C D be the values of the integral image at the corners of a
rectangle. The sum of original image values within the rectangle
can be computed:

𝑆𝑢𝑚 = 𝐴 − 𝐵 − 𝐶 + D

Only three additions are required for any size of rectangle. This
face detection approach minimizes computation time while
achieving high detection accuracy. It is now used in many
systems.

3.1.4 Face Recognition


There are several Algorithms in OpenCV to recognize face
after detecting. We’re using Eigenfaces for recognizing face.
Here are the steps our algorithm follow to implement it with the
project:
1) Load your training faces.
2) Convert your images into column vectors.
3) Calculate the mean
4) Reduce your matrix created in step2 using mean from step3.
5) Calculate Covariance Matrix C
6) Calculate SVD on matrix C
7) Visualize Eigenfaces
8) Reconstructing Faces
9) Recognition

28 | P a g e
CHAPTER 3: Development
3.1.5 Numpy:
NumPy is the fundamental package for scientific computing
with Python. It contains among other things:
• A powerful N-dimensional array object
• Sophisticated (broadcasting) functions
• Tools for integrating C/C++ and Fortran code
Besides its obvious scientific uses, NumPy can also be used as an
efficient multi-dimensional container of generic data. Arbitrary
datatypes can be defined. This allows NumPy to seamlessly and
speedily integrate with a wide variety of databases.

3.1.6 Open CV:


OpenCV (Open Source Computer Vision Library) is released
under a BSD license and hence it’s free for both academic and
commercial use. It has C++, Python and Java interfaces and
supports Windows, Linux, Mac OS, iOS and Android. OpenCV
was designed for computational efficiency and with a strong
focus on real-time applications. Written in optimized C/C++, the
library can take advantage of multi-core processing. Enabled
with OpenCL, it can take advantage of the hardware
acceleration of the underlying heterogeneous compute
platform.
Adopted all around the world, OpenCV has more than 47
thousand people of user community and estimated number of
downloads exceeding 14 million. Usage ranges from
interactive

29 | P a g e
CHAPTER 3: Development
art, to mines inspection, stitching maps on the web or
through advanced robotics.

3.1.7 Open CV:


Flask is a micro web framework written in Python. It is
classified as a microframework because it does not require
particular tools or libraries. It has no database abstraction layer,
form validation, or any other components where pre-existing
third-party libraries provide common functions. It’s used to
connect python code and make it readable for web applications.
We’re using it as the main framework for our web application.

30 | P a g e
CHAPTER 3: Development

3.2 Coding
3.2.1 Face Recognition Model:
Capture frames from web cam and store them in cap variable
cap = cv2.VideoCapture(0)

Make frame take full screen


cv2.namedWindow('frame', cv2.WINDOW_NORMAL)
cv2.setWindowProperty('frame', cv2.WND_PROP_FULLSCREEN,
cv2.WINDOW_FULLSCREEN)
cv2.namedWindow("frame", 0)
cv2.resizeWindow("frame", 800, 600)

Import cv model for face detection


face_cascade =
cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalfac
e_alt.xml')

Import cv model for eye detection


eye_cascade =
cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_eye_tree_
eyeglasses.xml')

Draw rectangle on face


for (x, y, w, h) in faces:
# print(x,y,w,h)

31 | P a g e
CHAPTER 3: Development
# frame start clone end clone color stroke
cv2.rectangle(frame, (x, y), (x + w, y + w), (0, 0, 255), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
eyes = eye_cascade.detectMultiScale(roi_gray)
id_, conf = reconizer.predict(roi_gray)

Draw rectangle on eye


for (ex, ey, ew, eh) in eyes:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)

Check face recognition percentage and get label by id


if conf >= 40 and conf <= 60:
if labels[id_] not in names:
names.append(labels[id_])

Click ‘q’ to kill frame


if cv2.waitKey(20) & 0xFF == ord('q'):
break

3.2.2 Model Training:


1) Reading images file
2) Pass every file to model
3) Relate feature by label that exist on file
4) Save feature and label in train.yml

32 | P a g e
CHAPTER 3: Development
import os
import cv2
import numpy as np
from PIL import Image
import pickle
BASE_DIR=os.path.dirname(os.path.abspath(__file__))
image_dir=os.path.join(BASE_DIR , "hema")
face_cascade=cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcasc
ade_frontalface_alt.xml')
reconizer=cv2.face.createLBPHFaceRecognizer()
y_label=[]
x_train=[]
current_id=0
label_ids={}
for root , dirs ,files in os.walk(image_dir):
for file in files:
if file.endswith('png') or file.endswith('jpg'):
path=os.path.join(root,file)
#root

label=os.path.basename(os.path.dirname(path)).replace(' ','-').lower()
pil_image=Image.open(path).convert('L') #convert to gray scall
size=(600,600)
final_image=pil_image.resize(size,Image.ANTIALIAS)
image_item = 'hem.png'
image_array=np.array(final_image,'uint8')
#print(image_array)
if label not in label_ids:
label_ids[label]=current_id
current_id+=1
id_=label_ids[label]

33 | P a g e
CHAPTER 3: Development
#print(label_ids)
faces = face_cascade.detectMultiScale(image_array, scaleFactor=1.5,
minNeighbors=5, minSize=(8, 8))
for (x,y,w,h) in faces:
roi=image_array[y:y+h,x:x+w]
cv2.imwrite(image_item, roi)
x_train.append(roi)
y_label.append(id_)
#print(label,path)
#x_label.append(label)
#y_train.append(path)
with open('labels.pickle','wb') as f:
pickle.dump(label_ids,f)
reconizer.train(x_train,np.array(y_label))
reconizer.save('trainner.yml')
print('recognizer is trained ')

3.2.2 Admin Tools:


Get student information to admin such as id, name, course
code, and Teacher

@app.route('/', methods=['GET', 'POST'])


def index():
d=[]
mycursor.execute('select stu_id , stu_name , course_code , course_name ,
count_att ,att_date from students join courses join courses_has_students on
students.stu_id=courses_has_students.students_stu_id and
courses.course_code=courses_has_students.courses_course_code;')
result = mycursor.fetchall()

34 | P a g e
CHAPTER 3: Development
for row in result:
d.append(row)
mydb.commit()
return render_template('admindashboard.html',data=d)

Get doctors information in doctor page


@app.route('/', methods=['GET', 'POST'])
def index():
d=[]
mycursor.execute('select stu_id , stu_name , course_code , course_name ,
count_att ,att_date from students join courses join courses_has_students on
students.stu_id=courses_has_students.students_stu_id and
courses.course_code=courses_has_students.courses_course_code;')
result = mycursor.fetchall()

for row in result:


d.append(row)
mydb.commit()

return render_template('admindashboard.html',data=d)

Return student information in student page


@app.route('/stu')
def stu():
a=[]
mycursor.execute(
'select stu_id , stu_name , stu_email , father_email ,lev_name ,
department_name from students join departments join level on
students.departments_department_id = department_id and
students.level_lev_id=level.lev_id ;')

35 | P a g e
CHAPTER 3: Development
result = mycursor.fetchall()

for row in result:


a.append(row)
mydb.commit()
return render_template('students.html',data_stu=a)

Return course information


def cour():
c=[]
mycursor.execute('select course_code , course_name , course_hour ,
doctor_name from courses join doctors on doctors.doctor_id=
courses.doctors_doctor_id;')
result = mycursor.fetchall()

for row in result:


c.append(row)
mydb.commit()
return render_template('courses.html',data_cour=c)

Add new doctors to the database


def doc_data():
id = request.form.get("id")
doctor = request.form.get("doctor")
email= request.form.get("email")
passwd = request.form.get("passwd")
m='success'

#msg=Message('{0},{1}'.format(doctor,passwd),sender='ibrahimeelqad@gma
il.com' , recipients=['{0}'.format(email)])

36 | P a g e
CHAPTER 3: Development

#mail.send(Message('{0},{1}'.format(doctor,passwd),sender='ibrahimeelqad
@gmail.com' , recipients=['{0}'.format(email)]))
mycursor.execute('insert into doctors (doctor_id , doctor_name ,
doctor_gmail , passwd) values("{0}","{1}","{2}","{3}");'.format(id, doctor,
email, passwd))
mydb.commit()

return render_template('add_d.html',m=m)

Edit teacher information:


1) Return teacher information to form page
2) Edit information and export to database system
@app.route('/doc/update_doc1' , methods=["POST"])
def update_doc1():
up_doc=[]
id = request.form.get("id")

mycursor.execute('select doctor_id , doctor_name , doctor_gmail , passwd


from doctors where doctor_id ="{0}";'.format(id))
result = mycursor.fetchall()

for row in result:


up_doc.append(row)
mydb.commit()

i=up_doc[0]
doc_id=i[0]
name=i[1]
email=i[2]
passwd=i[3]

37 | P a g e
CHAPTER 3: Development

return render_template('updatedoctor.html', doc_id=doc_id,name=name ,


email =email ,passwd=passwd)
@app.route('/doc/update_doc1/ubdate_doc2' , methods=["POST"])
def update_doc2():
id = request.form.get("id")
name= request.form.get("name")
email = request.form.get("email")
passwd = request.form.get("passwd")

mycursor.execute('update doctors set doctor_name="{0}", doctor_gmail


="{1}" , passwd="{2}" WHERE doctors.doctor_id = "{3}";'.format(name,
email, passwd, id))
mydb.commit()
return doc()

Import course information to the form


@app.route('/cour/update_cour1' , methods=["POST"])
def update_cour1():
up_doc=[]
id = request.form.get("id")

mycursor.execute('select course_code , course_name , course_hour ,


doctors_doctor_id from courses where course_code="{0}";'.format(id))

result = mycursor.fetchall()
mydb.commit()
for row in result:
up_doc.append(row)

38 | P a g e
CHAPTER 3: Development

print(up_doc)
i=up_doc[0]
cour_code=i[0]
cour_name=i[1]
hour=i[2]
teach=i[3]

return render_template('updatecourse.html',
code=cour_code,name=cour_name , hour =hour ,teach=teach)

Update information and export to database


@app.route('/cour/update_cour1/ubdate_cour2' , methods=["POST"])
def update_cour2():
code = request.form.get("code")
name= request.form.get("name")
hour = request.form.get("hour")
teach = request.form.get("teach")

mycursor.execute('update courses set course_name ="{0}" ,


course_hour="{1}" , doctors_doctor_id={2} WHERE
course_code="{3}";'.format(name,hour,teach,code))
mydb.commit()
return cour()

Import student data to form


@app.route('/stu/update_stu1' , methods=["POST"])
def update_stu1():
up_doc=[]
id = request.form.get("id")

39 | P a g e
CHAPTER 3: Development
mycursor.execute('select stu_id , stu_name ,
stu_email ,father_email,departments_department_id , level_lev_id from
students where stu_id ="{0}";'.format(id))

result = mycursor.fetchall()
mydb.commit()
for row in result:
up_doc.append(row)

print(up_doc)
i=up_doc[0]
id=i[0]
name=i[1]
stu_gmail=i[2]
fath_gmail=i[3]
depart=i[4]
level=i[5]

return render_template('updatestudent.html', id=id , name=name ,


stu_gmail=stu_gmail ,fath_gmail=fath_gmail , depart =depart ,level =level)

Edit and export students to database


def update_stu2():
id = request.form.get("id")
name= request.form.get("name")
stu_gmail = request.form.get("stu_email")
fath_gmail = request.form.get("fath_email")
depart=request.form.get("department")
level=request.form.get("level")

40 | P a g e
CHAPTER 3: Development
mycursor.execute('update students set stu_name ="{0}" ,
stu_email="{1}" ,father_email="{2}" , departments_department_id ="{3}" ,
level_lev_id ="{4}" WHERE
stu_id="{5}";'.format(name ,stu_gmail ,fath_gmail , depart ,level , id))
mydb.commit()
return stu()

Add new students


def add_stu():
id = request.form.get("id")
name = request.form.get("name")
gmail= request.form.get("gmail")
fath = request.form.get("fath")
depart = request.form.get("department")
level = request.form.get("level")
m='success'
mycursor.execute('insert into students (stu_id , stu_name , stu_email ,
father_email , departments_department_id , level_lev_id )values("{0}" ,
"{1}" , "{2}" ,"{3}" ,"{4}" ,"{5}");'.format(id , name ,gmail ,
fath ,depart ,level))
mydb.commit()

return render_template('addstudent.html',m=m)
@app.route('/cour/add_cour1',methods=["POST" ,"GET"])

Add new course


def add_cour2():
code = request.form.get("code")
name= request.form.get("name")
hour = request.form.get("hour")
teach = request.form.get("teacher")

41 | P a g e
CHAPTER 3: Development
mycursor.execute('insert into courses (course_code , course_name,
course_hour , doctors_doctor_id)values("{0}" , "{1}" ,
"{2}" ,"{3}" );'.format(code ,name ,hour ,teach))
mydb.commit()
return render_template('addcourse.html', success='success')

Relate specific student with specific course


@app.route('/rela2' , methods=['POST'])
def rela2():
id=request.form.get("id")
code=request.form.get("code")
mycursor.execute('insert into courses_has_students (courses_course_code ,
students_stu_id) values("{0}" , "{1}" );'.format(code,id))
mydb.commit()
return render_template('relation.html', data='success')

Delete specific course


def del_cour():
code = request.form.get("code")
print(code)
mycursor.execute('delete from courses_has_students where
courses_course_code ="{0}";'.format(code))
mydb.commit()
mycursor.execute('delete from courses where course_code
="{0}";'.format(code))
mydb.commit()
return cour()

42 | P a g e
CHAPTER 3: Development
Delete specific student
@app.route('/stu/del_stu' , methods=['POST'])
def del_stu():
id = request.form.get("id")
print(id)
mycursor.execute('delete from courses_has_students where students_stu_id
="{0}";'.format(id))
mydb.commit()
mycursor.execute('delete from students where stu_id="{0}";'.format(id))
mydb.commit()
return stu()

Delete specific Doctor


def del_doc():
try:
id = request.form.get("id")
mycursor.execute('delete from doctors where doctor_id
="{0}";'.format(id))
mydb.commit()
return doc()
except :
return "<h1>this doctor teach some courses and should change
data</h1>"

3.2.2 Teacher Tools:


Return report info to dashboard
def repo2():
code = request.form.get("code")
d=[]
mycursor.execute('select stu_id , stu_name , course_code , course_name ,
count_att ,att_date from students join courses join courses_has_students on

43 | P a g e
CHAPTER 3: Development
students.stu_id=courses_has_students.students_stu_id and
courses.course_code=courses_has_students.courses_course_code where
courses.course_code="{0}" ;'.format(code))
result = mycursor.fetchall()

for row in result:


d.append(row)
mydb.commit()
return render_template('admindashboard1.html',data=d)

Take ID from camera and record attendance


def take_att(course_code, syudent_id):
date = datetime.datetime.now()
mycursor = mydb.cursor()
d = []
mycursor.execute('select count_att from courses_has_students where
courses_course_code ="{0}" and students_stu_id
="{1}";'.format(course_code, syudent_id))

result = mycursor.fetchall()
mydb.commit()
print(result)

for row in result:


d.append(row)

d = d[0]
d = d[0]
d=d+1
print(d)

44 | P a g e
CHAPTER 3: Development
mycursor.execute('update courses_has_students set
count_att="{0}",att_date ="{1}" where students_stu_id ="{2}" and
courses_course_code ="{3}";'.format(d, date, syudent_id, course_code))
mydb.commit()

Open device webcam or a camera and start recognizing faces


def attendance():
code = request.form.get("code")
cap = cv2.VideoCapture(0)
cv2.namedWindow('frame', cv2.WINDOW_NORMAL)
cv2.setWindowProperty('frame', cv2.WND_PROP_FULLSCREEN,
cv2.WINDOW_FULLSCREEN)
cv2.namedWindow("frame", 0)
cv2.resizeWindow("frame", 800, 600)

face_cascade =
cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalfac
e_alt.xml')
eye_cascade =
cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_eye_tree_
eyeglasses.xml')

reconizer = cv2.face.createLBPHFaceRecognizer()
reconizer.load('trainner.yml')
labels = {'person name': 1}
with open('labels.pickle', 'rb') as f:

og_labels = pickle.load(f)
labels = {v: k for k, v in og_labels.items()}
sample = []

45 | P a g e
CHAPTER 3: Development
for i in range(len(labels)):
sample.append(labels[i])

names = []
count = 0
while True:
ret, frame = cap.read()
if ret == False:
continue

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)


faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5,
minNeighbors=5, minSize=(8, 8))

for (x, y, w, h) in faces:


# print(x,y,w,h)

# frame start clone end clone color stroke


cv2.rectangle(frame, (x, y), (x + w, y + w), (0, 0, 255), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
eyes = eye_cascade.detectMultiScale(roi_gray)
id_, conf = reconizer.predict(roi_gray)

# print(conf)
# conf for percentage
for (ex, ey, ew, eh) in eyes:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)

if conf >= 40 and conf <= 60:


if labels[id_] not in names:

46 | P a g e
CHAPTER 3: Development
names.append(labels[id_])

count = 0

else:
print(labels[id_], 'is regestered', conf)
font = cv2.FONT_HERSHEY_SIMPLEX
name = labels[id_]
color = (0, 255, 255)
stroke = 2
per = str(int(100 - conf)+20)
info = per + '%' + ' ' + name
cv2.putText(frame, info, (x, y), font, 1, color, stroke,
cv2.LINE_AA)
count = 0
else:
count += 1
font = cv2.FONT_HERSHEY_SIMPLEX
name = labels[id_]
color = (0, 255, 255)
stroke = 2
info = 'un_known'
cv2.putText(frame, info, (x, y), font, 1, color, stroke, cv2.LINE_AA)

if count == 300:
d = str(input('cant recognise who is??'))
stu_name = d + '.png'
cv2.imwrite(stu_name, roi_gray)
count = 0

# print(roi_color)
image_item = 'hema.png'

47 | P a g e
CHAPTER 3: Development
cv2.imwrite(image_item, roi_gray)
# print(frame)
# cv2.circle(frame,((x + x + w) / 2, (y + y + h) / 2), w / 2, (0, 255, 0),
2)
cv2.imshow('frame', frame)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
print(names,code)
for i in names:
print(i)
take_att(str(code), str(i))
return "<h1>GREATE , You Finished The Process</h1>"

48 | P a g e
CHAPTER 4

Design

49 | P a g e
CHAPTER 4: Design

Application Screening
Home page conta
4.1.1 Home page
• Home page contains 5 icons like:
1) admin login
2) doctor login
3) contact us
4) about us
5) home

Figure 10 home screen

50 | P a g e
CHAPTER 4: Design
• Contact us:
Register your name, your email and leave any comments
about the site .

Figure 11 contact us form

51 | P a g e
CHAPTER 4: Design
And this basic information about the site

Figure 12 site basic info.

52 | P a g e
CHAPTER 4: Design
4.1.2 admin login:
• Firstly, to login using given credentials to control the
dashboard.

Figure 13 login form

53 | P a g e
CHAPTER 4: Design
• Dashboard contains database of:
1) Relate student with doctor
2) Attendance
3) Courses
4) Students
5) Doctors

Figure 14 Admin dashboard

54 | P a g e
CHAPTER 4: Design
1) Relate student with course
This means that the student is registered in a new course.

Figure 15 register student to course

55 | P a g e
CHAPTER 4: Design
2) Attendance
Graph total attendance over the semester

Figure 16 student attendance stats

56 | P a g e
CHAPTER 4: Design
3) Courses
A table that contains information about the course and can
be modified from update button or delete course. Add new
course from add course button.

Figure 17 Courses view table

57 | P a g e
CHAPTER 4: Design
Add and Edit current courses by admin:

58 | P a g e
CHAPTER 4: Design
4) Student
A table that contains information about the students and can
be modified from update button or delete student. Add
student from add new button.

Figure 18 Students view table

59 | P a g e
CHAPTER 4: Design

Figure 19 Add new student

Figure 20 To edit students

60 | P a g e
CHAPTER 4: Design
5) Doctors
It is table that contains information about the doctors and
can be modified from update button.

Figure 21 Doctors view table

61 | P a g e
CHAPTER 4: Design

Figure 22 Edit doctor information

Figure 23 Add doctor from add new doctor button

62 | P a g e
CHAPTER 4: Design
4.1.3 Doctor login:

• Teacher page:
It will appear after doctor login.

Figure 24Teacher’s actions

63 | P a g e
CHAPTER 4: Design
• Take attendance:
1) Enter course code from course attendance form.

Figure 25 attendance taking screen

64 | P a g e
CHAPTER 4: Design
2) Camera capture student photo and
appear this message after right recognition.

65 | P a g e
CHAPTER 4: Design
• View report:
Enter course code to show attendance table of this course. The
report is a table that contains the student name, the course code,
the number of attendees and the last attendance date for each
student.

Figure 26course attendance overall report

66 | P a g e
CHAPTER 4: Design

Figure 27course report table view

67 | P a g e
CHAPTER 5

Conclusion and Future


work

68 | P a g e
CHAPTER 5: conclusion and Future work

5.1 Conclusion
Face images are the inputs for the attendance using face
recognition system. We came to realize that there are
extensive variety of methods for face recognition but some
of them are tedious and non-productive. That is why we put
on the search to choose a method that can identify faces
concisely and in a solid way. We are automating the
attendance system to decrease the errors occur due to the
manual taking attendance. We made our product as web
application so that it can be accessed in any place and using
any version of device and more accessibility in the usage.
Using artificial intelligence concept, the attendance
monitoring system is very secure, accurate and easy to
monitor students’ attendance. The system is designed to be
cost effective by being software dependent and not require
any additional hardware rather than a smartphone or a
laptop that is connected to a stable internet.

69 | P a g e
CHAPTER 5: conclusion and Future work

5.2 Future work


5.1.1 Other face recognition apps:
The same project can be utilized for several security
applications where authentication is needed to access the
privileges of the respective system. It can be used in
recognizing guilty parties involved in unauthorized
business. We can also trace a particular student in an
organization quickly with the help of this system.

5.1.2 Face recognition algorithm improvement:


Face recognition algorithm can be improved with respect
to the utilization of resources so that the project can
recognize more numbers of faces at a time which can
make the system far better.

5.1.3 Multiple device authentication:


A feature can be added to the system so that the student
can access system and mark the attendance himself using
his personal device after the teacher opens the lecture
attendance.

70 | P a g e
CHAPTER 5: conclusion and Future work
5.1.4 Mobile phone version:
Same application with its same features can be
implemented as a mobile application and publish the APK
for it since it’s more common to the user to have his most
used services as apps.

5.1.5 Desktop version:


Same application with its same features can be
implemented as a mobile application and publish the EXE
for it since it is more common to the user to have his most
used services as fixed apps on his personal device.

5.1.6 API for Attendance:


Implement the main functionality of the system
(attendance taking by face recognition function) as API so
it can be portable for various platforms and implemented
in different applications or used by other third parties.

5.1.7 Faculty system integration:


Connect with the working system in the faculty to
automatically assign professors teacher assistants and
students to new courses every new semester.

71 | P a g e
Appendixes

72 | P a g e
Appendix B: Screens and Figueres

Screens and Figures


FIGURE 1 DFD- LEVEL 0 15
FIGURE 2 DFD- LEVEL 1 15
FIGURE 3 DFD- LEVEL 2 16
FIGURE 4 USE CASE FOR SYSTEM 17
FIGURE 5 USE CASE FOR IMAGE PROCESSING 17
FIGURE 6 ACTIVITY DIAGRAM 19
FIGURE 7 STATE DIAGRAM 20
FIGURE 8 ERD 21
FIGURE 9 HAAR CASCADE FLOW CHART 27
FIGURE 10 HOME SCREEN 50
FIGURE 11 CONTACT US FORM 51
FIGURE 12 SITE BASIC INFO. 52
FIGURE 13 LOGIN FORM 53
FIGURE 14 ADMIN DASHBOARD 54
FIGURE 15 REGISTER STUDENT TO COURSE 55
FIGURE 16 STUDENT ATTENDANCE STATS 56
FIGURE 17 COURSES VIEW TABLE 57
FIGURE 18 STUDENTS VIEW TABLE 59
FIGURE 19 ADD NEW STUDENT 60
FIGURE 20 TO EDIT STUDENTS 60
FIGURE 21 DOCTORS VIEW TABLE 61
FIGURE 22 EDIT DOCTOR INFORMATION 62
FIGURE 23 ADD DOCTOR FROM ADD NEW DOCTOR BUTTO 62

73 | P a g e
FIGURE 24 TEACHER’S ACTIONS 63
FIGURE 25 ATTENDANCE TAKING SCREEN 64
FIGURE 26 COURSE ATTENDANCE OVERALL REPORT 66
FIGURE 27 COURSE REPORT TABLE VIEW 67

74 | P a g e
References
References

1. Varadharajan, E., Dharani, R., Jeevitha, S., Kavinmathi, B., & Hemalatha, S. (2016).
Automatic attendance management system using face detection. 2016 Online
International Conference on Green Engineering and Technologies (IC-GET).
doi:10.1109/get.2016.7916753
2. Automatic Student Attendance System using Face Recognition. (2020). International
Journal of Engineering and Advanced Technology Regular Issue, 9(3), 93-99.
doi:10.35940/ijeat.b4207.029320
3. Sutabri, T., Pamungkur, P., Kurniawan, A., & Saragih, R. E. (2019). Automatic Attendance
System for University Student Using Face Recognition Based on Deep Learning.
International Journal of Machine Learning and Computing, 9(5), 668-674.
doi:10.18178/ijmlc.2019.9.5.856
4. C. P., MR, BHAT, S., MR, S., MS, & S, S. K., MS. (n.d.). AUTOMATIC STUDENT ATTENDANCE
SYSTEM USING FACE RECOGNITION [Scholarly project].
5. Zhou, L. (2008). Image processing. Bellingham, WA: SPIE.
6. Birchfield, S. (2018). Image processing and analysis. Boston, MA: Cengage Learning.
7. (PDF) Student Attendance Management System. (n.d.). Retrieved July 07, 2020, from
https://www.researchgate.net/publication/323511629_Student_Attendance_Manageme
nt_System
8. Student Attendance Management System And Software. (n.d.). Retrieved July 07, 2020,
from http://www.technospacio.com/student-attendance.html
9. Howse, J., Joshi, P., & Beyeler, M. (2016). OpenCV: Computer vision projects with Python:
Get savvy with OpenCV and actualize cool computer vision applications: A course in three
modules. Birmingham, UK: Packt.

75 | P a g e

Вам также может понравиться