-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengineers_day.py
70 lines (69 loc) · 2.07 KB
/
engineers_day.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import cv2
import os
from subprocess import Popen
import sys
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
video_capture = cv2.VideoCapture(0)
video_capture.read()
face_count = 0
playing = False
eye_count = 0
face_no_count = 0
eye_no_count = 0
while True:
face_there = False
eye_there = False
# Capture frame-by-frame
ret, frame = video_capture.read()
img2 = frame
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
img = cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
face_there = True
roi_gray = gray[y:y+h, x:x+w]
roi_color = img2[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,0,0),2)
eye_there= True
if(face_there):
face_count = face_count + 1
if(face_count>10):
if playing == False :
pid = Popen(["rhythmbox","comingback.mp3"]).pid
playing = True
print("I see you!")
face_count = 0
else:
face_no_count = face_no_count + 1
if(face_no_count>10):
print("Where did you go?")
os.system("kill "+str(pid))
playing = False
face_no_count = 0
if(eye_there):
eye_count = eye_count + 1
if(eye_count>10):
print("Your eyes too!")
eye_count = 0
else:
eye_no_count = eye_no_count + 1
if(eye_no_count>10):
print("Open your eyes!")
eye_no_count = 0
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()