And welcome to lesson tapes, where we take a look at performing or implementing fear swaps, which
is a very cool and I guess it's a bit outdated now, but it was quite big back in 2015 2016 with Snapchats
and those ups, I mean, few swaps are so popular right now, but it was the height of its popularity
was probably back then.
So we're going to implement that using dylib, which we just demonstrated before on how we get facial
landmarks will know.
We're going to use those facial landmarks, line them up to do swaps, which is the underlying technology,
would help all of those with physical bumps work.
So let's open this notebook and we'll wait for it to load and standard procedure.
We load all libraries in images and the prediction model.
And this is a code for performing peer swaps.
So I wouldn't go to every single thing in this code because it's quite long.
You can see that here.
It's actually very low.
But firstly, I will say I didn't write this code.
This code was created by Matt.
We're not sure how much you care so much of it or something.
Yes.
And this is his blog address.
Here is this copyright license material is his name and why it took me so long to say that.
So we'll take a look at the code in a broad sense.
So let's take a look.
Perception is good.
Firstly, so we just declare some variables here, which is a path for prediction model scale effect
of the amount, which is basically how much we're doing the layering of the faces.
Then you can see remember how we had zero to 60 odd points, each of those points each.
Each of those points has some ranges, which correspond to first points, most points right by our left
brow.
Right.
I left a notice points in Joplin.
So those are the points we need to mesh and align so that we can line up on the face.
So you can see that that points used to line up on the face here, but is here and these are the overlay
points as well.
So remember, we're trying to overlay another face onto office, so we have to mesh those points together,
and that's what the overlay points indicate here.
So the other part to be doing here is just doing some color correction and some blurring so that we
can make the face swap look a little bit more realistic.
So that's what this color correction factor parameters controls.
This here is the detect and predict two objects.
You've seen this before the annotated landmark functions.
This is a draw convex hull, which allows us to map the points properly to three interfaces.
This is to get first mass so we can extract the face from the image to put onto the first image.
This here now is a transformation from two points.
So it returns the Afeyan transformation so that the points sort of line up and perspective adjusted
correctly.
So it's a lot of different stuff is going on in this code, but I hope this gives you that this shows
you the power of open TV so you can do some pretty complicated functional programs with open but simply
just open TV doing the manipulation in the back end.
So we have that and there.
No, we're going to take a look at the functions here.
This is a surreal image.
You get the landmarks simple function.
This is a warped image function where we just take down the image, the matrix and the shape, and we
just output the final image based on those parameters.
We have completely prevent the war by firing a function on it.
This is the color correction.
Remember, I mentioned we're doing some color correction with the color correct glyph parameter.
So this and reasons of Gaussian blur to make sure it looks, it looks nice.
And then this is a function here that controls everything swampy.
So we'll be just text to images here and uses all the functions we defined above to return the final
image, which is the image of the face being swapped.
So let's run this and it shouldn't take too long.
It's not super complicated.
There we go.
Very scary.
But we have just put Hillary Clinton's face on Donald Trump.
Color corrected it, warped it.
Properly adjusted the color.
Blue did slightly.
And we have this product here, which is pretty cool and the one above, because we did it twice.
That's what we see is what we want to do.
This is reverse.
This is Donald Trump's face overlaid onto Hillary Clinton's, so you can have a lot of fun with this,
too.
In fact, you can use this probably function here in the video quite easily and get the output so you
can actually have a video of Donald Trump's face swapped with Hillary or Biden's Obama's.
Anybody you want anybody famous who's calling us politicians because everyone knows who they are, but
they can use anything you want.
So that concludes this very cool lesson on implementing fierce works with Dillard.
Hope you enjoyed it, and I hope you have fun with this because I certainly did.
I'll see you in the next lesson where we take a look at implementing something called a tilt shift effect
using open TV.
So it's a nice little project going to fancy going too long, that would, but it's cool up.
But so you'll take a look at that shortly.
Thank you.