Giter Site home page Giter Site logo

face-replace's Introduction

Face Replacement Filter in Video

This is a proof-of-concept Python script inspired by MSQRD and Snapchat 3D Face Placement filters.

To play with the script you should have a still image with sample face and video file with someone's else face in it (or you can use your web camera with your own face;) ).

You can find sample still image and video in the "demo" directory.

Basic Idea

  1. Detected where is a face in the still image
  2. Extract face features' landmarks (like eyes, nose and mouth coordinates)
  3. Detect a face in the video frame and extract its landmarks too
  4. Align landmarks coordinates from steps 2 and 3
  5. Use results of affine transform to warp still-image face around video frame's face

Final result could be saved to the video file or just shown on the screen.

Example

Original video, no face replaced:

Final video, Arni's face is in place of mine:

Technical Notes

  • All image processing is done on the greyscale frames. If input video is in color, it will be converted to greyscale.
  • Web cam and Video in-out were tested on OS X thus video saved with QuickTime codec.
  • To make processing faster all input frames are down-sampled to the size 420x240 px.

Requirements

This script was tested in the following environment:

How To

Before you begin, download and extract Dlib face shape predictor ('shape_predictor_68_face_landmarks.dat'). Put it to ./models/shape_predictor_68_face_landmarks.dat

Usage:

python ./change-face-in-video.py [-h] STILLFACE VIDEOIN VIDEOOUT

where arguments are:

  STILLFACE   the full path to jpg file with face
  VIDEOIN     the full path to input video file where face will be changed. If
              "0" is provided then the web cam will be used
  VIDEOOUT    the full path to output video file with the new face. If "0" is
              provided then process video will be shown on the screen, but not
              saved.

For example this command will created a new video demo_arni.mov with face replacement from image arni.jpg:

python ./change-face-in-video.py ./demo/arni.jpg ./demo/demo_orig.mov ./demo/demo_arni.mov

This command will use image arni.jpg again, but for the video stream from web camera:

python ./change-face-in-video.py ./demo/arni.jpg 0 ./demo/demo_arni.mov

Credits

One Millisecond Face Alignment with an Ensemble of Regression Trees by Vahid Kazemi and Josephine Sullivan, CVPR 2014


Alexander Usoltsev, 2016

face-replace's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.