|
import os |
|
import cv2 |
|
import face_recognition |
|
import pickle |
|
import pyrebase |
|
|
|
|
|
config = { |
|
"apiKey": "AIzaSyClnRJAnrJgAgkYjuYnlvu-CJ6Cxyklebo", |
|
"databaseURL": "https://console.firebase.google.com/project/socioverse-2025/database/socioverse-2025-default-rtdb/data/~2F", |
|
"authDomain": "socioverse-2025.firebaseapp.com", |
|
"projectId": "socioverse-2025", |
|
"storageBucket": "socioverse-2025.appspot.com", |
|
"messagingSenderId": "689574504641", |
|
"appId": "1:689574504641:web:a22f6a2fa343e4221acc40", |
|
"serviceAccount":"socioverse-2025-firebase-adminsdk-gcc6m-6bfb53e6d9.json" |
|
} |
|
|
|
firebase = pyrebase.initialize_app(config) |
|
storage = firebase.storage() |
|
|
|
|
|
storage_folder = "Faces/" |
|
|
|
|
|
face_encodings = [] |
|
labels = [] |
|
|
|
|
|
blobs = storage.child(storage_folder).list_files() |
|
|
|
|
|
for blob in blobs: |
|
if blob.name.startswith(storage_folder) and (blob.name.endswith(".jpeg") or blob.name.endswith(".jpg") or blob.name.endswith(".png")): |
|
|
|
url = storage.child(f"{blob.name}").get_url(None) |
|
|
|
storage.child(url).download(f"{blob.name}","temp.jpeg") |
|
|
|
img = cv2.imread("temp.jpeg") |
|
|
|
|
|
rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
|
|
|
encode = face_recognition.face_encodings(img)[0] |
|
face_encodings.append(encode) |
|
name_parts = blob.name.split('/') |
|
name = name_parts[-1] |
|
name_parts = name.split('$') |
|
name = name_parts[0] |
|
labels.append(name) |
|
|
|
|
|
os.remove("temp.jpeg") |
|
|
|
|
|
data = {"encodings": face_encodings, "labels": labels} |
|
with open("face_encodings.pkl", "wb") as file: |
|
pickle.dump(data, file) |
|
|
|
|
|
pkl_blob = storage.child(f"{storage_folder}pkl/face_encodings.pkl") |
|
pkl_blob.put("face_encodings.pkl") |
|
|
|
print("Face encodings and labels saved to Firebase Storage in 'faces/pkl' folder as 'face_encodings.pkl'.") |