In this video, Olga writes a program which converts this video.
Into this.
So as you can see in the article, the video of the face of the person speaking is blurred.
So this is a technique I'm going to use.
I'm going to blur the area around the face so that it's not visible.
You can also use other techniques, such as writing a rectangle, which is filled in.
But this is a more standard practice.
So let me show you how I can do this using, of course, open CV.
So import quota and load the video.
You can find the video attached in the lecture resources.
So the input video, which is smile that's aimed before and this is the output VIDEO So I'm going to
leave the output video and recreate it using open CV.
You also have this face is the example, which is the Cascade Fire, which contains the blueprints.
Oh, our face looks like in example code.
So the program needs to have that file in order to recognize faces in a video.
So video is legal to see to the video capture.
What I'm doing is referring to Smile does MP Fool and creates a video object.
In Python and then create two valuable success and frame a sequel to video reads.
So what I'm doing here is I'm reading the first frame of the video just to check if the video is read
correctly.
So success will gets through or falls as a value and frame will give the first frame as a value.
So if the frame is read successfully, success will be equal to true.
Otherwise, it will be equal to falls.
Then we have faced Cascade, a variable which points to servitude that cascade classifier, and that's
points to faces that example the path of the XML file.
So we have the video, we have the first frame, we have the face cascades object and then we create
an output.
Which is empty for now.
So that's a sequel to video writer.
Let's name this file outputs smile, MP, fool or blurred smile if you preferred or blur face.
So that is the ultimate video now this requires also another argument here that is CV to dot video right
to underscore for CC, which is a class by itself.
It expects now this argument, which is the context of the video you want to create.
The effects of this is what works.
I've tried this and three frames.
It's another argument.
So we've got the path to the ultimate file, the context of the video as a second argument.
The frames per second of the article, the video.
And lastly, the dimensions of the output feed you know of this should be in the form of a tipple,
which could be something like a three hundreds for hundreds of bullets.
You can just declare these numbers like that.
You want to have the same width and height as the original video so that you don't end up with a distorted
video.
Therefore, we need to get the dimensions of the original video.
So what I'm going to do is after we create the video object, after we get the first frame, we get
the dimensions of that first frame.
It's a single to frame dot shape and we get the first item of that table.
So that's creates a table with the height and the width, and the width is equal to frame its shape.
One.
So then we can specify here the width which comes first and the height.
So those are the dimensions of the ultimate video.
Then we were ready to build the wire loop.
Well, success, for example, which is equal to true.
So if success is true, then we build the while loop and ride frames in this output video object.
So while success, we did take the faces from using face cascades.
So that object, which has a detect multi scale glass and this gets a frame as inputs.
So we were working on the first frame.
For now, we detect faces in the first frame.
And these are the coefficients.
And so I've covered those one point one and four is a good set of numbers.
So if you change these, you can make the algorithm more sensitive or less sensitive.
So if you make it over sensitive, it means you will detect false positives.
So false faces objects which which are not faces, but.
Are classified as faces from this algorithm, so that will give us a list of faces because we might
have more than one faces in the frame.
But then we can iterate over the faces for.
X or Y?
So each face has an X and Y and the width and height.
So these are the dimensions of the rectangle around the detected phase.
So we see for that to pull interfaces.
And then we modify the current frame.
So the current frame, but we only modify a particular slice of the frame that is a slice, the portion
where the face is.
So with this coordinate, so y so from y until y plus h.
So that means where the rectangle of the face towards and until somewhere in here.
So we get that portion and then we get the other portion as well.
So we go again from X to X plus width.
So that will give us basically that.
And that's so it will give us the entire rectangle where the face is.
So the entire frame is something like this, right?
And the phase has these coordinates.
So now what we do to this portion of the frame here is we apply a CV to the blur methods and this goes
like this.
So frame again, y.
Y plus h.
And ex until X plus width.
And then we also provides the intensity of the blurriness.
So 50 50 is a good number.
You can go less than that if you want the face to be more visible and you can increase these if you
want the blurring effect to be more intense.
And that's it.
So now we have modified that portion of the frame by blurting it out and.
Then we exit the loop and we say, Oh, foods dot right frame, so we are right, that's current frame
that's modified frame into the outputs.
VIDEO Then what we do is so far we worked on the very first frame of the video, then we want to give
the other frames.
So we say again, success that and frame is sequel to VIDEO That's right.
So that we'll read the next frame of the video, and that's it.
So the while loop will be repeating itself and we exit the loop and we say outputs that release.
To release the video and make it able for writing it on disc.
So I'm going to execute this now.
Now, if you get this error, there is some mismatch between the formats, the video formats.
That means you want to change the outputs from MP for to delete a VR and run again.
You can see that blur smile the same before it's created, but the script has not ended execution yet.
So we want to wait until this file is written.
And of course, for the next time, you can improve the experience, the execution, the program execution
experience by writing here a variable count is equal to zero and then you do see counts as increased
by one and then you print the cones so that you can see some outputs here.
So you see the while loop being executed, so you see these numbers.
Actually, I can stop this and Ronnie's again so that we can see some outputs in here.
So now we see the cones, which basically represent each frame.
So every frame now is being processed.
We are in the eighth frame, nine, 10 and so on.
There will be 90 frames in total because the video is three seconds long.
So there are 30 frames per second.
Three times three, it's 90.
Yes, of the execution has finished, I can download the Lord's mine, that's a AIVI file.
And here it is.
So you can only open this, at least in my case, I can only open it with VLCC program VRC Media Player.
So the other ones might not work.
And yeah, that's the outputs, and that's the final codes.
Thanks for following this, and I'll talk to you the next videos.
So you.