Have you ever seen Harry Potter’s Invisible Cloak; Was it wonderful? Have you ever wanted to wear that cloak? If Yes!! then in this post, we will build the same cloak which Harry Potter uses to become invisible. Yes, we are not building it in a real way but it is all about graphics trickery.
In this post, we will 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.
Why Red? Green is my favorite?
Sure, we could have used green, isn’t Red the magician’s color? Jokes aside, colors like green or blue will also work fine with a little bit of changes in code.
This technique is opposite to the Green Screening. In green screening, we remove background but here we will remove the foreground frame. So let’s start our code.
1. Capture and store the background frame [ This will be done for some seconds ]
2. Detect the red colored cloth using color detection and segmentation algorithm.
3. Segment out the red colored cloth by generating a mask. [ used in code ]
4. Generate the final augmented output to create a magical effect. [ video.mp4 ]
Below is the Code:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- PyQt5 - Make Status Bar invisible
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Project Idea | (Project Approval System)
- Python | Create video using multiple images using OpenCV
- Image resizing using Seam carving using OpenCV in Python
- Cartooning an Image using OpenCV - Python
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- OpenCV Python Program to analyze an image using Histogram
- Detection of a specific color(blue here) using OpenCV with Python
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Erosion and Dilation of images using OpenCV in python
- Template matching using OpenCV in Python
- Addition and Blending of images using OpenCV in Python
- Reading an image in OpenCV using Python
- Python | Play a video in reverse mode using OpenCV
- Python | Program to extract frames using OpenCV
- Opening multiple color windows to capture using OpenCV in Python
- Converting Color video to grayscale using OpenCV in Python
- Python | Play a video using OpenCV
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.