Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhruv committed Feb 27, 2021
0 parents commit 467e6cd
Show file tree
Hide file tree
Showing 632 changed files with 1,311,815 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
__pycache__
venv
76 changes: 76 additions & 0 deletions .ipynb_checkpoints/Capture_Image-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import csv

import cv2
import os


# counting the numbers


def is_number(s):
try:
float(s)
return True
except ValueError:
pass

try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass

return False



# Take image function

def takeImages():


Id = input("Enter Your Id: ")
name = input("Enter Your Name: ")
email = input("Enter Your emailid: ")

if(is_number(Id) and name.isalpha()):
cam = cv2.VideoCapture(0)
harcascadePath = "haarcascade_frontalface_default.xml"
detector = cv2.CascadeClassifier(harcascadePath)
sampleNum = 0

while(True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5, minSize=(30,30),flags = cv2.CASCADE_SCALE_IMAGE)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (10, 159, 255), 2)
#incrementing sample number
sampleNum = sampleNum+1
#saving the captured face in the dataset folder TrainingImage
cv2.imwrite("TrainingImage" + os.sep +name + "."+Id + '.' +
str(sampleNum) + ".jpg", gray[y:y+h, x:x+w])
#display the frame
cv2.imshow('frame', img)
#wait for 100 miliseconds
if cv2.waitKey(100) & 0xFF == ord('q'):
break
# break if the sample number is more than 100
elif sampleNum > 100:
break
cam.release()
cv2.destroyAllWindows()
res = "Images Saved for ID : " + Id + " Name : " + name + "Email :" + email
row = [Id, name,email]
with open("StudentDetails"+os.sep+"StudentDetails.csv", 'a+') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
else:
if(is_number(Id)):
print("Enter Alphabetical Name")
if(name.isalpha()):
print("Enter Numeric ID")


2 changes: 2 additions & 0 deletions .ipynb_checkpoints/Info-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EMAIL_ID = ''
PASSWORD = ''
94 changes: 94 additions & 0 deletions .ipynb_checkpoints/Recognize-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import datetime
import os
import time

import cv2
import pandas as pd
from csv import writer

#-------------------------
def recognize_attendence():
recognizer = cv2.face.LBPHFaceRecognizer_create() # cv2.createLBPHFaceRecognizer()
recognizer.read("TrainingImageLabel"+os.sep+"Trainner.yml")
harcascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(harcascadePath)
df = pd.read_csv("StudentDetails"+os.sep+"StudentDetails.csv")
font = cv2.FONT_HERSHEY_SIMPLEX
col_names = ['Id', 'Name', 'Time']
attendance = pd.DataFrame(columns=col_names)

# Initialize and start realtime video capture
cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cam.set(3, 640) # set video width
cam.set(4, 480) # set video height
# Define min window size to be recognized as a face
minW = 0.1 * cam.get(3)
minH = 0.1 * cam.get(4)

while True:
minThreshold = 55 # Accurate minThresold = 67

ret, im = cam.read()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, 1.2, 5,minSize = (int(minW), int(minH)),flags = cv2.CASCADE_SCALE_IMAGE)
for(x, y, w, h) in faces:
cv2.rectangle(im, (x, y), (x+w, y+h), (10, 159, 255), 2)
Id, conf = recognizer.predict(gray[y:y+h, x:x+w])

if conf < 100:

aa = df.loc[df['Id'] == Id]['Name'].values
confstr = " {0}%".format(round(100 - conf))
tt = str(Id)+"-"+aa

else:
Id = ' Unknown '
tt = str(Id)
confstr = " {0}%".format(round(100 - conf))

# if (100-conf) > 67:
if (100-conf) > minThreshold:
ts = time.time()
timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
aa = str(aa)[2:-2]

attendance.loc[len(attendance)] = [Id, aa, timeStamp]
tt = str(tt)[2:-2]
if(100-conf) > minThreshold:
tt = tt + " [Pass]"
cv2.putText(im, str(tt), (x+5,y-5), font, 1, (255, 255, 255), 2)
else:
cv2.putText(im, str(tt), (x + 5, y - 5), font, 1, (255, 255, 255), 2)

if (100-conf) > minThreshold:
cv2.putText(im, str(confstr), (x + 5, y + h - 5), font,1, (0, 255, 0),1 )
elif (100-conf) > 50:
cv2.putText(im, str(confstr), (x + 5, y + h - 5), font, 1, (0, 255, 255), 1)
else:
cv2.putText(im, str(confstr), (x + 5, y + h - 5), font, 1, (0, 0, 255), 1)



attendance = attendance.drop_duplicates(subset=['Id'], keep='first')
cv2.imshow('Attendance', im)
if (cv2.waitKey(1) == ord('q')):
break
ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
Hour, Minute, Second = timeStamp.split(":")
# fileName = "Attendance"+os.sep+"Attendance_"+date+"_"+Hour+"-"+Minute+"-"+Second+".csv"
fileName ="Attendance"+os.sep+"Attendance_"+date+".csv"
temp = os.getcwd()+os.sep+fileName
if os.path.exists(temp):
old_file = pd.read_csv(temp)
new_file = pd.concat([old_file,attendance])
new_file.drop_duplicates(subset=['Id'], keep='first',inplace=True)
new_file.to_csv(fileName, index=False)
else:
attendance.to_csv(fileName, index=False)
print("Attendance Successful")
cam.release()
cv2.destroyAllWindows()


