forked from lazyCodes7/perfect-pause
-
Notifications
You must be signed in to change notification settings - Fork 1
/
perfect-pause.py
69 lines (52 loc) · 1.74 KB
/
perfect-pause.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
import numpy as np
import cv2
import vlc
import time
#We are using OpenCV to achieve object detection from live frame
def monitor_human():
return_var = 0
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye_tree_eyeglasses.xml')
first_read = True
cap = cv2.VideoCapture(0)
ret,img = cap.read()
while(ret):
ret,img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray,5,1,1)
faces = face_cascade.detectMultiScale(gray, 1.3, 5,minSize=(200,200))
if(len(faces)>0):
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,255),10)
roi_face = gray[y:y+h,x:x+w]
roi_face_clr = img[y:y+h,x:x+w]
eyes = eye_cascade.detectMultiScale(img,1.3,5,minSize=(50,50))
for (ex,ey,ew,eh) in eyes:
img=cv2.rectangle(img,(ex,ey),(ex+ew,ey+eh),(0,0,255),2)
if(len(eyes)>=2):
pass
else:
return_var=1
else:
return_var=1
return(return_var)
# The above function returns the status derived through monitoring
media_player = vlc.MediaPlayer()
# adding media object
media = vlc.Media("./rm.mkv")
# setting media to the media player
media_player.set_media(media)
media_player.audio_set_volume(100)
# start playing video
while(True):
media_player.play()
time.sleep(0)
value = 0
if(monitor_human()==1):
while(monitor_human()==1):
media_player.set_pause(1)
time.sleep(1)
if(monitor_human()==0):
media_player.play()
time.sleep(0)
break