In this article, we will learn how to create your own Invisibility Cloak using simple computer vision techniques in OpenCV . We wrote this code in Python here because it provides a comprehensive and sufficient library to build this program.
Here we will create this magical experience using image processing techniques. To run this code, you need a video in
video.mp4 mp4 named “
video.mp4 “. You must have the fabric of the same color, and it must not have a different color on it. We take the red cloth. If you change clothes, the code will remain the same, but with minor changes.
Why red? Is green my favorite?
Surely we could use green, isn`t the magician`s red? Jokes aside, colors like green or blue will also work well with small changes to the code.
This method is the opposite of green screening . On the green screen, we are removing the background, but here we are removing 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:
You can check the source code in the project github repository for video input and more details — here