├── README.md └── InvisibleCloak.py /README.md: -------------------------------------------------------------------------------- 1 | # The-Invisible-Cloak 2 | An OpenCV project which uses an image processing technique called Color detection and segmentation to make yourself invisible live in the webcam with the help of asingle-color cloth(Here I'm using a red cloth). 3 | 4 | Technologies Used: Python 3.9-> OpenCV library, NumPy library 5 | 6 | BASIC IDEA behind the project: 7 | 8 | 1.Capture and store the background frame. 9 | 10 | 2. Detecting the red colored cloth using color detection 11 | algorithm. 12 | 13 | 3. Segmenting out the red colored cloth by generating a mask. 14 | 15 | 4. Generating the final augmented output to create the magical 16 | effect. 17 | -------------------------------------------------------------------------------- /InvisibleCloak.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import time 4 | 5 | cap = cv2.VideoCapture(0) 6 | time.sleep(3) 7 | background=0 8 | 9 | for i in range(30): 10 | ret,background = cap.read() 11 | 12 | background = np.flip(background,axis=1) 13 | 14 | while(cap.isOpened()): 15 | ret, img = cap.read() 16 | 17 | # Flip the image 18 | img = np.flip(img, axis = 1) 19 | 20 | # Now Converting the image to HSV color space. 21 | hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 22 | blurred = cv2.GaussianBlur(hsv, (35, 35), 0) 23 | 24 | # Defining lower range for red color detection. 25 | lower = np.array([0,120,70]) 26 | upper = np.array([10,255,255]) 27 | mask1 = cv2.inRange(hsv, lower, upper) 28 | 29 | # Defining upper range for red color detection 30 | lower_red = np.array([170,120,70]) 31 | upper_red = np.array([180,255,255]) 32 | mask2 = cv2.inRange(hsv, lower_red, upper_red) 33 | 34 | # Addition of the two masks to generate the final mask. 35 | mask = mask1 + mask2 36 | mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, np.ones((5,5), np.uint8)) 37 | 38 | # Replacing pixels corresponding to cloak with the background pixels. 39 | img[np.where(mask == 255)] = background[np.where(mask == 255)] 40 | cv2.imshow('Display',img) 41 | k = cv2.waitKey(10) 42 | if k == 27: 43 | break --------------------------------------------------------------------------------