-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncodeGenerator.py
58 lines (47 loc) · 1.5 KB
/
EncodeGenerator.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
import cv2
import numpy as np
import os
import face_recognition
import pickle
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import storage
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred, {
'databaseURL': "https://ai-face-recognition-system-default-rtdb.firebaseio.com/",
'storageBucket': "gs://ai-face-recognition-system.appspot.com"
})
# Importing student images
folderPath = 'Images'
pathList = os.listdir(folderPath)
print(pathList)
imgList = []
studentIds = []
for path in pathList:
imgList.append(cv2.imread(os.path.join(folderPath, path)))
studentIds.append(os.path.splitext(path)[0])
fileName = f'{folderPath}/{path}'
bucket = storage.bucket()
blob = bucket.blob(fileName)
try:
blob.upload_from_filename(fileName)
print(f"Uploaded {fileName} successfully.")
except Exception as e:
print(f"Error uploading {fileName}: {e}")
print(studentIds)
def findEncodings(imagesList):
encodeList = []
for img in imagesList:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encode = face_recognition.face_encodings(img)[0]
encodeList.append(encode)
return encodeList
print("Encoding Started ...")
encodeListKnown = findEncodings(imgList)
encodeListKnownWithIds = [encodeListKnown, studentIds]
print("Encoding Complete")
file = open("EncodeFile.p", 'wb')
pickle.dump(encodeListKnownWithIds, file)
file.close()
print("File Saved")