In this video, we will write a program which opens a computer webcam, and it shows the video of life,
as you can see in here.
So in addition, we also see a rectangle around the face of humans in the video.
So let's do this in this video.
So I'd like to start this program from the previous script, and I'm going to build upon this.
So the previous program?
Was able to open the computer webcam and to record the video.
Using that webcam, but we didn't see the video live.
We just got a final video file at the end in this program, we want to see what is being captured alive
and the way you do that is by using a method called CV.
To that, I am show a let me explain you where we put that methods.
So here we create the video, we capture it from the webcam and we get the first frame and then we get
behind the width.
We create a face cascades a blueprint for detecting faces, and then we create an output file where
the video will be stored when we close the program.
And then we have this loop success as a Boolean.
So it is true when the video is being captured from the webcam, we detect the faces from the frame,
the current frame.
So the frame we got sets from here.
Then we go through all the phases and we draw a rectangle around each phase.
Now at this point here we want to on indent, so be outside the full loop.
But inside the one loop and see see two dots I show I am stands for image show.
So we want to show the frame, the image on the screen.
We want to give a label to the window.
Recording should define.
And then the second argument should be the actual image object.
So the frame object you want to display on that window.
After that, you want to apply the CV to that weight key methods and give an argument of one.
This is basically specifying how long will you wait to display the next video?
So this is one milliseconds and that is a safe value so we can keep it one.
And that's it.
We can run this code now and see what's going on here.
So once I run, it's among your programs, you should see this icon that is the program that has the
video.
So this is life.
Now you see the rectangle around my face, even though this is a very bad lighting.
It's still working well.
You know, you can stop this using this button.
The Stop button, although there is a better way to stop the video from playing, using a more user
friendly technique that is by after the key you apply if key is equal to.
So you see this double assignment operator AWD Q So if the user presses the Q button on their keyboard,
then you want to break the loop.
So let's try this again.
So here is the window.
I press Q.
It took one or two seconds, but the video stopped.
So you should also see now that we have the output, that's Avio File here in my folder, I can open
it with V L C.
And you can see that the video is playing very fast, and we can fix that by changing the frame per
second rate over the video.
So what's happening here is that my webcam records video in 15 frames per second, but the video right
here is configured to write 30 frames per second.
So there is a mismatch between the frames you should try to find on your computer how many frames your
webcam captures and then puts here that number of frames.
So 15, in my case.
So let me run this again.
Yeah, here is the video.
One, two three.
Let's stop.
Cue.
So when you press Q, you should have the focus on the video player for Q to work.
Let me check the output again.
Now, the speeds looks normal to me.
Yeah.
So it's working.
We need to add two more lines here to make this more complete.
And that is, you need to release the video.
This is a good practice to do.
And served to destroy all the windows, that is the methods, and let's try the program again to make
sure everything is working smoothly.
So here is the window.
Hello again.
Press cue to quit.
And it's quite.
There is a bit of delay in my computer, though.
But anyway, if this is the final program.
Capturing the video from webcam, detecting the faces in the video, showing the video on the screen
and also writing the video file in a video a V file, so I hope it works for you and I'll talk to you
in the next videos.
So you.