-
Notifications
You must be signed in to change notification settings - Fork 1
/
FaceEncoder.py
56 lines (47 loc) · 1.67 KB
/
FaceEncoder.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
import face_recognition as fr
from FirebaseBucket import FirebaseBucket
import json
from pathlib import Path
class FaceEncoder:
src=str(Path().resolve())
saveDir="KnownFaces/"
localJsonDir=src+"/ChangedData.json"
encDir=src+"/encodings.json"
fbb=FirebaseBucket()
def getEncoding(self,rollNo):
self.fbb.downloadFaceImg(rollNo)
img=fr.load_image_file(self.saveDir+rollNo+".jpg")
enc = fr.face_encodings(img)[0]
# self.fbb.deleteImage(rollNo)
return enc.tolist()
def create_new_class(self, class_info):
self.fbb.createClass(class_info)
def update_class_total(self,name):
self.fbb.updateCLassTotal(name)
def update_presence_of_student(self,roll,class_name):
self.fbb.updatePresence(roll,class_name)
def encodingUpdater(self):
print("Updating student info, please wait.")
self.fbb.updateStudentInfo()
print("Running Encoding updater, please wait.")
f=open(self.localJsonDir)
f2=open(self.encDir)
locData=json.load(f)
fbData=self.fbb.getChangedData()
encData=json.load(f2)
f.close()
f2.close()
for roll,dat in fbData.items():
if (roll in locData and int(dat)>int(locData[roll])) or (roll not in locData):
enc=self.getEncoding(roll)
locData[roll]=int(dat)
encData[roll]=enc
# print(encData)
f=open(self.localJsonDir,'w')
f2=open(self.encDir,'w')
json.dump(locData,f)
json.dump(encData,f2)
f.close()
f2.close()
class_info=self.fbb.getCurrentClass()
return class_info