-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenroll.py
37 lines (29 loc) · 1.15 KB
/
enroll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import face_recognition,cv2,pickle
import spreadsheet
photo_folder = 'D:/projects/face_recoginition/Face-recognition-based-attendance-system-master/known face photos/'
facial_encodings_folder='D:/projects/face_recoginition/Face-recognition-based-attendance-system-master/known face encodings/'
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
def encoding_of_enrolled_person(name,image):
enroll_encoding=[]
enroll_encoding.append(face_recognition.face_encodings(face_recognition.load_image_file(image))[0])
f=open(facial_encodings_folder+name+'.txt','w+')
with open(facial_encodings_folder+name+'.txt','wb') as fp:
pickle.dump(enroll_encoding,fp)
f.close
def enroll_via_camera(name):
while True:
ret,frame=cap.read()
cv2.imshow('Enrolling new attendee',frame)
k=cv2.waitKey(1)
if k & 0xFF==ord('y'):
cv2.imwrite(photo_folder+name+'.jpg',frame)
encoding_of_enrolled_person(name,photo_folder+name+'.jpg')
cv2.destroyAllWindows()
break
if k& 0xFF==ord('q'):
print('quitting')
cv2.destroyAllWindows()
break
cap.release()
email=input("Enter email address: ")
spreadsheet.enroll_person_to_sheet(name,email)