Building Harry Potter’s Cloak Of Invisibility Using Python

6+
We have seen Harry Potter’s invisibility cloak in the movies and read about it in the book. In this article, we will show how to build it using Python.
Source: Artem Malstev from Unsplash

It is a dream of many of us to go to Hogwarts and learn magical spells just like Harry Potter and his friends. I always wanted to learn how I can be invisible. Harry had a cloak which could turn him invisible. That cloak was known as Cloak of Invisibility. 

Well, we are not creating Cloak of Invisibility; it will be a graphical trick that would resemble Invisibility Cloak. 

We have chosen Python because it has enough and exhaustive libraries to support our program.

We have used Color Detection and Segmentation, which is an image processing technique, to bring this magical invisibility experience to life. We will also be requiring a red-colored cloth. We will be turning this red cloth invisible.

Working:

As discussed above. We are using the Color Detection and Segmentation technique to turn a normal cloth into an invisible cloak. Well, this technique is just the opposite of the Green Screening technique. Here are the steps that we will follow:

  • First, we will be capturing and storing the background frame.
  • Detection of Red color using color detection and segmentation technique.
  • Creating a mask of red color and segmenting it out.
  • Finally the magical part, generation of our final augmented output.

Code:

GitHub Link

https://github.com/Sid-Yo/Invisible-cloak-SidYo/blob/master/sidyo_potter.py

Output Video Link

Tips

Here are some tips which can enhance our magical experience:

  • Make sure there is no other red-colored object in the frame.
  • Wear something other than red.
  • The red color cloth should be of proper shade.
  • Make sure you are out of frame when you run the code.
  • Come inside the frame when the webcam has captured the background image.

Can I use any other color than red?

Yes, we can use any color cloth of our choice by making some changes in the code. We will need to change the Hue Saturation Value (HSV) value of the red color with the HSV value of the color of your choice.

Hue range from 0 to 360 degrees, and is defined as the color portion of the model. Here are some Hue ranges:

  • Red: 0-60 degree
  • Yellow: 61-120 degree
  • Green: 121-180 degree
  • Cyan: 181-240 degree
  • Blue: 241-300 degree
  • Magenta: 301-360 degree

Saturation ranges from 0 to 100 percent and defines the quantity of grey in a particular color. Reducing saturation to zero gives a faded effect and makes the image greyer. 

Value or Brightness ranges from 0 to 100 percent and describes the intensity of color. It works in conjunction with Saturation. Here, 0 gives completely black while 100 reveals the brightest color.

Congratulations! Welcome to the family of Wizards.

close
6+

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

DMCA.com Protection Status