All Projects → MarekKowalski → Faceswap

MarekKowalski / Faceswap

Licence: mit
3D face swapping implemented in Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Faceswap

Tf flame
Tensorflow framework for the FLAME 3D head model. The code demonstrates how to sample 3D heads from the model, fit the model to 2D or 3D keypoints, and how to generate textured head meshes from Images.
Stars: ✭ 193 (-62.01%)
Mutual labels:  3d-models, face-alignment
Flyover Reverse Engineering
Reversing Apple's 3D satellite mode
Stars: ✭ 485 (-4.53%)
Mutual labels:  3d-models
Ensmallen
A header-only C++ library for numerical optimization --
Stars: ✭ 436 (-14.17%)
Mutual labels:  optimization
Tree Gen
Procedural generation of tree models in blender
Stars: ✭ 465 (-8.46%)
Mutual labels:  3d-models
Teaching
Teaching Materials for Dr. Waleed A. Yousef
Stars: ✭ 435 (-14.37%)
Mutual labels:  optimization
Etlegacy Deprecated
Archived repository. For current repo, see: https://github.com/etlegacy/etlegacy
Stars: ✭ 470 (-7.48%)
Mutual labels:  3d-models
O Cnn
O-CNN: Octree-based Convolutional Neural Networks for 3D Shape Analysis
Stars: ✭ 432 (-14.96%)
Mutual labels:  3d-models
Ringnet
Learning to Regress 3D Face Shape and Expression from an Image without 3D Supervision
Stars: ✭ 504 (-0.79%)
Mutual labels:  3d-models
Awesome Robotics
A curated list of awesome links and software libraries that are useful for robots.
Stars: ✭ 478 (-5.91%)
Mutual labels:  optimization
Face Pose Net
Estimate 3D face pose (6DoF) or 11 parameters of 3x4 projection matrix by a Convolutional Neural Network
Stars: ✭ 464 (-8.66%)
Mutual labels:  face-alignment
Winapp2
A database of extended cleaning routines for popular Windows PC based maintenance software.
Stars: ✭ 463 (-8.86%)
Mutual labels:  optimization
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (-12.4%)
Mutual labels:  3d-models
Llvm
Project moved to: https://github.com/llvm/llvm-project
Stars: ✭ 4,461 (+778.15%)
Mutual labels:  optimization
Geneticalgorithmpython
Source code of PyGAD, a Python 3 library for building the genetic algorithm and training machine learning algorithms (Keras & PyTorch).
Stars: ✭ 435 (-14.37%)
Mutual labels:  optimization
Autokernel
AutoKernel 是一个简单易用,低门槛的自动算子优化工具,提高深度学习算法部署效率。
Stars: ✭ 485 (-4.53%)
Mutual labels:  optimization
Openastrotracker
3D printed DSLR tracking mount
Stars: ✭ 434 (-14.57%)
Mutual labels:  3d-models
Qpth
A fast and differentiable QP solver for PyTorch.
Stars: ✭ 461 (-9.25%)
Mutual labels:  optimization
Webpack Closure Compiler
[DEPRECATED] Google Closure Compiler plugin for Webpack
Stars: ✭ 467 (-8.07%)
Mutual labels:  optimization
Imagemin
[Unmaintained] Minify images seamlessly
Stars: ✭ 4,948 (+874.02%)
Mutual labels:  optimization
Lepto
Automated image Editing, Optimization and Analysis via CLI and a web interface. You give to lepto your input and output directories, the plugins you want to use and their options. Then lepto does his job, you keep your original files and the structure of the input directory. Some plugins can even collect data (like primary colors) from your images and save them in a JSON file.
Stars: ✭ 490 (-3.54%)
Mutual labels:  optimization

FaceSwap

FaceSwap is an app that I have originally created as an exercise for my students in "Mathematics in Multimedia" on the Warsaw University of Technology. The app is written in Python and uses face alignment, Gauss Newton optimization and image blending to swap the face of a person seen by the camera with a face of a person in a provided image.

You will find a short presentation the program's capabilities in the video below (click to go to YouTube): click to go to YouTube

How to use it

To start the program you will have to run a file named zad2.py (Polish for exercise 2), which will require:

  • Python 2.7 (I recommend Anaconda)
  • OpenCV (I used 2.4.13)
  • Numpy
  • dlib
  • pygame
  • PyOpenGL

You can download all of the libraries above either from PIP or from Christoph Gohlke's excellent website: http://www.lfd.uci.edu/~gohlke/pythonlibs/

You will also have to download the face alignment model from here: http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2 and unpack it to the main project directory.

A faster and more stable version

A faster and more stable version of FaceSwap is available on Dropbox here. This new version is based on the Deep Alignment Network method, which is faster than the currently used method if ran on a GPU and provides more stable and more precise facial landmarks. Please see the GitHub repository of Deep Alignment Network for setup instructions.

I hope to find time to include this faster version in the repo code soon.

How it works

The general outline of the method is as follows:

First we take the input image (the image of a person we want to see on our own face) and find the face region and its landmarks. Once we have that we fit the 3D model to those landmarks (more on that later) the vertices of that model projected to the image space will be our texture coordinates.

Once that is finished and everything is initialized the camera starts capturing images. For each captured images the following steps are taken:

  1. The face region is detected and the facial landmarks are located.
  2. The 3D models is fitted to the located landmarks.
  3. The 3D models is rendered using pygame with the texture obtained during initialization.
  4. The image of the rendered model is blended with the image obtained from the camera using feathering (alpha blending) and very simple color correction.
  5. The final image is shown to the user.

The most crucial element of the entire process is the fitting of the 3D model. The model itself consists of:

  • the 3D shape (set of vertices) of a neutral face,
  • a number of blendshapes that can be added to the neutral face to produce mouth opening, eyebrow raising, etc.,
  • a set of triplets of indices into the face shape that form the triangular mesh of the face,
  • two sets of indices which establish correspondence between the landmarks found by the landmark localizer and the vertices of the 3D face shape.

The model is projected into the image space using the following equation:

equation

where s is the projected shape, a is the scaling parameter, P are the first two rows of a rotation matrix that rotates the 3D face shape, S_0 is the neutral face shape, w_1-n are the blendshape weights, S_1-n are the blendshapes, t is a 2D translation vector and n is the number of blendshapes.

The model fitting is accomplished by minimizing the difference between the projected shape and the localized landmarks. The minimization is accomplished with respect to the blendshape weights, scaling, rotation and translation, using the Gauss Newton method.

Licensing

The code is licensed under the MIT license, some of the data in the project is downloaded from 3rd party websites:

Contact

If need help or you found the app useful, do not hesitate to let me know.

Marek Kowalski [email protected], homepage: http://home.elka.pw.edu.pl/~mkowals6/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].