Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 2bd178f

Browse files
authored
Merge pull request #132 from anisha282000/Invisible_cloak
Invisible Cloak
2 parents 8ec4b27 + 36fcdcd commit 2bd178f

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Invisible Cloak
2+
This is a python script about the cloak of invisibility which was used by harry to become invisible.
3+
4+
## How it works
5+
* It captures and store the background.
6+
* Detect the defined color using color detection.
7+
* Segment out the red colored cloth by generating a mask.
8+
* Generate the final augmented output to create a magical effect.
9+
10+
## Installation
11+
* Use the package manager [pip](https://pip.pypa.io/en/stable/) to install Opencv.
12+
13+
```bash
14+
pip install opencv-python
15+
```
16+
* Install Numpy
17+
18+
```bash
19+
pip install numpy
20+
```
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import numpy as np
2+
import cv2
3+
import time
4+
5+
print("""
6+
BE PREPARE YOU WILL BE INVISIBLE SOON............
7+
""")
8+
9+
if __name__ == '__main__':
10+
cap = cv2.VideoCapture(0)
11+
12+
#For capturing output video
13+
fourcc = cv2.VideoWriter_fourcc(*'XVID')
14+
out = cv2.VideoWriter('harry.avi' , fourcc, 20.0, (640,480))
15+
time.sleep(2)
16+
background = 0
17+
18+
#capturing background
19+
for i in range(30):
20+
ret, background = cap.read()
21+
22+
#capturing image
23+
while(cap.isOpened()):
24+
ret, img = cap.read()
25+
26+
if not ret:
27+
break
28+
#HSV stands for Hue Satrurated Value
29+
hsv=cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
30+
31+
#YOU CAN CHANGE THE COLOR VALUE BELOW ACCORDING TO YOUR CLOTH COLOR
32+
lower_red = np.array([0,120,70])
33+
upper_red = np.array([10,255,255])
34+
mask1 = cv2.inRange(hsv , lower_red , upper_red)
35+
36+
lower_red = np.array([170,120,70])
37+
upper_red = np.array([180,255,255])
38+
mask2 = cv2.inRange(hsv , lower_red , upper_red)
39+
40+
mask1 = mask1 + mask2
41+
42+
#Open and clean the mask image
43+
mask1=cv2.morphologyEx(mask1, cv2.MORPH_OPEN ,np.ones((3,3) , np.uint8) , iterations=2)
44+
45+
mask2=cv2.morphologyEx(mask1, cv2.MORPH_DILATE ,np.ones((3,3) , np.uint8) , iterations=1)
46+
47+
mask2 = cv2.bitwise_not(mask1)
48+
49+
#Generating the final output
50+
res1 = cv2.bitwise_and(background, background, mask=mask1)
51+
res2 = cv2.bitwise_and(img, img, mask=mask2)
52+
53+
final_output = cv2.addWeighted(res1 , 1, res2 , 1, 0)
54+
55+
cv2.imshow('Invisibility Game' , final_output)
56+
k=cv2.waitKey(10)
57+
if k==27:
58+
print("Escape hit, closing...")
59+
break
60+
61+
cap.release()
62+
out.release()
63+
cv2.destroyAllWindows()

Image-Processing/README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)