-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_faces.py
More file actions
62 lines (45 loc) · 965 Bytes
/
Copy pathencode_faces.py
File metadata and controls
62 lines (45 loc) · 965 Bytes
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
import os
import pickle
import cv2
KNOWN_FACES_DIR = "faces"
encodings = {}
names = []
for person in os.listdir(KNOWN_FACES_DIR):
person_path = os.path.join(
KNOWN_FACES_DIR,
person
)
if not os.path.isdir(person_path):
continue
names.append(person)
encodings[person] = []
for image_name in os.listdir(person_path):
image_path = os.path.join(
person_path,
image_name
)
image = cv2.imread(image_path)
if image is None:
continue
gray = cv2.cvtColor(
image,
cv2.COLOR_BGR2GRAY
)
resized = cv2.resize(
gray,
(100,100)
)
encodings[person].append(
resized.flatten()
)
with open(
"face_encodings.pkl",
"wb"
) as file:
pickle.dump(
encodings,
file
)
print(
"Face database created successfully!"
)