You will be creating a web application which will perform real time video processing of a webcam video stream consisting of a green screen and replace it with a background video or an image of your choice.
You will be creating a web application which will perform real time video processing of a webcam video stream consisting of a green screen and replace it with a background video or an image of your choice.
Have you ever seen a movie in which a superhero flies through the sky? You can see all the skyscrapers whizzing by in the background, and it looks so cool. Have you ever WONDERed how movie makers film such shots?
The special effects created during weather forecasts and many, many television shows and movies utilize a special tool called a green screen. Why is it called a green screen? Mainly because it consists of a large screen that is green! The green screen is an integral part of the special effects process known formally as chromakey.
Chromakeying, sometimes known as color keying, is the process of singling out a particular color in an electronic image and then using computer software to make that color transparent. This allows another image, which can be just about anything you can imagine, to show through.
This project is a good start for beginners, a new idea for intermediates and a refreshing hobby project for professionals. It involves the basic use of all of HTML, CSS and JS languages. Reason for following this tech-stack is that these languages are easy to use and are also fast in terms of execution time.
The project consists of the following stages:
The desired end result of this project is like this:
Some of the applications of Green Screen Video Processing are:-
You will be creating a web application which will perform real time video processing of a webcam video stream consisting of a green screen and replace it with a background video or an image of your choice.
Have you ever seen a movie in which a superhero flies through the sky? You can see all the skyscrapers whizzing by in the background, and it looks so cool. Have you ever WONDERed how movie makers film such shots?
The special effects created during weather forecasts and many, many television shows and movies utilize a special tool called a green screen. Why is it called a green screen? Mainly because it consists of a large screen that is green! The green screen is an integral part of the special effects process known formally as chromakey.
Chromakeying, sometimes known as color keying, is the process of singling out a particular color in an electronic image and then using computer software to make that color transparent. This allows another image, which can be just about anything you can imagine, to show through.
This project is a good start for beginners, a new idea for intermediates and a refreshing hobby project for professionals. It involves the basic use of all of HTML, CSS and JS languages. Reason for following this tech-stack is that these languages are easy to use and are also fast in terms of execution time.
The project consists of the following stages:
The desired end result of this project is like this:
Some of the applications of Green Screen Video Processing are:-
We'll start of by initializing the project structure.
npm init
and fill all the require details in the prompt.Now we can implement the various components of our project.
In this milestone, a basic template of some code will be required in the project files.
index.html
file with all the CSS and JS files imported present in the project folder.<canvas>
elements with the IDs c1
and c2
and one <video>
element with ID v1
. The given IDs for above three HTML elements will be used by JavaScript methods to access and interact with them in the further stages.index.js
file must contain references to the video and canvas elements along with Canvas 2D Context
for the canvas c1
and c2
.A required skeleton document with HTML elements is created to display three different video streams present at each different stages in the video processing pipeline.
In this milestone, we will capture the input webcam video stream and display it on the <video>
and 1st <canvas>
.
<video>
element's Webcam stream using MediaDevices.getUserMedia()
which is available as a Web API under MediaDevices
interface.computeFrame()
which will be used for frame by frame video processing.<video>
element with ID v1
and pass second parameter as anonymous function enclosed of setInterval()
method attached to computeFrame()
function.c1
and programmatically created background image or video of your choice to Canvas c2
in computeFrame
function.After implementing the above requirements, video is displayed in the <video>
element and canvas1, selected background image is displayed in the canvas2.
In this milestone, we will set the green pixels alpha value to transparent ( i.e zero ) and display in the 1st Canvas.
In the computeFrame() function,
c1
and extract pixels from the data
attribute of the frame.(r,g,b,a)
values and convert each pixel from RGB to HSL format.a
of each pixel to zero if the Hue value lies in the range of Green color.c1
at the end of the function outside the pixel manipulation loop.After implementing the above requirements, processed video with transparent pixels is displayed in the canvas1.
In this milestone, we will merge the processed video stream with a personalized background image or video and display it in the 2nd Canvas.
In the Pixel Manipulation loop of computeFrame() function,
rgba
for pixels from the frame using fillStyle
attribute of the Canvas Context c2
if the Hue value doesn't lies in the range of Green color.((Current Pixel iteration value/ length of pixel array) % Width of Canvas c2)
.((Current Pixel iteration value / length of pixel array) / Width of Canvas c2)
.fillRect
method of Canvas Context.After implementing the above requirements, below is the processed video with personalized background.
As the basic implementation is all done, for all the curious cats out there, these are some of the line items which can be implemented to spice up the existing functionality.
[Note: This is not a mandatory milestone]
You should be able to add more features to your application.