cv.Facemark - MATLAB File Help | Go to online doc for cv.Facemark |
Base class for all facemark models
Facial landmark detection is a useful algorithm with many possible applications including expression transfer, virtual make-up, and facial puppetry. This class implements an API for facial landmark detector. Two kinds of algorithms are implemented including active appearance model [AAM] and regressed local binary features [LBF] able to work in real-time.
All facemark models in OpenCV are derived from the abstract base class Facemark, which provides a unified access to all facemark algorithms in OpenCV.
To utilize the Facemark API in your program, please take a look at the opencv tutorials, as well as mexopencv samples.
Facemark is a base class which provides universal access to any specific facemark algorithm. Therefore, the users should declare a desired algorithm before they can use it in their application.
The typical pipeline for facemark detection is listed as follows:
Here is an example of loading a pretrained model (you should provide full paths to files specified below):
obj = cv.Facemark('LBF', 'CascadeFace','lbpcascade_frontalface.xml');
obj.loadModel('lbfmodel.yaml');
img = imread('lena.jpg');
faces = obj.getFaces(img);
landmarks = obj.fit(img, faces);
for i=1:numel(faces)
img = cv.rectangle(img, faces{i}, 'Color','g');
img = cv.Facemark.drawFacemarks(img, landmarks{i});
end
imshow(img)
Here is an example of training a model:
% filename to save the trained model
obj = cv.Facemark('LBF', 'ModelFilename','ibug68.model');
obj.setFaceDetector('myFaceDetector');
% load the list of dataset: image paths and landmark file paths
[imgFiles, ptsFiles] = cv.Facemark.loadDatasetList(...
'data/images_train.txt', 'data/points_train.txt');
% add training samples
for i=1:numel(imgFiles)
img = imread(imgFiles{i});
pts = cv.Facemark.loadFacePoints(ptsFiles{i});
obj.addTrainingSample(img, pts);
end
obj.training();
[AAM]:
G. Tzimiropoulos and M. Pantic, "Optimization problems for fast AAM fitting in-the-wild," ICCV 2013.
[LBF]:
S. Ren, et al. , "Face alignment at 3000 fps via regressing local binary features", CVPR 2014.
Superclasses | handle |
Sealed | false |
Construct on load | false |
Facemark | Constructor |
func | name of custom face detector function |
id | Object ID |
addTrainingSample | Add one training sample to the trainer | |
addlistener | Add listener for event. | |
delete | Destructor | |
Static | drawFacemarks | Utility to draw the detected facial landmark points |
eq | == (EQ) Test handle equality. | |
findobj | Find objects matching specified conditions. | |
findprop | Find property of MATLAB handle object. | |
fit | Detect landmarks in faces | |
ge | >= (GE) Greater than or equal relation for handles. | |
getData | Get data from an algorithm | |
getFaces | Detect faces from a given image using default or user-defined face detector | |
Static | getFacesHAAR | Default face detector |
gt | > (GT) Greater than relation for handles. | |
Sealed | isvalid | Test handle validity. |
le | <= (LE) Less than or equal relation for handles. | |
listener | Add listener for event without binding the listener to the source object. | |
Static | loadDatasetList | A utility to load list of paths to training images and annotation files |
Static | loadFacePoints | A utility to load facial landmark information from a given file |
loadModel | A function to load the trained model before the fitting process | |
Static | loadTrainingData1 | A utility to load facial landmark information from the dataset |
Static | loadTrainingData2 | A utility to load facial landmark dataset from a single file |
Static | loadTrainingData3 | Extracts the data for training from .txt files which contains the corresponding image name and landmarks |
lt | < (LT) Less than relation for handles. | |
ne | ~= (NE) Not equal relation for handles. | |
notify | Notify listeners of event. | |
setFaceDetector | Set a user-defined face detector for the Facemark algorithm | |
training | Trains a Facemark algorithm using the given dataset |
ObjectBeingDestroyed | Notifies listeners that a particular object has been destroyed. |