-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_face_rec.py
50 lines (38 loc) · 1.08 KB
/
setup_face_rec.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
import cv2
import os
import numpy as np
import face_recognition
def grabImages(numImages):
cam = cv2.VideoCapture(0)
cv2.namedWindow("image")
count = 0
images = []
while True:
ret, frame = cam.read()
if not ret:
print("Failed to grab frame.")
break
cv2.imshow("image", frame)
k = cv2.waitKey(1)
# ESC pressed
if k % 256 == 27 or count >= numImages:
print("Escape hit, closing...")
break
# SPACE pressed
elif k % 256 == 32:
frame = cv2.resize(frame, (800, 600))
images.append(frame)
count += 1
cam.release()
cv2.destroyAllWindows()
return np.array(images)
if __name__ == "__main__":
knownImages = grabImages(5)
knownEmbeddings = []
for img in knownImages:
enc = face_recognition.face_encodings(img)[0]
knownEmbeddings.append(enc)
print(enc)
knownEmbeddings = np.array(knownEmbeddings)
with open('known_embeddings.npy', 'wb') as f:
np.save(f, knownEmbeddings)