-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLoad_people_into_DataBase.py
More file actions
35 lines (28 loc) · 1.01 KB
/
Load_people_into_DataBase.py
File metadata and controls
35 lines (28 loc) · 1.01 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
from Inference.FaceRecognizer import FaceRecognizer
import numpy as np
import cv2
import json
import os
PEOPLE_DIR = "People"
files = os.listdir("DataBase")
if "DataBase.json" not in files:
with open(os.path.join("DataBase","DataBase.json"), "x") as file:
empty_json = {}
json.dump(empty_json,file)
def add_person_to_database(Name, feature_vector):
# load DataBase.json File
with open(os.path.join("DataBase", "DataBase.json"), "r") as file:
data = json.load(file)
# append the record
data[Name] = feature_vector
# Save updated record to DataBase.json
with open(os.path.join("DataBase", "DataBase.json"), "w") as file:
json.dump(data,file)
print(f"{Name} is added to DataBase")
people = os.listdir(PEOPLE_DIR)
recog = FaceRecognizer()
for person in people:
name = person.split('.')[0]
face = cv2.imread(os.path.join(PEOPLE_DIR, person))
face_embd = recog.get_face_embedding(face).flatten().tolist()
add_person_to_database(name, face_embd)