├── requirements.txt ├── demo ├── User Adding.jpeg ├── User count.jpeg ├── USER INTERFACE.jpeg ├── Camer Capturing.jpeg ├── CSV ATTENDANCE RECORD.jpeg ├── Live Images Capturing.jpeg └── Take attendance button.jpeg ├── static ├── images │ ├── logo2.png │ ├── companylogo.jpg │ └── adminlogin.css ├── face_recognition_model.pkl └── style.css ├── templates ├── admin.html ├── adminlogin.html └── home.html ├── README.md ├── .gitignore └── app.py /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/requirements.txt -------------------------------------------------------------------------------- /demo/User Adding.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/User Adding.jpeg -------------------------------------------------------------------------------- /demo/User count.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/User count.jpeg -------------------------------------------------------------------------------- /demo/USER INTERFACE.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/USER INTERFACE.jpeg -------------------------------------------------------------------------------- /static/images/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/static/images/logo2.png -------------------------------------------------------------------------------- /demo/Camer Capturing.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/Camer Capturing.jpeg -------------------------------------------------------------------------------- /static/images/companylogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/static/images/companylogo.jpg -------------------------------------------------------------------------------- /demo/CSV ATTENDANCE RECORD.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/CSV ATTENDANCE RECORD.jpeg -------------------------------------------------------------------------------- /demo/Live Images Capturing.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/Live Images Capturing.jpeg -------------------------------------------------------------------------------- /demo/Take attendance button.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/demo/Take attendance button.jpeg -------------------------------------------------------------------------------- /static/face_recognition_model.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frozen-dev71/attendance-management/main/static/face_recognition_model.pkl -------------------------------------------------------------------------------- /templates/admin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /templates/adminlogin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Sign in 6 | 7 | 9 | 10 | 11 | 12 |
13 | 16 |
17 | Twitter 18 |
19 |
20 |
21 | 22 | 23 |
24 |
25 | 26 | 27 |
28 | 29 |
30 |
31 | Forget password? or Sign up 32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Face Recognition Attendance System 3 | 4 | ## Description 5 | Software for Industry , where they can track the attendence of their employee with the help of face recognition using OpenCV library. 6 | 7 | ## Table of Contents 8 | - [Project Plan](#project-plan) 9 | - [Features](#features) 10 | - [Installation](#installation) 11 | - [Usage](#usage) 12 | - [Contributing](#contributing) 13 | - [License](#license) 14 | 15 | ## Project Plan 16 | - Task: 17 | - [x] Create a home page 18 | - [x] Show attendence log on home for particular day 19 | - [ ] Recreate a HTML , bootstrap boilerplate and remove unwanted code 20 | - [ ] Show date and day on home page 21 | - [ ] Company name should be visible on home page 22 | - [ ] Show list of total Employee on home page 23 | - [ ] Create a Admin panel 24 | - [ ] Give various rights to admin 25 | - [ ] Work on UI 26 | 27 | ## Features 28 | - Adding a New User 29 | 30 | - Capturing Live Images 31 | 32 | - To understand the Total number of Users in Database 33 | 34 | - Click on Take Attendance 35 | 36 | - Multiple User Faces can be detected 37 | 38 | - Attendance of Multiple Users taken 39 | 40 | - Attendance of Users displayed 41 | 42 | ## Installation 43 | - Explain how to install or set up the project. 44 | 45 | ## Usage 46 | - this is useful in tracking the attendence of your employees 47 | 48 | ## Contributing 49 | - Contributers are welcomed, you can simply fork the repo and contribute , and make PR 50 | - Dont wait for getting issue assigned to you 51 | ## License 52 | - Include information about the project's license. 53 | 54 | -------------------------------------------------------------------------------- /static/images/adminlogin.css: -------------------------------------------------------------------------------- 1 | /* Importing fonts from Google */ 2 | @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap'); 3 | 4 | /* Reseting */ 5 | * { 6 | margin: 0; 7 | padding: 0; 8 | box-sizing: border-box; 9 | font-family: 'Poppins', sans-serif; 10 | } 11 | 12 | body { 13 | background: #ecf0f3; 14 | } 15 | 16 | .wrapper { 17 | max-width: 350px; 18 | min-height: 500px; 19 | margin: 80px auto; 20 | padding: 40px 30px 30px 30px; 21 | background-color: #ecf0f3; 22 | border-radius: 15px; 23 | box-shadow: 13px 13px 20px #cbced1, -13px -13px 20px #fff; 24 | } 25 | 26 | .logo { 27 | width: 80px; 28 | margin: auto; 29 | } 30 | 31 | .logo img { 32 | width: 100%; 33 | height: 80px; 34 | object-fit: cover; 35 | border-radius: 50%; 36 | box-shadow: 0px 0px 3px #5f5f5f, 37 | 0px 0px 0px 5px #ecf0f3, 38 | 8px 8px 15px #a7aaa7, 39 | -8px -8px 15px #fff; 40 | } 41 | 42 | .wrapper .name { 43 | font-weight: 600; 44 | font-size: 1.4rem; 45 | letter-spacing: 1.3px; 46 | padding-left: 10px; 47 | color: #555; 48 | } 49 | 50 | .wrapper .form-field input { 51 | width: 100%; 52 | display: block; 53 | border: none; 54 | outline: none; 55 | background: none; 56 | font-size: 1.2rem; 57 | color: #666; 58 | padding: 10px 15px 10px 10px; 59 | /* border: 1px solid red; */ 60 | } 61 | 62 | .wrapper .form-field { 63 | padding-left: 10px; 64 | margin-bottom: 20px; 65 | border-radius: 20px; 66 | box-shadow: inset 8px 8px 8px #cbced1, inset -8px -8px 8px #fff; 67 | } 68 | 69 | .wrapper .form-field .fas { 70 | color: #555; 71 | } 72 | 73 | .wrapper .btn { 74 | box-shadow: none; 75 | width: 100%; 76 | height: 40px; 77 | background-color: #03A9F4; 78 | color: #fff; 79 | border-radius: 25px; 80 | box-shadow: 3px 3px 3px #b1b1b1, 81 | -3px -3px 3px #fff; 82 | letter-spacing: 1.3px; 83 | } 84 | 85 | .wrapper .btn:hover { 86 | background-color: #039BE5; 87 | } 88 | 89 | .wrapper a { 90 | text-decoration: none; 91 | font-size: 0.8rem; 92 | color: #03A9F4; 93 | } 94 | 95 | .wrapper a:hover { 96 | color: #039BE5; 97 | } 98 | 99 | @media(max-width: 380px) { 100 | .wrapper { 101 | margin: 30px 20px; 102 | padding: 40px 15px 15px 15px; 103 | } 104 | } -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | .navbar-text { 2 | padding-top: 0.5rem; 3 | padding-bottom: 0.5rem; 4 | color: black; 5 | } 6 | 7 | /* Custom styles for the navbar */ 8 | .custom-navbar { 9 | background-color: rgba(194, 217, 255, 0.6); /* Semi-transparent white background */ 10 | border-radius: 30px; /* Capsule shape */ 11 | margin-top: 10px; /* Margin from the top */ 12 | margin-left: 20px; /* Margin from the left */ 13 | margin-right: 20px; /* Margin from the right */ 14 | } 15 | 16 | .custom-navbar .navbar-brand { 17 | color: black; /* Text color for the company name */ 18 | font-size: 26px; /* Increase font size */ 19 | margin-left: 20px; /* Margin from the left to the logo */ 20 | } 21 | 22 | .custom-navbar .navbar-brand:hover { 23 | text-decoration: none; /* Remove the underline on hover */ 24 | } 25 | 26 | .custom-navbar .nav-link { 27 | color: black; /* Text color for other links */ 28 | transition: box-shadow 0.3s; /* Smooth transition for the shadow */ 29 | font-size: 18px; /* Increase font size */ 30 | } 31 | 32 | .custom-navbar .nav-link:hover { 33 | box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); /* Add a shadow on hover */ 34 | } 35 | 36 | .custom-navbar .navbar-text { 37 | font-size: 18px; /* Increase font size */ 38 | } 39 | 40 | .custom-navbar .btn { 41 | background-color: #6c3483; /* Dark purple background for the button */ 42 | color: white; /* Button text color */ 43 | border: none; 44 | } 45 | 46 | .custom-navbar .btn:hover { 47 | background-color: #5b2a6e; /* Dark purple background on hover */ 48 | } 49 | 50 | /* Additional CSS to clear floats */ 51 | .clearfix::after { 52 | content: ""; 53 | clear: both; 54 | display: table; 55 | } 56 | 57 | 58 | #Abutton{ 59 | font-size: 24px; 60 | font-weight: bold; 61 | border-radius: 10px; 62 | width:250px; 63 | padding: 10px; 64 | margin-top: 30px; 65 | margin-bottom: 30px; 66 | color: #17139e; 67 | box-shadow: 15px 15px 19px rgba(0, 0, 0, 0.1); 68 | transition: all 0.3s ease 0s; 69 | outline: none; 70 | } 71 | #Abutton:hover{ 72 | color: white; 73 | background-color: #17139e; 74 | box-shadow: 0px 15px 20px #6864d7; 75 | transform: translateY(-7px); 76 | } 77 | 78 | #add{ 79 | font-size: 18px; 80 | font-weight: bold; 81 | border-radius: 10px; 82 | width:200px; 83 | padding: 10px; 84 | margin-top: 15px; 85 | margin-bottom: 1px; 86 | color: #17139e; 87 | box-shadow: 15px 15px 19px rgba(0, 0, 0, 0.1); 88 | transition: all 0.3s ease 0s; 89 | outline: none; 90 | } 91 | #add:hover{ 92 | color: white; 93 | background-color: #17139e; 94 | box-shadow: 0px 15px 20px #6864d7; 95 | transform: translateY(-7px); 96 | } 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #for this project 2 | /static/faces/ 3 | /Attendance 4 | .idea 5 | 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | share/python-wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | MANIFEST 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .nox/ 48 | .coverage 49 | .coverage.* 50 | .cache 51 | nosetests.xml 52 | coverage.xml 53 | *.cover 54 | *.py,cover 55 | .hypothesis/ 56 | .pytest_cache/ 57 | cover/ 58 | 59 | # Translations 60 | *.mo 61 | *.pot 62 | 63 | # Django stuff: 64 | *.log 65 | local_settings.py 66 | db.sqlite3 67 | db.sqlite3-journal 68 | 69 | # Flask stuff: 70 | instance/ 71 | .webassets-cache 72 | 73 | # Scrapy stuff: 74 | .scrapy 75 | 76 | # Sphinx documentation 77 | docs/_build/ 78 | 79 | # PyBuilder 80 | .pybuilder/ 81 | target/ 82 | 83 | # Jupyter Notebook 84 | .ipynb_checkpoints 85 | 86 | # IPython 87 | profile_default/ 88 | ipython_config.py 89 | 90 | # pyenv 91 | # For a library or package, you might want to ignore these files since the code is 92 | # intended to run in multiple environments; otherwise, check them in: 93 | # .python-version 94 | 95 | # pipenv 96 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 97 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 98 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 99 | # install all needed dependencies. 100 | #Pipfile.lock 101 | 102 | # poetry 103 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 104 | # This is especially recommended for binary packages to ensure reproducibility, and is more 105 | # commonly ignored for libraries. 106 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 107 | #poetry.lock 108 | 109 | # pdm 110 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 111 | #pdm.lock 112 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 113 | # in version control. 114 | # https://pdm.fming.dev/#use-with-ide 115 | .pdm.toml 116 | 117 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 118 | __pypackages__/ 119 | 120 | # Celery stuff 121 | celerybeat-schedule 122 | celerybeat.pid 123 | 124 | # SageMath parsed files 125 | *.sage.py 126 | 127 | # Environments 128 | .env 129 | .venv 130 | env/ 131 | venv/ 132 | ENV/ 133 | env.bak/ 134 | venv.bak/ 135 | 136 | # Spyder project settings 137 | .spyderproject 138 | .spyproject 139 | 140 | # Rope project settings 141 | .ropeproject 142 | 143 | # mkdocs documentation 144 | /site 145 | 146 | # mypy 147 | .mypy_cache/ 148 | .dmypy.json 149 | dmypy.json 150 | 151 | # Pyre type checker 152 | .pyre/ 153 | 154 | # pytype static type analyzer 155 | .pytype/ 156 | 157 | # Cython debug symbols 158 | cython_debug/ 159 | 160 | # PyCharm 161 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 162 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 163 | # and can be added to the global gitignore or merged into this file. For a more nuclear 164 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 165 | #.idea/ 166 | -------------------------------------------------------------------------------- /templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Face Recognised Attendence 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 | Company Logo 26 | Company Name 27 | 28 | 29 | Face Recognised attendence system 30 | 31 |
32 | 33 | Date: 26/10/2023, Wednesday 34 | 35 | 36 | Time: 09:09 AM 37 | 38 |
39 | 40 |
41 |
42 |
43 | 44 |
45 |

