├── README.md └── invisibilityCloak.py /README.md: -------------------------------------------------------------------------------- 1 | # you're-a-wizard-Harry 2 | 3 | this will make anything red invisible (even your...mouth), you can change the colour in the code 4 | 5 | how it works 6 | 7 | - type python invisibilityCloak.py in your terminal (make sure your code editor has permission to open the webcam) 8 | - then straight away move away from webcam (it needs to take a photo if your background, give it 5 seconds) 9 | - then if you have anything red, it will be invisible (can change colour) 10 | - if you have bluetooth on, it might connect to your phone so turn it off. 11 | - Any issues, ask your favourite LLM! 12 | 13 | - Enjoy! 14 | -------------------------------------------------------------------------------- /invisibilityCloak.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import time 4 | 5 | print(""" 6 | Your cloak is loading.... 7 | hide from your webcam for the first 5 seconds, as it needs to capture the background (without you in it) 8 | """) 9 | 10 | # Initialize webcam 11 | video = cv2.VideoCapture(0) 12 | time.sleep(3) 13 | 14 | # Capture static background frame 15 | bg_frame = 0 16 | for _ in range(30): 17 | success, bg_frame = video.read() 18 | 19 | # Flip background for mirror view 20 | bg_frame = np.flip(bg_frame, axis=1) 21 | 22 | while video.isOpened(): 23 | success, frame = video.read() 24 | if not success: 25 | break 26 | 27 | # Flip the frame horizontally (mirror effect) 28 | frame = np.flip(frame, axis=1) 29 | 30 | # Convert BGR image to HSV color space 31 | hsv_img = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 32 | 33 | # Slightly smoothen the image 34 | blurred_hsv = cv2.GaussianBlur(hsv_img, (35, 35), 0) 35 | 36 | # Lower red hue range, you can swap out the colour, this is set to red 37 | red_lower_1 = np.array([0, 120, 70]) 38 | red_upper_1 = np.array([10, 255, 255]) 39 | mask_red1 = cv2.inRange(hsv_img, red_lower_1, red_upper_1) 40 | 41 | # Upper red hue range 42 | red_lower_2 = np.array([170, 120, 70]) 43 | red_upper_2 = np.array([180, 255, 255]) 44 | mask_red2 = cv2.inRange(hsv_img, red_lower_2, red_upper_2) 45 | 46 | # Combine both red masks 47 | full_mask = mask_red1 + mask_red2 48 | 49 | # Clean up noise from the mask 50 | full_mask = cv2.morphologyEx( 51 | full_mask, cv2.MORPH_OPEN, np.ones((5, 5), np.uint8)) 52 | 53 | # Replace detected red areas with background 54 | frame[np.where(full_mask == 255)] = bg_frame[np.where(full_mask == 255)] 55 | 56 | # Show the final output 57 | cv2.imshow('Magic Window', frame) 58 | 59 | # Break loop if ESC key is pressed 60 | if cv2.waitKey(10) == 27: 61 | break 62 | --------------------------------------------------------------------------------