-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a23dc90
Showing
5 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pandas import read_csv | ||
import datetime as dt | ||
|
||
def mark_attendance(names): | ||
names=set(names) | ||
print(names) | ||
df=read_csv('attendance_data/attendance.csv',index_col='Name') | ||
|
||
today=dt.datetime.now() | ||
today=today.strftime('%d/%m/%y') | ||
|
||
student_status=['Nil' for i in range(len(df))] | ||
|
||
df[today]=student_status | ||
|
||
for i in names: | ||
df.loc[i]['25/08/19']='Yes' | ||
df.to_csv('attendance_data/attendance.csv') | ||
df.to_excel(r'attendance_data/attendance.xlsx',header=True) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import cv2 | ||
from tkinter import * | ||
from tkinter import messagebox | ||
import os | ||
from time import sleep | ||
|
||
def create_dir(): | ||
label=[] | ||
dir1=os.getcwd()+'/training_data' | ||
for x,y,z in os.walk(dir1): | ||
for a in y: | ||
label.append(int(a)) | ||
if label==[]: | ||
i='0' | ||
else: | ||
i=max(label) | ||
i=i+1 | ||
|
||
os.chdir('training_data') | ||
os.mkdir(str(i)) | ||
os.chdir(str(i)) | ||
|
||
return os.getcwd() | ||
|
||
def capture_pic(root,entry1): | ||
name=entry1.get() | ||
root.destroy() | ||
cwd=create_dir() | ||
cam=cv2.VideoCapture(0) | ||
ch=1 | ||
while True: | ||
ret,frame=cam.read() | ||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | ||
cv2.imshow('Capturing',gray) | ||
cv2.imwrite(name+str(ch)+'.jpg',cv2.flip(gray, 1 )) | ||
ch=ch+1 | ||
if ch>10: | ||
break | ||
if cv2.waitKey(1) & 0xFF ==ord('q'): | ||
break | ||
cam.release() | ||
root=Tk() | ||
root.geometry('0x0') | ||
root.title('Alert') | ||
messagebox.showinfo('Alert','Data Captured !!') | ||
root.destroy() | ||
cv2.destroyAllWindows() | ||
window() | ||
|
||
def window(): | ||
root=Tk() | ||
root.geometry('500x170+400+300') | ||
root.title('Face Capture') | ||
frame=Frame(root) | ||
label=Label(frame,text='Face Capture ',font=('Verdana',15,'bold')) | ||
label.pack(pady=30) | ||
label=Label(frame,text='Student Name : ',font=('Verdana',11,'bold')) | ||
label.pack(side=LEFT) | ||
entry1=Entry(frame,font=('Verdana',11)) | ||
entry1.pack(side=LEFT) | ||
bt=Button(frame,text='Capture',font=('Verdana',9,'bold'),\ | ||
bg='blue',fg='white',width=7,command=lambda:capture_pic(root,entry1)) | ||
bt.pack(padx=20) | ||
frame.pack() | ||
root.mainloop() | ||
|
||
|
||
if __name__=='__main__': | ||
window() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import cv2 | ||
from numpy import array | ||
import os,time | ||
from attendance import mark_attendance | ||
|
||
def facedetect(image): | ||
img_gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) | ||
cascade=cv2.CascadeClassifier('xml\haarcascade_frontalface_default.xml') | ||
faces=cascade.detectMultiScale(img_gray,scaleFactor=1.1,minNeighbors=5) | ||
|
||
return faces,img_gray | ||
|
||
def create_labels(): | ||
dir1='C:/Users/shree/AppData/Local/Programs/Python/Python36/Face Detection/training_data' | ||
faces_list=[] | ||
fid=[] | ||
temp='' | ||
names=[] | ||
|
||
for path,subdir,files in os.walk(dir1): | ||
name='' | ||
for f in files: | ||
if f.startswith('.'): | ||
continue | ||
image_path=os.path.join(path,f) | ||
img_id=os.path.basename(path) | ||
|
||
img=cv2.imread(image_path) | ||
img_re=cv2.resize(img,(1000,600)) | ||
faces,img_gray=facedetect(img_re) | ||
|
||
if (len(faces)!=1): | ||
continue | ||
|
||
x,y,w,h=faces[0] | ||
req_region=img_gray[y:y+w,x:x+h] | ||
faces_list.append(req_region) | ||
fid.append(int(img_id)) | ||
temp=f | ||
|
||
for char in temp: | ||
if char.isdigit(): | ||
break | ||
else: | ||
name=name+char | ||
names.append(name) | ||
names.remove('') | ||
|
||
names_dic=dict(zip(set(fid),names)) | ||
|
||
return faces_list,fid,names_dic | ||
|
||
|
||
def trainer(faces_list,fid): | ||
trainer=cv2.face.LBPHFaceRecognizer_create() | ||
trainer.train(faces_list,array(fid)) | ||
return trainer | ||
|
||
def rectangle(face,image): | ||
x,y,w,h=face | ||
cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2) | ||
|
||
def text(image,text,x,y): | ||
font=cv2.FONT_HERSHEY_DUPLEX | ||
cv2.putText(image,text,(x-15,y-40),font,1,(255,0,0),2) | ||
|
||
|
||
#dic={0:'Pradhyumn',1:'B'} | ||
|
||
faces_list,fid,names_dic=create_labels() | ||
classifier=trainer(faces_list,fid) | ||
|
||
all_labels=[] | ||
|
||
#test_prediction | ||
'''img_test=cv2.imread('test.jpg') | ||
faces,img_gray_test=facedetect(img_test) | ||
for f in faces: | ||
(x,y,w,h)=f | ||
req_region=img_gray_test[y:y+w,x:x+h] | ||
label,confi=classifier.predict(req_region) | ||
all_labels.append(names_dic[label].capitalize()) | ||
rectangle(f,img_gray_test) | ||
text(img_gray_test,names_dic[label].capitalize(),x,y) | ||
cv2.imshow('Gray',img_gray_test) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows()''' | ||
|
||
#live_prediction | ||
cam=cv2.VideoCapture(0) | ||
ch=1 | ||
while True: | ||
ret,frame=cam.read() | ||
faces,img_gray_test=facedetect(frame) | ||
|
||
for f in faces: | ||
(x,y,w,h)=f | ||
req_region=img_gray_test[y:y+w,x:x+h] | ||
label,confi=classifier.predict(req_region) | ||
all_labels.append(names_dic[label].capitalize()) | ||
rectangle(f,img_gray_test) | ||
text(img_gray_test,names_dic[label].capitalize(),x,y) | ||
|
||
cv2.imshow('Gray',img_gray_test) | ||
|
||
if cv2.waitKey(10)==ord('q'): | ||
break | ||
cam.release() | ||
cv2.destroyAllWindows() | ||
|
||
mark_attendance(all_labels) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import cv2 | ||
import os | ||
|
||
|
||
def capture(): | ||
label=[] | ||
dir1='C:/Users/shree/Desktop/Python/Projects/Face Detection/training_data' | ||
for x,y,z in os.walk(dir1): | ||
for a in y: | ||
label.append(int(a)) | ||
|
||
i=max(label) | ||
i=i+1 | ||
os.chdir('training_data') | ||
os.mkdir(str(i)) | ||
print(os.getcwd()) | ||
|
||
if __name__=='__main__': | ||
capture() | ||
|
||
|