-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_for_wink_detection.py
65 lines (59 loc) · 1.73 KB
/
main_for_wink_detection.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
import cv2
import WinkRecognition
import MHIv2
from OpenCVTracker import FaceTracker
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
frameCount = 0
faces = None
prevLeftEye = None
prevRightEye = None
leftEyeInitialised = False
counter = 0
startTime = None
timerResult = None
timerSet = False
face = None
winkEyeX = None
winkEyeY = None
faceSample = None
def scaleEye(eyeImage):
# NEEDED WHEN THE EYE IMAGE IS TOO LARGE
# eyeWidth = len(eyeImage[0])
# eyeHeight = len(eyeImage)
# return eyeImage[int(eyeWidth/8):int(7*eyeWidth/8),int(eyeHeight/8):int(7*eyeHeight/8)]
return eyeImage
# setup
faceTracker = FaceTracker(vc)
while leftEyeInitialised is False:
faceTracker.performFaceTracking()
leftEye,rightEye=faceTracker.getEyes()
if (leftEye is not None and rightEye is not None):
MHIv2.nextFrame(scaleEye(leftEye))
leftEyeInitialised = True
# loop
while rval:
faceTracker.performFaceTracking()
# frameCount = (frameCount+1) % 15 # should only detect faces every x amount of frames, to receive a better framerate
cv2.imshow("preview", frame)
rval, frame = vc.read()
wink = False
leftEye, rightEye = faceTracker.getEyes()
if (leftEye is not None and rightEye is not None):
MHIeye = MHIv2.nextFrame(scaleEye(leftEye))
cv2.imshow("a", MHIeye)
cv2.imshow("oog",scaleEye(leftEye))
if WinkRecognition.getWinkRecognition(MHIeye):
wink = True
if wink:
cv2.imshow("effect", frame)
else:
cv2.imshow("effect",cv2.resize(frame,(100,80)))
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow("preview")