train (cv.LBPHFaceRecognizer) - MATLAB File Help
cv.LBPHFaceRecognizer/train

Trains a FaceRecognizer with given data and associated labels

obj.train(src, labels)

Input

The following source code snippet shows you how to learn a Fisherfaces model on a given set of images. The images are read with cv.imread and pushed into a cell array. The labels of each image are stored within an integer vector. Think of the label as the subject (the person) this image belongs to, so same subjects (persons) should have the same label. For the available FaceRecognizer you don't have to pay any attention to the order of the labels, just make sure same persons have the same label:

% holds images and labels
images = {};
labels = [];
% images for first person
images{end+1} = cv.imread('person0/0.jpg', 'Grayscale',true);
labels{end+1} = 0;
images{end+1} = cv.imread('person0/1.jpg', 'Grayscale',true);
labels{end+1} = 0;
images{end+1} = cv.imread('person0/2.jpg', 'Grayscale',true);
labels{end+1} = 0;
% images for second person
images{end+1} = cv.imread('person1/0.jpg', 'Grayscale',true);
labels{end+1} = 1;
images{end+1} = cv.imread('person1/1.jpg', 'Grayscale',true);
labels{end+1} = 1;
images{end+1} = cv.imread('person1/2.jpg', 'Grayscale',true);
labels{end+1} = 1;

Now that you have read some images, we can create a new FaceRecognizer. In this example I'll create a Fisherfaces model and decide to keep all of the possible Fisherfaces:

% Create a new Fisherfaces model and retain all available
% Fisherfaces, this is the most common usage of this specific
% FaceRecognizer:
model = cv.BasicFaceRecognizer('Fisherfaces');

And finally train it on the given dataset (the face images and labels):

% This is the common interface to train all of the available FaceRecognizer
% implementations:
model.train(images, labels);
See also
Method Details
Access public
Sealed false
Static false