-
Notifications
You must be signed in to change notification settings - Fork 0
/
eyetracking.py
39 lines (28 loc) · 977 Bytes
/
eyetracking.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
from eyetracker import EyeTracker
import imutils
import argparse
import cv2
ap=argparse.ArgumentParser()
ap.add_argument('-f','--face',required=True,help='path to where the face cascade resides')
ap.add_argument('-e','--eye',required=True,help='Path to where the eye cascade resides')
ap.add_argument('-v','--video',help='path to the video')
args=vars(ap.parse_args())
et=EyeTracker(args['face'],args['eye'])
if not args.get('video',False):
camera=cv2.VideoCapture(0)
else:
camera=cv2.VideoCapture(args['video'])
while True:
(grabbed,frame)=camera.read()
if args.get('video') and not grabbed:
break
frame=imutils.resize(frame,width=400)
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
rects=et.track(gray)
for rect in rects:
cv2.rectangle(frame,(rect[0],rect[1]),(rect[2],rect[3]),(0,255,0),2)
cv2.imshow('Tracking',frame)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
camera.release()
cv2.destroyAllWindows()