-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaceRecog.py
48 lines (36 loc) · 1.04 KB
/
faceRecog.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
import cv2
import numpy as np
import os
cap = cv2.VideoCapture(0)
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
name = input("Enter 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 face", gray)
cv2.imshow("My Screen", frame)
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])
f_name = "face_data.npy"
if os.path.exists(f_name):
old = np.load(f_name)
data = np.vstasck([old,data])
np.save(f_name,data)
cap.release()
cv2.destroyAllWindows()