An illusion- Image Projection with OpenCV

Sandeep Panchal
Analytics Vidhya
Published in
3 min readFeb 18, 2020
Source link

My warm welcome to all the readers!

Hey pals, how about having a cool project? Why not play around with the OpenCV (Open Source Computer Vision), a library used for computer vision? We are going to do the same now. With OpenCV, we are going to build cool stuff. The main theme of this project is to create an illusion effect that shows the projection of a moving (dynamic) image. This is done by combining the static frame with dynamic frames. By frames, I mean the images that are created during video capturing.

FYI: Inspired the idea of static and dynamic frames from https://www.machinelearningman.com/post/invisible-cloak-of-harry-potter-with-python

There are three main steps:

  1. Create static frames (background)
  2. Create dynamic frames (foreground)
  3. Add static and dynamic frames.

1. Create static frames (background):

In the first step, we have to create a frame that is used as a background. This frame is fixed and used as a background. The background frame is static and unchangeable. Any changes in the foreground will not affect the background.

Sample code to create a static background

2. Create dynamic frames (foreground):

In this step, we have to create continuous frames that are used for the foreground. Any object or subject in the background, if moved, the trace of the object or subject is seen. Trace of the object or subject moved looks like the transparent reflection that creates an illusion effect. For example, in the static frame, we have a table. From the foreground, if the table is moved or removed, the trace of the table can be seen as a transparent reflection.

Sample code to create foreground

3. Add static frame and dynamic frames:

In this step, we will add static frame (background) and dynamic frames (foreground) with cv2.add() or cv2.addWeighted().

Sample code to add foreground and background

Output: Video of the illusion effect:

FYI: For full code, please visit the GitHub repository

Connect me:

  1. LinkedIn: https://www.linkedin.com/in/sandeep-panchal-682734111/
  2. GitHub: https://github.com/Sandeep-Panchal

Thank you all for reading this blog. Your suggestions are very much appreciated!

--

--