-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththug_life.py
46 lines (36 loc) · 1.2 KB
/
thug_life.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
import cv2
cap = cv2.VideoCapture(0)
classifier = cv2.CascadeClassifier("haarcascade_eye.xml")
glasses = cv2.imread("try.png", cv2.IMREAD_UNCHANGED)
print(glasses.shape)
while True:
retval, image = cap.read()
if retval:
eyes = classifier.detectMultiScale(image)
eyes = sorted(eyes, key=lambda eye: eye[2]*eye[3], reverse=True)
if len(eyes) >= 2:
x1, y1, w1, h1 = eyes[0]
x2, y2, w2, h2 = eyes[1]
if (x1 > x2):
x1, x2 = x2, x1
y1, y2 = y2, y1
w1, w2 = w2, w1
h1, h2 = h2, h1
h = min(h1,h2)
w = x2 + w2 - x1 + 40
x1 -= 20
glasses = cv2.resize(glasses, (w,h))
cv2.imshow("Glasses", glasses)
cut = image[y1:y1 + h, x1:x1+w]
for row in range(h):
for col in range(w):
if glasses[row, col, 3] > 100:
cut[row, col] = glasses[row, col, :3]
cv2.imshow("thug_life", image)
key = cv2.waitKey(10)
if key == ord("q"):
break
if key == ord("c"):
cv2.imwrite("classroom.png", image)
cap.release()
cv2.destroyAllWindows()