{{mess}}

46 |
48 |

Today's 49 | Attendance assignment

50 | 51 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | {% if l %} 63 | 64 | {% for i in range(l) %} 65 | 66 | 67 | 68 | 69 | 70 | 71 | {% endfor %} 72 | {% endif %} 73 |
S NoNameIDTime
{{ i+1 }}{{ names[i] }}{{ rolls[i] }}{{ times[i] }}
74 |
75 |
76 |
77 |
79 |
80 |

Add 81 | New User control_point_duplicate

82 | 83 |
84 | 86 |
87 | 88 |
89 | 91 |
92 | 94 |
95 | 96 | 97 |
98 |
Total Users in Database: {{totalreg}}
99 |
100 |
101 | 102 |
103 |
104 |

Total Users lists

105 |
106 |
107 |
108 | 109 | 110 | 111 | 112 |
113 | 127 |
128 | 129 | 130 |
131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import cv2 3 | import os 4 | from flask import Flask,request,render_template,redirect,session,url_for 5 | from datetime import date 6 | from datetime import datetime 7 | import numpy as np 8 | from sklearn.neighbors import KNeighborsClassifier 9 | import pandas as pd 10 | import joblib 11 | import time 12 | # import db 13 | 14 | #VARIABLES 15 | MESSAGE = "WELCOME " \ 16 | " Instruction: to register your attendence kindly click on 'a' on keyboard" 17 | 18 | #### Defining Flask App 19 | app = Flask(__name__) 20 | 21 | #### Saving Date today in 2 different formats 22 | datetoday = date.today().strftime("%m_%d_%y") 23 | datetoday2 = date.today().strftime("%d-%B-%Y") 24 | 25 | #### Initializing VideoCapture object to access WebCam 26 | face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 27 | try: 28 | cap = cv2.VideoCapture(1) 29 | except: 30 | cap = cv2.VideoCapture(0) 31 | 32 | #### If these directories don't exist, create them 33 | if not os.path.isdir('Attendance'): 34 | os.makedirs('Attendance') 35 | if not os.path.isdir('static'): 36 | os.makedirs('static') 37 | if not os.path.isdir('static/faces'): 38 | os.makedirs('static/faces') 39 | if f'Attendance-{datetoday}.csv' not in os.listdir('Attendance'): 40 | with open(f'Attendance/Attendance-{datetoday}.csv','w') as f: 41 | f.write('Name,Roll,Time') 42 | 43 | #### get a number of total registered users 44 | 45 | def totalreg(): 46 | return len(os.listdir('static/faces')) 47 | 48 | #### extract the face from an image 49 | def extract_faces(img): 50 | if img!=[]: 51 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 52 | face_points = face_detector.detectMultiScale(gray, 1.3, 5) 53 | return face_points 54 | else: 55 | return [] 56 | 57 | #### Identify face using ML model 58 | def identify_face(facearray): 59 | model = joblib.load('static/face_recognition_model.pkl') 60 | return model.predict(facearray) 61 | 62 | #### A function which trains the model on all the faces available in faces folder 63 | def train_model(): 64 | faces = [] 65 | labels = [] 66 | userlist = os.listdir('static/faces') 67 | for user in userlist: 68 | for imgname in os.listdir(f'static/faces/{user}'): 69 | img = cv2.imread(f'static/faces/{user}/{imgname}') 70 | resized_face = cv2.resize(img, (50, 50)) 71 | faces.append(resized_face.ravel()) 72 | labels.append(user) 73 | faces = np.array(faces) 74 | knn = KNeighborsClassifier(n_neighbors=5) 75 | knn.fit(faces,labels) 76 | joblib.dump(knn,'static/face_recognition_model.pkl') 77 | 78 | #### Extract info from today's attendance file in attendance folder 79 | def extract_attendance(): 80 | df = pd.read_csv(f'Attendance/Attendance-{datetoday}.csv') 81 | names = df['Name'] 82 | rolls = df['Roll'] 83 | times = df['Time'] 84 | l = len(df) 85 | return names,rolls,times,l 86 | 87 | #### Add Attendance of a specific user 88 | def add_attendance(name): 89 | username = name.split('_')[0] 90 | userid = name.split('_')[1] 91 | current_time = datetime.now().strftime("%H:%M:%S") 92 | 93 | df = pd.read_csv(f'Attendance/Attendance-{datetoday}.csv') 94 | if str(userid) not in list(df['Roll']): 95 | with open(f'Attendance/Attendance-{datetoday}.csv','a') as f: 96 | f.write(f'\n{username},{userid},{current_time}') 97 | else: 98 | print("this user has already marked attendence for the day , but still i am marking it ") 99 | # with open(f'Attendance/Attendance-{datetoday}.csv','a') as f: 100 | # f.write(f'\n{username},{userid},{current_time}') 101 | 102 | 103 | ################## ROUTING FUNCTIONS ############################## 104 | 105 | #### Our main page 106 | @app.route('/') 107 | def home(): 108 | names,rolls,times,l = extract_attendance() 109 | return render_template('home.html',names=names,rolls=rolls,times=times,l=l,totalreg=totalreg(),datetoday2=datetoday2, mess = MESSAGE) 110 | 111 | 112 | #### This function will run when we click on Take Attendance Button 113 | @app.route('/start',methods=['GET']) 114 | def start(): 115 | ATTENDENCE_MARKED = False 116 | if 'face_recognition_model.pkl' not in os.listdir('static'): 117 | names, rolls, times, l = extract_attendance() 118 | MESSAGE = 'This face is not registered with us , kindly register yourself first' 119 | print("face not in database, need to register") 120 | return render_template('home.html',names=names,rolls=rolls,times=times,l=l,totalreg=totalreg,datetoday2=datetoday2, mess = MESSAGE) 121 | # return render_template('home.html',totalreg=totalreg(),datetoday2=datetoday2,mess='There is no trained model in the static folder. Please add a new face to continue.') 122 | 123 | cap = cv2.VideoCapture(0) 124 | ret = True 125 | while True: 126 | # Read a frame from the camera 127 | ret, frame = cap.read() 128 | 129 | # Convert the frame to grayscale 130 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 131 | 132 | # Detect faces in the grayscale frame 133 | faces = face_detector.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5) 134 | 135 | # Draw rectangles around the detected faces 136 | for (x, y, w, h) in faces: 137 | cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) 138 | face = cv2.resize(frame[y:y+h,x:x+w], (50, 50)) 139 | identified_person = identify_face(face.reshape(1,-1))[0] 140 | cv2.putText(frame, f'{identified_person}', (x + 6, y - 6), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 20), 2) 141 | if cv2.waitKey(1) == ord('a'): 142 | add_attendance(identified_person) 143 | current_time_ = datetime.now().strftime("%H:%M:%S") 144 | print(f"attendence marked for {identified_person}, at {current_time_} ") 145 | ATTENDENCE_MARKED = True 146 | break 147 | if ATTENDENCE_MARKED: 148 | # time.sleep(3) 149 | break 150 | 151 | # Display the resulting frame 152 | cv2.imshow('Attendance Check, press "q" to exit', frame) 153 | cv2.putText(frame,'hello',(30,30),cv2.FONT_HERSHEY_COMPLEX,2,(255, 255, 255)) 154 | 155 | # Wait for the user to press 'q' to quit 156 | if cv2.waitKey(1) == ord('q'): 157 | break 158 | 159 | cap.release() 160 | cv2.destroyAllWindows() 161 | names, rolls, times, l = extract_attendance() 162 | MESSAGE = 'Attendence taken successfully' 163 | print("attendence registered") 164 | return render_template('home.html', names=names, rolls=rolls, times=times, l=l, totalreg=totalreg(), 165 | datetoday2=datetoday2, mess=MESSAGE) 166 | 167 | @app.route('/add',methods=['GET','POST']) 168 | def add(): 169 | newusername = request.form['newusername'] 170 | newuserid = request.form['newuserid'] 171 | userimagefolder = 'static/faces/'+newusername+'_'+str(newuserid) 172 | if not os.path.isdir(userimagefolder): 173 | os.makedirs(userimagefolder) 174 | cap = cv2.VideoCapture(0) 175 | i,j = 0,0 176 | while 1: 177 | _,frame = cap.read() 178 | faces = extract_faces(frame) 179 | for (x,y,w,h) in faces: 180 | cv2.rectangle(frame,(x, y), (x+w, y+h), (255, 0, 20), 2) 181 | cv2.putText(frame,f'Images Captured: {i}/50',(30,30),cv2.FONT_HERSHEY_SIMPLEX,1,(255, 0, 20),2,cv2.LINE_AA) 182 | if j%10==0: 183 | name = newusername+'_'+str(i)+'.jpg' 184 | cv2.imwrite(userimagefolder+'/'+name,frame[y:y+h,x:x+w]) 185 | i+=1 186 | j+=1 187 | if j==500: 188 | break 189 | cv2.imshow('Adding new User',frame) 190 | if cv2.waitKey(1)==27: 191 | break 192 | cap.release() 193 | cv2.destroyAllWindows() 194 | print('Training Model') 195 | train_model() 196 | names,rolls,times,l = extract_attendance() 197 | if totalreg() > 0 : 198 | names, rolls, times, l = extract_attendance() 199 | MESSAGE = 'User added Sucessfully' 200 | print("message changed") 201 | return render_template('home.html',names=names,rolls=rolls,times=times,l=l,totalreg=totalreg(),datetoday2=datetoday2, mess = MESSAGE) 202 | else: 203 | return redirect(url_for('home.html',names=names,rolls=rolls,times=times,l=l,totalreg=totalreg(),datetoday2=datetoday2)) 204 | # return render_template('home.html',names=names,rolls=rolls,times=times,l=l,totalreg=totalreg(),datetoday2=datetoday2) 205 | 206 | #### Our main function which runs the Flask App 207 | app.run(debug=True,port=1000) 208 | if __name__ == '__main__': 209 | pass 210 | #### This function will run when we add a new user 211 | --------------------------------------------------------------------------------