-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathattendencemain.py
146 lines (124 loc) · 3.45 KB
/
attendencemain.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
import face_recognition
import cv2
import numpy as np
from PIL import Image,ImageDraw
import pickle
def verify(v,we):
import remove as f
known_face_encodings=[]
known_face_names=[]
m=1
f.clean(v)
t=None
l=[]
r=[]
b=[]
u=[]
fonts = cv2.FONT_HERSHEY_SIMPLEX
w=0
# org
org = (50, 50)
# fontScale
fontScale = 1.3
# Blue color in BGR
color = (255, 0, 0)
# Line thickness of 2 px
thickness = 4
s=[]
all_face_encodings = {}
path1 =v+"/"
h=""
d=[]
listing = os.listdir(path1)
for file in listing:
k=str(file)
print(file)
for p in k:
if p=='.':
break
h=h+p
d.append(h)
h=""
print("Face Training and Encoding##",end="")
for o in d:
shah_image = face_recognition.load_image_file(v+"/"+str(o)+".jpg")
np.save(v+"/"+str(o),shah_image)
print("#",end ="")
shah_encoding = face_recognition.face_encodings(shah_image)[0]
np.save(v+"/"+str(o)+"-en",shah_encoding)
print("#",end ="")
for o in d:
shah_image=np.load(v+"/"+str(o)+".npy")
all_face_encodings[str(o)] = face_recognition.face_encodings(shah_image)[0]
print("#",end ="")
with open(v+"/"+'dataset_sali1.dat', 'wb') as f:
pickle.dump(all_face_encodings, f)
print("Completed")
print("\nComparison Starting [##",end="")
for o in d:
print("##",end ="")
shah_encoding=np.load(v+"/"+str(o)+"-en.npy")
known_face_encodings.append(shah_encoding)
known_face_names.append(str(o))
test_images=face_recognition.load_image_file(we)
face_locations=face_recognition.face_locations(test_image)
face_encoding = face_recognition.face_encodings(test_image,face_locations)
pil_image=Image.fromarray(test_image)
draw=ImageDraw.Draw(pil_image)
for (top,right,bottom,left) ,face_encoding in zip(face_locations,face_encodings):
matches=face_recognition.compare_faces(known_face_encodings,face_encoding)
print("#",end ="")
name="Unknown Person"
if True in matches:
print("#",end ="")
first_match_index=matches.index(True)
name=known_face_names[first_match_index]
draw.rectangle(((left+2,top+2),(right+2,bottom+2)),outline=(0,255,255),width=5)
print("#",end ="")
text_width,text_height=draw.textsize(name)
#draw.rectangle(((left,bottom-text_height-10),(right,bottom)),fill=(0,0,0),outline=(0,0,0),width=5)
#draw.text((left+6,bottom-text_height-5),name,fill=(255,255,255,255))
l.append(left)
r.append(right)
print("#",end ="")
u.append(text_height)
b.append(bottom)
# print(name)
s.append(name)
print("#",end ="")
w=w+1
del draw
import ex as et
# print(s)
ku=et.reads(s,v)
print("##]Completed")
pu=0
for ju in ku:
pu=pu+1
if pu==0:
print("All are present")
else:
for ju in ku:
print(ju)
print("are absent")
img = np.array(pil_image)
img= cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# print(s)
for t in s:
print(".",end="")
if t is not None :
for z in range(0,w):
# print(t)
img= cv2.putText(img,s[z],(l[z]+6,b[z]-u[z]), fonts,
fontScale, color, thickness,cv2.LINE_AA)
# scale_percent = 60 # percent of original size
#width = int(img.shape[1] * scale_percent / 100)
#height = int(img.shape[0] * scale_percent / 100)
#dim = (width, height)
#img = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("test",img)
print("press any key to continue")
cv2.waitKey(0)
cv2.destroyAllWindows()
#verify("classf")