Need help with face-replace?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

137 Stars 43 Forks 6 Commits 0 Opened issues


Snapchat -like replace face in the video by a face mask

Services available


Need anything else?

Contributors list

# 154,533
1 commit

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.


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.


This script was tested in the following environment:

How To

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



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

For example this command will created a new video
with face replacement from image

python ./ ./demo/arni.jpg ./demo/ ./demo/

This command will use image

again, but for the video stream from web camera:

python ./ ./demo/arni.jpg 0 ./demo/


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

Alexander Usoltsev, 2016

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.