#### Overview of this book

Mastering OpenCV, now in its third edition, targets computer vision engineers taking their first steps toward mastering OpenCV. Keeping the mathematical formulations to a solid but bare minimum, the book delivers complete projects from ideation to running code, targeting current hot topics in computer vision such as face recognition, landmark detection and pose estimation, and number recognition with deep convolutional networks. You’ll learn from experienced OpenCV experts how to implement computer vision products and projects both in academia and industry in a comfortable package. You’ll get acquainted with API functionality and gain insights into design choices in a complete computer vision project. You’ll also go beyond the basics of computer vision to implement solutions for complex image processing projects. By the end of the book, you will have created various working prototypes with the help of projects in the book and be well versed with the new features of OpenCV4.
Preface
Free Chapter
Cartoonifier and Skin Color Analysis on the RaspberryPi
Explore Structure from Motion with the SfM Module
Face Landmark and Pose with the Face Module
Number Plate Recognition with Deep Convolutional Networks
Face Detection and Recognition with the DNN Module
Introduction to Web Computer Vision with OpenCV.js
Android Camera Calibration and AR Using the ArUco Module
iOS Panoramas with the Stitching Module
Finding the Best OpenCV Algorithm for the Job
Avoiding Common Pitfalls in OpenCV
Other Books You May Enjoy

# Estimating face direction from landmarks

Having obtained the facial landmarks, we can attempt to find the direction of the face. The 2D face landmark points essentially conform to the shape of the head. So, given a 3D model of a generic human head, we can find approximate corresponding 3D points for a number of facial landmarks, as shown in the following photo:

# Estimated pose calculation

From these 2D–3D correspondences, we can calculate 3D pose (rotation and translation) of the head, with respect to the camera, by way of the Point-n-Perspective (PnP) algorithm. The details of the algorithm and object pose detection are beyond the scope of this chapter; however, we can quickly rationalize why just a handful of 2D&...