-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlevel3.py
60 lines (45 loc) · 1.29 KB
/
level3.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
from scipy.spatial import distance as dist
from imutils.video import FileVideoStream
from imutils.video import VideoStream
from imutils import face_utils
import numpy as np
import argparse
import imutils
import time
import dlib
import cv2
import subprocess
from playsound import playsound
class LookAway:
def lookAway(self,detector,predictor,cap):
TIME_TO_LOOK_AWAY=5
# detector = dlib.get_frontal_face_detector()
# predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
print('I am in level 3')
# cap=cv2.VideoCapture(0)
ret, frame = cap.read()
startTime=0
endTime=0
while ret:
ret,frame = cap.read()
frame = imutils.resize(frame, width=450)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('lookAway',frame)
# detect faces in the grayscale frame
rects = detector(gray, 0)
if len(rects)==0 and startTime==0:
startTime=time.time()
if len(rects)==1:
startTime=time.time()
elpased_time = time.time()-startTime
if round(elpased_time) >=TIME_TO_LOOK_AWAY:
#print("congoooooooooooooooooooo")
playsound('beep.mp3')
break
print(round(elpased_time))
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
cap.release()
cv2.destroyAllWindows()