How to do it...

The OpenCV library proposes a number of face recognition methods implemented as a subclass of the generic cv::face::FaceRecognizer class. In this recipe, we will examine the cv::face::LBPHFaceRecognizer class, which is interesting to us because it is based on a simple, but often very effective, classification approach, that is, the nearest neighbor classifier.

Moreover, the image representation it uses is built from the LBP feature, which is a very popular way of describing image patterns. Let's take a look at the following steps:

  1. In order to create an instance of the cv::face::LBPHFaceRecognizer class, its static create method is called as follows:
cv::Ptr<cv::face::FaceRecognizer> recognizer = cv::face::LBPHFaceRecognizer::create(1, ...

Get OpenCV 4 Computer Vision Application Programming Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.