-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCam.py
More file actions
53 lines (36 loc) · 1.05 KB
/
Copy pathCam.py
File metadata and controls
53 lines (36 loc) · 1.05 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import cv2
import os
import numpy as np
detector=cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
cap=cv2.VideoCapture(0)
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])
f_name = "face_data.npy"
if os.path.exists(f_name):
old = np.load(f_name)
data = np.vstack([old, data])
np.save(f_name, data)
cap.release()
cv2.destroyAllWindows()