-
-
Notifications
You must be signed in to change notification settings - Fork 264
Invisible Clock using Python #417 #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3216856
Create invisiblecloak.py
Cartikx3 eaf3bca
Rename BasicPythonScripts/invisiblecloak.py to BasicPythonScripts/INV...
Cartikx3 28ba2e4
Create README.md
Cartikx3 37da627
Update README.md
Cartikx3 67428d4
VIdeo Added In README
bhattcodes 6b5c8c1
Merge pull request #1 from bhattcodes/main
Cartikx3 03dbcfe
Update README.md
Cartikx3 3e2896f
Create requirements.txt
Cartikx3 11de7ea
Add files via upload
Cartikx3 4356aba
Create MEDIA
Cartikx3 69e6d5c
Delete MEDIA
Cartikx3 5d81054
Create READ.md
Cartikx3 dae7ed9
Add files via upload
Cartikx3 4a5aca9
Delete output.mp4
Cartikx3 0e316fb
Create Invisibility Cloak
Cartikx3 ac86eb0
Delete Invisibility Cloak
Cartikx3 a34aad4
Rename BasicPythonScripts/INVISIBLE CLOAK/invisiblecloak.py to BasicP...
Cartikx3 e5f5c26
Update requirements.txt
Cartikx3 74f562a
Rename BasicPythonScripts/INVISIBLE CLOAK/requirements.txt to BasicPy...
Cartikx3 4bce61b
Update and rename BasicPythonScripts/INVISIBLE CLOAK/README.md to Bas...
Cartikx3 4bd1d23
Rename BasicPythonScripts/INVISIBLE CLOAK/MEDIA/READ.md to BasicPytho...
Cartikx3 10c212f
Add files via upload
Cartikx3 98e8274
Delete BasicPythonScripts/INVISIBLE CLOAK/MEDIA directory
Cartikx3 c252586
Delete READ.md
Cartikx3 32e3bb4
Update README.md
Cartikx3 571e073
Update README.md
Cartikx3 aac9b32
Update README.md
Cartikx3 13b08f2
Add files via upload
Cartikx3 3dc4cd7
Update README.md
Cartikx3 0240c1f
Delete output.mp4
Cartikx3 dc3a99c
Update README.md
Cartikx3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BasicPythonScripts/Invisibility Cloak/Media/output.gif
45 changes: 45 additions & 0 deletions
BasicPythonScripts/Invisibility Cloak/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Invisibility Cloak | ||
|
||
# Aim | ||
Hello EVERYONE,lets do some magic using computer vision. I hope you all know about ‘invisible cloak’, this will make you invisible. We will see how we can do the same magic trick with the help of computer vision. I will code with python and use the opencv and numpy library. | ||
|
||
# Purpose | ||
Our purpose is to become Invisible using a cloak with the help of various Python libraries. | ||
|
||
# Setup instructions | ||
|
||
1. Install the latest python 3.5 and above and once you finish installing it . | ||
2. Add opencv library. | ||
3. Add Numpy library. | ||
|
||
# Detailed explanation | ||
|
||
We wll learn how to create our own ‘Invisibility Cloak’ using simple computer vision techniques in OpenCV. Here we have written this code in Python because it provides exhaustive and sufficient library to build this program. | ||
|
||
Here, we will create this magical experience using an image processing technique called Color detection and segmentation. In order to run this code, you need an mp4 video named "video.mp4". You must have a cloth of same color and no other color should be visible into that cloth. We are taking the red cloth. If you are taking some other cloth, the code will remain the same but with minute changes. | ||
|
||
firstly the program when you run it it will capture the background image and then. When you put a red colored colored cloth in front of camera the program will detect the colored cloak using color detection and segmentation algorithm . And the program will generate a mask to determine the region in the frame corresponding to the detected color(red in this case). Program will refine this mask and then use it for segmenting out the cloth from the frame. Program will replace the pixels value of the detected red color region with corresponding pixel values of the static background. | ||
|
||
# Compilation Steps | ||
|
||
1. Capture and store the background frame | ||
2. Detect the defined color using color detection and segmentation algorithm. | ||
3. Segment out the defined colored part by generating a mask. | ||
4. Generate the final augmented output to create a magical effect. | ||
|
||
|
||
|
||
# Output | ||
|
||
|
||
 | ||
|
||
|
||
|
||
|
||
|
||
# Author(s):- | ||
[Kartik Srivardhan](http://github.com/Cartikx3) | ||
|
||
|
||
|
69 changes: 69 additions & 0 deletions
BasicPythonScripts/Invisibility Cloak/invisible_cloak.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import cv2 | ||
import time | ||
import numpy as np | ||
|
||
## Preparation for writing the ouput video | ||
fourcc = cv2.VideoWriter_fourcc(*'XVID') | ||
out = cv2.VideoWriter('output.avi',fourcc,20.0, (640,480)) | ||
|
||
##video capturing from the webcam | ||
cap = cv2.VideoCapture(0) | ||
|
||
## Allow the system to sleep for 3 seconds before the webcam starts | ||
time.sleep(3) | ||
count = 0 | ||
background = 0 | ||
|
||
## Capture the background in range of 60 | ||
for i in range(60): | ||
ret,background = cap.read() | ||
background = np.flip(background,axis=1) | ||
|
||
|
||
## Read every frame from the webcam, until the camera is open | ||
while(cap.isOpened()): | ||
ret, img = cap.read() | ||
if not ret: | ||
break | ||
count+=1 | ||
img = np.flip(img,axis=1) | ||
|
||
## Convert the color space from BGR to HSV | ||
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) | ||
|
||
## Generate masks to detect red color | ||
lower_red = np.array([0,120,50]) | ||
upper_red = np.array([10,255,255]) | ||
mask1 = cv2.inRange(hsv,lower_red,upper_red) | ||
|
||
lower_red = np.array([170,120,70]) | ||
upper_red = np.array([180,255,255]) | ||
mask2 = cv2.inRange(hsv,lower_red,upper_red) | ||
|
||
mask1 = mask1+mask2 | ||
|
||
## Open and Dilate the mask image | ||
mask1 = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, np.ones((3,3),np.uint8)) | ||
mask1 = cv2.morphologyEx(mask1, cv2.MORPH_DILATE, np.ones((3,3),np.uint8)) | ||
|
||
|
||
## Create an inverted mask to segment out the red color from the frame | ||
mask2 = cv2.bitwise_not(mask1) | ||
|
||
|
||
## Segment the red color part out of the frame using bitwise and with the inverted mask | ||
res1 = cv2.bitwise_and(img,img,mask=mask2) | ||
|
||
## Create image showing static background frame pixels only for the masked region | ||
res2 = cv2.bitwise_and(background, background, mask = mask1) | ||
|
||
|
||
## Generating the final output | ||
finalOutput = cv2.addWeighted(res1,1,res2,1,0) | ||
out.write(finalOutput) | ||
cv2.imshow("magic",finalOutput) | ||
cv2.waitKey(1) | ||
|
||
cap.release() | ||
out.release() | ||
cv2.destroyAllWindows() |
5 changes: 5 additions & 0 deletions
BasicPythonScripts/Invisibility Cloak/requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This projects requires latest Python version (i.e 3.5 and above) that has PIP built in and the libraries that are imported are :- | ||
|
||
1. openCV Library. | ||
2. Numpy Library. | ||
3. time Module. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.