You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yinguobing 981cac645e update mark model with new weights 2 years ago
assets update mark model with new weights 2 years ago
doc add wechat info 4 years ago
.gitignore Initial commit 6 years ago
LICENSE Initial commit 6 years ago update reademe 2 years ago hide the face box 2 years ago update model file 2 years ago use optical flow tracker to update kalman filter parameters 5 years ago fixed typo 3 years ago add function to draw axes 4 years ago fixed typo 3 years ago

Head pose estimation

Real time human head pose estimation using TensorFlow and OpenCV.

demo demo

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.


TensorFlow OpenCV Numpy

The code was tested on Ubuntu 20.04.


This repository already provided a pre-trained model for facial landmarks detection. Just git clone then you are good to go.

# From your favorite development directory:
git clone


A video file or a webcam index should be assigned through arguments. If no source provided, the built in webcam will be used by default.

With video file

For any video format that OpenCV supports (mp4, avi etc.):

python3 --video /path/to/video.mp4

With webcam

The webcam index should be provided:

python3 --cam 0

How it works

There are three major steps:

  1. Face detection. A face detector is introduced to provide a face bounding box containing a human face. Then the face box is expanded and transformed to a square to suit the needs of later steps.

  2. Facial landmark detection. A pre-trained deep learning model take the face image as input and output 68 facial landmarks.

  3. Pose estimation. After getting 68 facial landmarks, the pose could be calculated by a mutual PnP algorithm.

The marks are detected frame by frame that makes the pose unstable. A Kalman filter is used to solve this problem, you can draw the original pose to observe the difference.

Retrain the model

To retrain the facial landmark detection model please refer to this series of posts (in Chinese only). The training code is also open sourced:


This project is licensed under the MIT License - see the file for details


Yin Guobing (尹国冰) - yinguobing


The pre-trained TensorFlow model file is trained with various public data sets which have their own licenses. Please refer to them before using this code.

The 3D model of face comes from OpenFace, you can find the original file here.

The build in face detector comes from OpenCV.