Coders Packet

Invisibility Cloak using OpenCV in Python

By Sai Lokesh

This model is based on OpenCV. Here the live video is captured and if the cloak/any material of any selected color is in the video it shows the background in that particular region.

This model is based on OpenCV. It's written in Python. Here the live video is captured and if the cloak/any material of specific color is in the video it shows the background in that particular region. Its almost like there is no obstacle to that specific color in the video at all. Here the color we choose is red. Here the dependencies are OpenCV, NumPy, Time.

The workflow is as follows

1. Capture and store the background frame.
2. Detect the red colored cloth using color detection and segmentation.
3. Segment out the red colored cloth by generating a mask.
4. Generating the output.

First, the background has to be captured. Open the cam and leave it for 2-3 seconds to capture the background. Then the background image which is in the form BGR has to be converted into HSV form.we have to create two masks one is corresponding to the background image and another one corresponding to the target image.

To create masks first, we have to make the boundaries for the red color in the target image. Only that region will be replaced by the background image. In order to define the boundary, we should know the following three factors/channels.

Hue: It encodes the color information. It can be treated as an angle where 0 degree corresponds to red color,120 degrees represents green and 240 represents the blue color.

Saturation: It encodes the purity of color.

Value: It encodes the brightness of color.

In the end, morphology function has to be applied to the two masks one corresponding to the background and another one corresponding to the obstacle. The main purpose of the Morphology function is it deletes the Noice/disturbances in the video/image. Here the disturbance is mask corresponding to the target image.so it will erase it and the background will appear in that mask region.

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Sai Lokesh (sailokeshvadlamudi)

Download packets of source code on Coders Packet