-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_generetor.py
More file actions
69 lines (49 loc) · 1.7 KB
/
Copy pathencode_generetor.py
File metadata and controls
69 lines (49 loc) · 1.7 KB
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
import cv2
import face_recognition
import pickle
import os
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import storage
# IMPORTING OUR FIREBASE DATABASE
cred = credentials.Certificate("project/realtimefaceattendence-87692-firebase-adminsdk-rkz7t-4f8a26e0ff.json")
firebase_admin.initialize_app(cred, {
'databaseURL': "https://realtimefaceattendence-87692-default-rtdb.firebaseio.com/",
'storageBucket': "realtimefaceattendence-87692.appspot.com"
})
#IMPORTING THE STUDENT IMAGES
folderPath = 'project/Images'
PathList = os.listdir(folderPath)
# print(PathList)
imgList = []
student_IDs = []
for path in PathList:
imgList.append(cv2.imread(os.path.join(folderPath, path)))
# print(path)
# print(os.path.splitext(path)[0])
student_IDs.append(os.path.splitext(path)[0])
# UPLOADING THE IMAGES IN OUR DATABASE
filename = f'{folderPath}/{path}'
bucket = storage.bucket()
blob = bucket.blob(filename)
blob.upload_from_filename(filename)
print(student_IDs)
# WE WILL LOOP THROURH EVERY IMAGE ANF ENCODE EACH IMAGE
def findEncodings(imagesList):
encodeList = []
for img in imagesList:
# WE NEED THE IMAGES IN THE COLOR FORMAT (COLOR SPACE)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encode = face_recognition.face_encodings(img)[0]
# print(encode)
encodeList.append(encode)
return encodeList
print("Encoding started.....")
encodeList_Known = findEncodings(imgList)
encodeList_Known_with_IDs = [encodeList_Known, student_IDs]
print("Encoding Complete")
file = open("EncodeFile.p", 'wb')
pickle.dump(encodeList_Known_with_IDs, file)
file.close()
print("File Saved")