-
Notifications
You must be signed in to change notification settings - Fork 0
/
face_recog_collector.py
55 lines (36 loc) · 1.09 KB
/
face_recog_collector.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
import cv2
import numpy as np
import os
cap = cv2.VideoCapture(0)
detector = cv2.CascadeClassifier(cv2.data.haarcascades+"haarcascade_frontalface_default.xml")
name = input("Enter your name : ")
frames = []
outputs = []
while True:
ret, frame = cap.read()
if ret:
faces = detector.detectMultiScale(frame)
for face in faces:
x,y,w,h = face
cut = frame[y:y+h, x:x+w]
fix = cv2.resize(cut, (100,100))
gray = cv2.cvtColor(fix,cv2.COLOR_BGR2GRAY)
cv2.imshow("My Screen", frame)
cv2.imshow("My face", gray)
key = cv2.waitKey(1)
if key==ord("q"):
break
if key==ord("c"):
# cv2.imwrite(name + ".jpg", frame)
frames.append(gray.flatten())
outputs.append([name])
X=np.array(frames)
y=np.array(outputs)
data = np.hstack([y, X])
file_name = "face_data.npy"
if os.path.exists(file_name):
old = np.load(file_name)
data = np.vstack([old, data])
np.save(file_name, data)
cap.release()
cv2.destroyAllWindows()