Skip to content

A program that uses Colour Segmentation using OpenCV and makes a specific colour disappear.

Notifications You must be signed in to change notification settings

zabhitak/invisible_cloak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Harry Potter's Invisible Cloak

This is simply a program that uses color segmentation and a bit of image processing to replace the foreground object of interest with the background.

You can take a unicolor bedsheet and apply color segmentation on it. After that take a picture of the background and place the bedsheet over yourself to virtually disappear, or make some part of your body disappear.

Dependencies:

  1. Python 3
  2. Numpy
  3. OpenCV (Python)

Installation for Python 3

Visit: https://www.python.org/downloads/ and download the version suitable for your System

Installation for Numpy

Open Command Prompt (Windows) or Terminal (Linux) and type in the following command:

 pip install numpy

Visit: https://scipy.org/install.html for details.

Installation for OpenCV

Open Command Prompt (Windows) or Terminal (Linux) and type in the following command:

 pip install opencv-python

Visit: https://pypi.org/project/opencv-python/ for details.

Algorithm

  • Convert RGB to HSV and select a range, which is used to segment the color
  • Create a mask with the segmented HSV color
  • Apply Morphological Operations (Closing) to fill out holes in the mask. Make sure you use appropiate kernel/filter size. 10 works for my case.
  • Find all the contours using OpenCV function and then arrange them in descending order in terms of Area.
  • Select the largest contour and create a complete mask of that using polynomial fill function.
  • With that mask, create object and background masks
  • Bitwise OR the background and object masks in order to replace the object of interest with the background
  • Repeat this for every frame
  • Voila!

How to use?

  1. Run the ColorSegmentation.py (While Running it, make sure nobody is infront of the webcam)
  2. An window showing the background image will pop up.
  3. Press any key while being on that window to start real time frame-by-frame Color segmentation.

The HSV values are calculated for the following cloth color. But you may have to re-define your values to make it work for other colors.

How does it work ?

The algorithm is very similar in principle to green screening. But unlike green screening where we remove the background, in this application, we remove the foreground! We are using a red colored cloth as our cloak. Why red? Why not green? 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 tweaking.

The basic idea is given below:

  • Capture and store the background frame.
  • Detect the red colored cloth using color detection algorithm.
  • Segment out the red colored cloth by generating a mask.
  • Generate the final augmented output to create the magical effect.

About

A program that uses Colour Segmentation using OpenCV and makes a specific colour disappear.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages