-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
83 lines (69 loc) · 2.77 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
import cv2
import numpy as np
from collections import deque
from scripts import easter_ears, illini_eyes, nosetracking
import sys, os
camera_num = 0 #picks which camera to use. For a device with multiple cameras, camera_num can be set to 1, 2 etc.
vid = cv2.VideoCapture(0) #captures video feed from the selected camera
#defining local variables for nose reading
MAX_BUFFER = 20
pts = deque(maxlen=MAX_BUFFER)
nose_cascade = cv2.CascadeClassifier('dependencies/nose.xml') #pranav's REFACTOR: only done once, no need to keep in while loop
mode = 'def' #set a mode variable
while (True):
ret, frame = vid.read() # saves the current frame from the video feed
canvas = np.zeros(frame.shape, np.uint8)
frame = cv2.flip(frame, 1)
#function call
if mode =='easter_ears':
cv2.imshow('frame', easter_ears.bunnyears(frame))
elif mode == 'illini_eyes':
try:
cv2.imshow('frame', illini_eyes.IlliniI(frame))
except:
continue
elif mode =='nosetracking':
# pts.appendleft(nosetracking.nosetracking(frame, pts, nose_cascade))
nosetracking.nosetracking(frame, pts, nose_cascade)
for i in range(1, len(pts)):
# if either of the tracked points are None, ignore
if pts[i - 1] is None or pts[i] is None:
continue
if pts[i-1] and pts[i]:
thickness = int(np.sqrt(MAX_BUFFER / float(i + 1)) * 2.5)
cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)
cv2.imshow('frame', frame)
# try:
# pts.appendleft(nosetracking.nosetracking(frame, pts, nose_cascade))
# for i in range(1, len(pts)):
# # if either of the tracked points are None, ignore
# if pts[i - 1] is None or pts[i] is None:
# continue
# thickness = int(np.sqrt(MAX_BUFFER / float(i + 1)) * 2.5)
# cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)
# cv2.imshow('frame', frame)
# except Exception as err:
# print(repr(err))
# exc_type, exc_obj, exc_tb = sys.exc_info()
# fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
# print(str(exc_tb.tb_lineno))
# sys.exit()
# the 'q' button is set as the quit button
else:
cv2.imshow('frame', frame)
### code to switch between different modes
key = cv2.waitKey(1)
if key == ord('q'):
break
elif key == ord('i'):
mode = 'illini_eyes'
elif key == ord('b'):
mode = 'easter_ears'
elif key == ord('n'):
mode = 'nosetracking'
elif key == ord('d'):
mode = 'def'
else:
pass
vid.release()
cv2.destroyAllWindows()