forked from frc-team-3341/A-New-Vision-Workshop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanswers.py
179 lines (148 loc) · 5.98 KB
/
answers.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from time import sleep
from scv import *
import math
mode = 4
# Keycode from OpenCV
key = 0
# Initial exposure setting for camera
expos = -8
# Variable to increment - adjusts which overlay we want initially
switch = 3
# Max number of images, delimited starting with 0
num_images = 5
toggle = False
# SUPER CHALLENGE # 1 ANSWER
if mode == 0:
img = img_load('parlor.png')
cone = img_load('cone.png')
cream = img_load('greencircle.png')
img = draw(img, cream, get_width(img) / 2 - 50, get_height(img) / 2 - 65, 100, 100)
img = draw(img, cone, get_width(img) / 2 - 50, get_height(img) / 2, 100, 200)
show_image(img)
# MOUTH DETECT AND DRAW CHALLENGE
elif mode == 1:
original = img_load('face_detect.png') # Load the original image
faces = find_faces(original) # Find the faces
if len(faces) != 0: # If there are faces
x, y, width, height = faces[-1] # Get best match for faces
original = draw(original, img_load('greencircle.png'), x, y, width, height)
show_image(original)
# MUSTACHE FINAL CHALLENGE ANSWER
elif mode == 2:
stache = img_load('stache.png') # Load the stache
while True:
if not toggle:
original = get_camera_image() # Load the original image
mouths = find_mouths(original) # Find the mouths
if len(mouths) != 0: # If there are mouths
x, y, width, height = mouths[-1] # Get best match for mouth
original = draw(original, stache, x, int(y - height / 3.5), width, int(height / 1.2))
key = show_image(original)
if key == 27: # if ESC is pressed, exit
cv2.destroyAllWindows()
break
if key == 32:
toggle = not toggle
# CAFFE DNN DEMO
elif mode == 3:
# SPACE NIGHT - ASTRONAUT IMAGE adapted from: (Public Domain license)
# https://freesvg.org/astronauts-helmet-vector-image
# "Cute Alien" is original artwork (Aric Volman)
helmet = img_load('astro_helmet.png') # Load the face
alien = img_load('cute_alien.png') # Load the cute alien
dog = img_load('dog.png')
stache = img_load('stache2.png')
cat = img_load('cutecat.png')
mascot = img_load('mascot.png')
original = get_camera_image() # Load the original image
while True:
if not toggle:
original = get_camera_image() # Load the original image
width, height, x, y = find_faces_dnn(original) # Get best match for mouth
if switch == 0:
original = draw(original, helmet, x, y, width, height)
if switch == 1:
original = draw(original, alien, x, y, width, height)
if switch == 2:
original = draw(original, dog, x, y, width, height)
if switch == 3:
original = draw(original, stache, x, y, width, height)
if switch == 4:
original = draw(original, cat, x, y, width, height)
if switch == 5:
original = draw(original, mascot, x, y, width, height)
key = show_image(original)
if key == 97: # A - Switches to and from different pictures!
# time.sleep(1)
if switch >= num_images:
switch = 0
else:
switch += 1
if key == 32: # Space bar - Pauses
toggle = not toggle
if expos <= -13:
expos = -13
if expos >= -1:
expos = -1
if key == 122: # Z key - Increase exposure
expos += 1
set_exposure(expos)
if key == 120: # X Key - Decrease exposure
expos -= 1
set_exposure(expos)
if key == 27: # if ESC is pressed, exit
cv2.destroyAllWindows()
break
# HAAR CASCADE DEMO
elif mode == 4:
# SPACE NIGHT - ASTRONAUT IMAGE adapted from: (Public Domain license)
# https://freesvg.org/astronauts-helmet-vector-image
# "Cute Alien" is original artwork (Aric Volman)
helmet = img_load('astro_helmet.png') # Load the face
alien = img_load('cute_alien.png') # Load the cute alien
dog = img_load('dog.png')
stache = img_load('stache2.png')
cat = img_load('cutecat.png')
mascot = img_load('mascot.png')
original = get_camera_image() # Load the original image
while True:
if not toggle:
original = get_camera_image() # Load the original image
faces = find_faces(original) # Find the mouths
if len(faces) != 0: # If there are mouths
for i in range(0, len(faces)):
x, y, width, height = faces[i] # Get best match for mouth
if switch == 0:
original = draw(original, helmet, x, y, width, height)
if switch == 1:
original = draw(original, alien, x, y, width, height)
if switch == 2:
original = draw(original, dog, x, y, width, height)
if switch == 3:
original = draw(original, stache, x, y, width, height)
if switch == 4:
original = draw(original, cat, x, y, width, height)
if switch == 5:
original = draw(original, mascot, x, y, width, height)
key = show_image(original)
if key == 97: # A - Switches to and from different pictures!
# time.sleep(1)
if switch >= num_images:
switch = 0
else:
switch += 1
if key == 32: # Space bar - Pauses
toggle = not toggle
if (expos <= -13):
expos = -13
if (expos >= -1):
expos = -1
if key == 122: # Z key - Increase exposure
expos += 1
set_exposure(expos)
if key == 120: # X Key - Decrease exposure
expos -= 1
set_exposure(expos)
if key == 27: # if ESC is pressed, exit
cv2.destroyAllWindows()
break