If you ever wondered whether you can swap face in any video to any face you'd like then you are in the right place. Since today I will explain to you how to do that without any knowledge of programming.
Step 1: Gather Training Data.
You will need to acquire plenty of pictures with the face of the person you want to insert into your video and the person in the video. You can use Google, Bing image search, DuckDuckgo. FaceSwap reposatory has scripts to automatically download large amount of images from some sources.
Examples:
-python faceswap.py extract -i ~/faceswap/photo/ford -o ~/faceswap/data/ford
-python faceswap.py extract -I ~/faceswap/photo/cage -o ~/faceswap/data/cage
Some images may contain a lot of unnecessary elements. So you want your algorithm only to be able to recognize faces and later on swap them. For that you will use HOG.(Histogram of Oriented Gradients)
Step 2: Histogram of Oriented Gradients
It's basically a function call and the link to all prerequisites will be provided in the end of the post. But what happens in the background?
Well, first image is being simplified. Turned into black and white. You do not need colors to recognize faces. Then every pixel is replaced by an arrow pointing from lighter pixel to a darker one:
To make image easier to process we break the image into squares and count how many different directions there are, then replace each square with the direction which has the most counts. In the end we get something like that:
And we going for very simple representation that captures the basic structure of a face in simple way:
Once we have representation, we can compare it. And start to detect faces.
Step 3: Train your model to recognize faces
We can use Autoencoder - Convolutional neural network. This network has an ability to recognize sub-masks which we created in first 2 steps.
Step 4: Feed the video into the model you've trained.
All of the resource to do that can be found in this Git
More information/instructions/resources can be found in this video