How to do it...

Let's see how we can build a face recognizer using a local binary patterns histogram:

  1. Create a new Python file and import the following packages (the full code is given in the face_recognizer.py file that is provided for you):
import os 
 
import cv2 
import numpy as np 
from sklearn import preprocessing  
  1. Let's define a class to handle all of the tasks that are related to label encoding for the classes:
# Class to handle tasks related to label encoding 
class LabelEncoder(object): 
  1. Define a method to encode the labels. In the input training data, labels are represented by words. However, we need numbers to train our system. This method will define a preprocessor object that can convert words into numbers in an organized fashion ...

Get Python Machine Learning Cookbook - Second 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.