Hi, welcome back.
In this video Over the Roads, a program which detects faces in a video, in an MP for video and then
creates a new video based on the original video, but with rectangles added around the faces in the
video.
Now to understand these video, you should have watched two previous videos.
One is where we detected faces in an image that is the code that we build through all that video.
This is the video in the image processing section and also in the video processing section.
We had a video where we extracted frames from a video file and this video in this program, we will
combine the code of these two scripts.
That's why I've pasted these two scripts in this report.
So let's start how do we start this?
Well, we want to first read the video video we will be working on is this one in here is three seconds
long.
And we will try to detect the face of the person here.
So draw a rectangle around this with you.
Right.
So let's start by opening the video.
I think this script should be the first one in here, so we import open S.U.V. and we capture a video
file stoning that's in the video valuable and we get to the first frame of the video here.
We just have a counter a that is equal to one.
We don't need that, actually.
Just delete the counter.
And here we have success, which is equal to true if we were able to get.
The video writes successfully so while true, we execute this block of codes.
What we do here is we write an image to an image file.
This is not what we're doing this time.
So we delete that.
What we do this time in each frame is we detect faces.
So in this other script in here we are opening an image, a frame.
We construct frames, using files, using image files.
But this time we have those image objects.
So that is an image object that is an image object.
This comes from the video of this comes from an image file.
But still, these two are the same types of objects.
So what we do is once we have an object, a frame objects, we want to get the faces from that image
object.
You see that image object is passed in here.
So I'm going to delete that.
We don't need that and get this line face cascades and paste.
It's above the loop outside the loop because we want to create a Cascades object first.
So this is the blueprint that contains how a face a human face looks like.
So then we get the faces in here in the wide loop.
So indent.
So the first sets of faces for that first frame rates.
So we create the first frame here, the very first frame of the video, and we detect faces in that
very first frame rates.
Then what we do is that while we iterate so we get that block of codes, we paste it here and indent
tab, you see four is under the wire loop and then you have this is intent on the before loop o seu
for x y width and height in.
Faces, we say it right, a rectangle around the frame, the current frame in the first iteration of
the while loop, this will be the very first frame of the video we said that's already.
So we draw a rectangle with these coordinates where the face is found.
This is a white rectangle with a width of four.
That's fine.
And then what do we do with this frame?
We want to ride that frame in a new video for that, we need to first create a new video on empty video.
So let's do that outside the loop outputs as a variable name, a sequence of two dots VIDEO.
Right to is the class that creates new videos and opens TV works well with a VIP video formats.
So let's the right outputs does Aivi as the name of the video file a comma.
Then you have to give some parameters, such as video writer.
That's one.
This is the context of the video, so you have to write it like this.
Then outside the parentheses goes the number of frames per second and also the dimensions of the new
video.
You want to have the dimensions we can gather those using actually, we can use it hides a single to
frame the shape zero and width is equal to frame the shape.
So we're getting the dimensions of the original video because we want to have the new video using the
same width and height.
So for width and then height, the resolution of the video and we have 30 frames per second.
So once we have an empty video file video objects, we don't have a file yet, then we want to create
a file on disk.
So we say under the while loop outside the full loop, just here, actually outside the full loop.
So once we drew rectangles in the current frame, then we want to access the empty output video and
use the right methods and right the frame, the current frame to the video.
So we detect face in the frame.
We iterate over all the faces because there could be more than one face in the video.
We are right rectangles around the face and then we ride the frame in the outward video.
Then what we do is we again get to the next frame.
So when we execute this, the next frame will be stored in the frame variable and the loop will run
again.
So this time with a second frame, we detect faces with the second frame.
We iterate through those phases.
We arrive the second frame in the video, which is currently open and so on.
We repeat the process until all the frames have been exhausted.
Then outside the wire loop, you have to indent your axis, outputs the video and you release it to
generate the video and store its on disk.
So we don't need that's code.
This is all we need.
Let me split this line in here because it's too long and we are ready to run this.
So, Ron, we see that output does a the eye has been generated, but you have to wait for about two
minutes or so because video processing takes long.
So we have three seconds, but we have 90 frames and a rifle is not that fast.
So you have to wait a while.
So my run button is green again, that means the processing finished.
So let me download this article to Aivi file because I don't think it's is able to open API files.
The way you can open them is by using.
I tried the VLCC program works well.
Yeah.
So this is a video.
It's three seconds.
You see the rectangle there for some moments.
We also see.
A false positive in here in the hands of the person is detected as a phase.
Perhaps you can fix that by experimenting with these values in here so you can try that on your own.
You can try to do 1.2 and increase and decrease the other value as well.
We discussed these values when we detected faces in images in the image processing section.
If you want to visually see the artifacts here, you could add a counter such as can't equal to zero
of you say here counts increased by one and print counts.
So that way you can see what's going on here.
So one, two three.
There's a number of the frames they started from one.
Sometimes I noticed that this was far slower.
This time it was faster the processing.
So 90 frames in total in output.
That's a V file.
And that is all you can get the frames of a video modify them, such as writing rectangles around faces
as we did, and then write back the frames in a new video.
Thank you for following I'll talk to you in the next videos.