37 changes: 37 additions & 0 deletions .ipynb_checkpoints/automail-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import yagmail
import os
import datetime
import Info
import pandas as pd
import numpy as np

date = datetime.date.today().strftime("%B %d, %Y")
path = 'Attendance'
os.chdir(path)
files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)
# receiver = '[email protected]'
# receiver = '[email protected]'
df = pd.read_csv(r'C:\Users\neel\Desktop\FRAS (1)\FRAS\StudentDetails\StudentDetails.csv') #ama check kari lejo ke path set che ne

receivers = df["email"]
newest = files[-1]
filename = newest
sub = "Attendance Report for " + str(date)
body = " Attendance Submitted."

for receiver in receivers:
# receiver = '[email protected]'
# mail information
if pd.isnull(reciver):
continue
else:
yag = yagmail.SMTP(Info.EMAIL_ID, Info.PASSWORD)

# sent the mail
yag.send(
to=receiver,
subject=sub, # email subject
contents=body, # email body
attachments= filename # file attached
)
print("Email Sent to "+reciver)
101 changes: 101 additions & 0 deletions .ipynb_checkpoints/main-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os # accessing the os functions
import check_camera
import Capture_Image
import Train_Image
import Recognize


# creating the title bar function

def title_bar():
os.system('cls') # for windows

# title of the program

print("\t**********************************************")
print("\t***** Face Recognition Attendance System *****")
print("\t**********************************************")


# creating the user main menu function

def mainMenu():
title_bar()
print()
print(10 * "*", "WELCOME MENU", 10 * "*")
print("[1] Check Camera")
print("[2] Capture Faces")
print("[3] Train Images")
print("[4] Recognize & Attendance")
print("[5] Auto Mail")
print("[6] Quit")

while True:
try:
choice = int(input("Enter Choice: "))

if choice == 1:
checkCamera()
break
elif choice == 2:
CaptureFaces()
break
elif choice == 3:
Trainimages()
break
elif choice == 4:
RecognizeFaces()
break
elif choice == 5:
os.system("py automail.py")
break
mainMenu()
elif choice == 6:
print("Thank You")
break
else:
print("Invalid Choice. Enter 1-4")
mainMenu()
except ValueError:
print("Invalid Choice. Enter 1-4\n Try Again")
exit


# ---------------------------------------------------------
# calling the camera test function from check camera.py file

def checkCamera():
check_camera.camer()
key = input("Enter any key to return main menu")
mainMenu()


# --------------------------------------------------------------
# calling the take image function form capture image.py file

def CaptureFaces():
Capture_Image.takeImages()
key = input("Enter any key to return main menu")
mainMenu()


# -----------------------------------------------------------------
# calling the train images from train_images.py file

def Trainimages():
Train_Image.TrainImages()
key = input("Enter any key to return main menu")
mainMenu()


# --------------------------------------------------------------------
# calling the recognize_attendance from recognize.py file

def RecognizeFaces():
Recognize.recognize_attendence()
key = input("Enter any key to return main menu")
mainMenu()


# ---------------main driver ------------------
mainMenu()
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: python
python:
- "3.7"
# command to install dependencies
cache: pip
install:
- pip install -r requirements.txt
# command to run tests
script: python main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Id,Name,Time
1234,Urvesh,17.19.16
29,neel,17.19.28
69,dp,17.20.46
98,nirja,17.20.50
123,neel,17:53:32
234,parul,17:53:39
8 changes: 8 additions & 0 deletions Attendance/Attendance_2019-08-22_00-38-17.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Id,Name,Date,Time
1,['Mubin'],8/22/2019,0:36:55
7,['Jonny'],8/22/2019,0:37:06
6,['Ajay'],8/22/2019,0:37:33
5,['Aksay'],8/22/2019,0:37:48
4,['Salman'],8/22/2019,0:37:56
3,['Tom'],8/22/2019,0:38:03
2,['Aamir'],8/22/2019,0:38:10
9 changes: 9 additions & 0 deletions Attendance/Attendance_2019-08-24_13-34-43.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Id,Name,Date,Time
2,['Jacky'],8/24/2019,13:31:55
3,['Aamir'],8/24/2019,13:32:11
4,['Tom'],8/24/2019,13:32:19
1,['Mubin'],8/24/2019,13:32:38
6,['Aksay'],8/24/2019,13:33:05
12,['Bruce'],8/24/2019,13:34:09
13,['Jonny'],8/24/2019,13:34:17
11,['Kasfia'],8/24/2019,13:34:23
3 changes: 3 additions & 0 deletions Attendance/Attendance_2019-08-24_14-11-44.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Id,Name,Date,Time
14,['Fuad'],2019-08-24,14:11:34
1,['Mubin'],2019-08-24,14:11:42
2 changes: 2 additions & 0 deletions Attendance/Attendance_2019-08-24_14-44-53.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Id,Name,Date,Time
15,['jawad'],2019-08-24,14:44:39
8 changes: 8 additions & 0 deletions Attendance/Attendance_2021-02-27.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Id,Name,Time
1234,Urvesh,17.19.16
29,neel,17.19.28
69,dp,17.20.46
98,nirja,17.20.50
123,neel,17:53:32
234,parul,17:53:39
456,neelshah,20:14:44
Loading

0 comments on commit 467e6cd

Please sign in to comment.