In this tutorial you'll learn how to display anthropometric points and head rotation angles after a person's face is found on a video or image. This tutorial is based on the Face Detection and Tracking in a Video Stream tutorial and the corresponding project.
- Create the project, where faces will be detected and tracked using the
VideoWorkerobject. Faces in this project are highlighted with a green rectangle (see Face Detection and Tracking in a Video Stream).
- Modify the
pbio::RawSampleobject contains all the information about a tracked face, namely: face bounding rectangle, anthropometric points, position of eyes, angles, etc. Using the
pbio::RawSample::getLandmarksmethod, get anthropometric points of a tracked face.
Note: In this project we use the
singlelbf set of anthropometric points (31 points). As an option, you can use a different set of points, called
esr (47 points) (see Anthropometric Points). To do this, specify the
video_worker.xml configuration file instead of
video_worker_lbf.xml in the
ViewWindow::ViewWindow constructor (
ViewWindow.cpp) (see Face Detection and Tracking in a Video Stream).
- Visualize the points – the points will be displayed on the face as little red circles.
- Run the project. You'll see anthropometric points on your face.
- The information about head rotation angles is also obtained from
- Include the
QQuaternionheaders. Using the
QQuaternion::fromEulerAnglesmethod, get the rotation matrix.
Note: Face SDK uses yaw (rotation along the Z axis), pitch (rotation along the Y axis), and roll (rotation along the X axis) rotation angles. Face SDK algorithm allows to detect faces in the following range of angles: yaw [-60; 60], pitch [-60; 60], roll [-30; 30].
- Since the image received from the camera and displayed on the screen is a mirror image of a user (the right part of the face is displayed on the left side of the image, and vice versa), invert the direction of the Y axis (multiply it by -1) for correct visualization of angles.
- To visualize the angles, calculate the midpoint between a person's eyes
axis_origin, which will be the origin point for the yaw, pitch, roll vectors.
- To make sure that the length of the yaw, pitch, roll vectors is proportional to the face size, introduce the
axis_lengthcoefficient. It is half of the diagonal of the face bounding rectangle
- Visualize the angles – vectors will be displayed in different colors (yellow, red, and green).
- Draw the vectors in the loop. The starting point for vectors is the point between the person's eyes. The endpoint for vectors equals to the projection of the vector on the
QPointFimage plane multiplied by the
axis_lengthcoefficient and plotted from the starting point.
- Run the project. You'll see the anthropometric points and head rotation angles.