-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvisibilityCloak.py
48 lines (30 loc) · 1.36 KB
/
invisibilityCloak.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
import cv2
import numpy as np
import time
def nothing(x):
pass
cap = cv2.VideoCapture(0)
time.sleep(1)
for i in range(30):
ret, background = cap.read() # stores backgroung image
while True:
ret, img = cap.read()
if not ret:
break
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # converts BGR feed to HSV
lowerBlue = np.array([169, 175, 75]) # lower and upper hsv boundaries for cloak color
upperBlue = np.array([185, 255, 255])
mask1 = cv2.inRange(hsv, lowerBlue, upperBlue) # creates the mask
mask1 = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, np.ones((3, 3), np.uint8), iterations=2)
mask1 = cv2.morphologyEx(mask1, cv2.MORPH_DILATE, np.ones((3, 3), np.uint8), iterations=2)
mask2 = cv2.bitwise_not(mask1) # everything except mask
cloak = cv2.bitwise_and(background, background, mask=mask1)
non_cloak = cv2.bitwise_and(img, img, mask=mask2)
final = cv2.addWeighted(cloak, 1, non_cloak, 1, 0) # overlays the backgroung on visible feed where cloak is present
# thus creating an effect of invisibility
cv2.imshow("INVISIBILITY CLOAK", final)
k = cv2.waitKey(1)
if k == ord("q"): # shuts down in "q" key is pressed
break
cv2.destroyAllWindows()
cap.release()