efghi7890 commited on
Commit
aa9f87b
·
1 Parent(s): 99ecb73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -1
app.py CHANGED
@@ -10,9 +10,62 @@ def greet(video):
10
  images = []
11
  classNames = []
12
  myList = os.listdir(path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  cap = cv2.VideoCapture(video)
 
 
14
  succes, img = cap.read()
15
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  return gray
17
 
18
  iface = gr.Interface(
 
10
  images = []
11
  classNames = []
12
  myList = os.listdir(path)
13
+ print(myList)
14
+ for cl in myList
15
+ curImg = cv2.imread(f'{path}/{cl}')
16
+ images.append(curImg)
17
+ classNames.append(os.path.splitext(cl)[0])
18
+ print(classNames)
19
+
20
+ def findEncoding(images):
21
+ encodeList = []
22
+ for img in images:
23
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
24
+ encode = face_recognition.face_encodings(img)[0]
25
+ encodeList.append(encode)
26
+ return encodeList
27
+
28
+ def markAttendance(name):
29
+ with open('Attendance.csv','r+') as f:
30
+ myDataList = f.readlines()
31
+ nameList = []
32
+ for line in myDataList:
33
+ entry = line.split(',')
34
+ nameList.append(entry[0])
35
+ if name not in nameList:
36
+ now = datetime.now()
37
+ dtString = now.strftime('%H:%M:%S')
38
+ f.writelinbes(f'\n{name},{dtString}')
39
+ encodeListKnown = findEncodings(images)
40
+ print('Encoding Complete')
41
+
42
  cap = cv2.VideoCapture(video)
43
+
44
+ while True:
45
  succes, img = cap.read()
46
+ imgS = cv2.resize(img,(0,0),None,0.25,0.25)
47
+ imgS = cv2.cvtColor(imgs, cv2.COLOR_BGR2GRAY)
48
+
49
+ facesCurFrame = face:recognition.face_locations(imgS)
50
+ encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
51
+
52
+ for encodeFace_faceLoc in zip(encodesCurFrame, facesCurFrame):
53
+ matches = face_recognition.compare_faces(encodeListKnown,encodeFace)
54
+ faceDis = face_recognition.face_distance(encodeListKnown,encodeFace)
55
+ matchIndex = np.argmin(faceDis)
56
+
57
+ if matches[matchIndex]:
58
+ name = classNames[matchIndex].upper()
59
+ y1,x2,y2,x1 = faceLoc
60
+ y1,x2,y2,x1 = y1*4,x2*4,y2*4,x1*4
61
+ cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),2)
62
+ cv2.rectangle(img,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILED)
63
+ cv2.putText(img,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),2)
64
+ markAttendance(name)
65
+ cv2.imshow('Webcam',img)
66
+ cv2.waitKey(1)
67
+
68
+
69
  return gray
70
 
71
  iface = gr.Interface(