In this tutorial, you'll learn how to display anthropometric points and head rotation angles after a person's face has been found on a video or image. This tutorial is based on the tutorial Face Detection and Tracking in a Video Stream and the corresponding project.
- Create the project, in which 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 function
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, which is called
esr (47 points) (see Anthropometric Points). To do this, you'll need to specify the configuration file
video_worker.xml instead of
video_worker_lbf.xml in the constructor
ViewWindow.cpp) (see Face Detection and Tracking in a Video Stream).
- Visualize the points – they'll 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 headers
QQuaternion. Using the
QQuaternion::fromEulerAnglesmethod, get the rotation matrix.
Note: In Face SDK, yaw (rotation along the Z axis), pitch (rotation along the Y axis), and roll (rotation along the X axis) rotation angles are used. 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 vise versa), we have to invert the direction of the Y axis (multiply it by -1) for correct visualization of angles.
- To visualize the angles, we have to calculate the midpoint between the eyes of a person
axis_origin, which will be the origin point for the vectors yaw, pitch, roll.
- To make sure that the length of the yaw, pitch, roll vectors is proportional to the face size, we introduce the
axis_lengthcoefficient. It's 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 image plane
QPointFmultiplied by the
axis_lengthcoefficient and plotted from the starting point.
- Run the project. You'll see the anthropometric points and head rotation angles.