├── image.jpg ├── .gitattributes ├── invisible_v.MOV ├── background.py ├── README.md └── invisible.py /image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zakiazft/invisible_cloak/HEAD/image.jpg -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /invisible_v.MOV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zakiazft/invisible_cloak/HEAD/invisible_v.MOV -------------------------------------------------------------------------------- /background.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | cap = cv2.VideoCapture(0) 3 | while cap.isOpened(): 4 | ret, back = cap.read() 5 | if ret: 6 | cv2.imshow("image", back) 7 | if cv2.waitKey(5) == ord('q'): 8 | cv2.imwrite('image.jpg', back) 9 | break 10 | 11 | cap.release() 12 | cv2.destroyAllWindows() 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # invisibility_cloak 2 | This is how you you can have your own Harry Potter Invisibility cloak. 3 | 4 | here, you have to select hsv code of a perticular color (in my case red) which will make that colored object invisible. 5 | I have also used morphological transformation to reduce the noise. 6 | # prerequisites 7 | * python 3.7 8 | * install opecCV library 9 | > conda install opencv-contrib-python 10 | 11 | and you are good to go. 12 | -------------------------------------------------------------------------------- /invisible.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | cap = cv2.VideoCapture(0) 5 | back = cv2.imread('./image.jpg') 6 | 7 | while cap.isOpened(): 8 | ret, frame = cap.read() 9 | 10 | if ret: 11 | hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 12 | l_red = np.array([0, 100, 100]) 13 | u_red = np.array([10, 255, 255]) 14 | 15 | mask = cv2.inRange(hsv, l_red, u_red) 16 | kernel = np.ones((5, 5), np.uint8) 17 | 18 | mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) 19 | mask = cv2.morphologyEx(mask, cv2.MORPH_DILATE, kernel) 20 | 21 | mask2 = cv2.bitwise_not(mask) 22 | 23 | part1 = cv2.bitwise_and(back, back, mask=mask) 24 | part2 = cv2.bitwise_and(frame, frame, mask=mask2) 25 | 26 | cv2.imshow("cloak", part1+part2) 27 | 28 | if cv2.waitKey(5) == ord('q'): 29 | break 30 | 31 | cap.release() 32 | cv2.destroyAllWindows() 33 | --------------------------------------------------------------------------------