Skip to content

MATLAB Tutorial

Yuval Nirkin edited this page Oct 13, 2016 · 7 revisions

Quick start

The simplest way to use the function is by feeding it the path of the model file and a path to a video file to process:

modelFile = 'path/to/shape_predictor_68_face_landmarks.dat';
frames = find_face_landmarks(modelFile, 'video.mp4');
show_face_landmarks('video.mp4', frames);

For processing images, the following options can be used:

Single image:

frames = find_face_landmarks(modelFile, 'img.jpg');

Regular expression. For example all jpg images:

frames = find_face_landmarks(modelFile, '.*jpg');

All images in a directory:

frames = find_face_landmarks(modelFile, 'dataset_dir');

It is also possible to process directly from a live camera stream. For a camera with device id 0:

frames = find_face_landmarks(modelFile, 0);

Saving and Loading

Finding face landmarks can be a slow process on high resolution sequences. Also for finding small faces it is required to process the sequences in different scales. In the following example, a video file will be processed in the original scale and in a multiple of 2, the landmarks from the scale where more faces were found will be saved to file in the original sequence resolution, the landmarks will then be read and displayed:

modelFile = 'path/to/shape_predictor_68_face_landmarks.dat';
sfl_cache('video.mp4', modelFile, 'scales', 1:2);
frames = find_face_landmarks('video.mp4');
show_face_landmarks('video.mp4', frames);
Clone this wiki locally