-
Notifications
You must be signed in to change notification settings - Fork 44
MATLAB Tutorial
First make sure to download the landmarks model file: shape_predictor_68_face_landmarks.dat.
The simplest way to use the function is by feeding it the path of the model file and an image to process:
modelFile = 'path/to/shape_predictor_68_face_landmarks.dat';
I = imread('dataset_dir/img_01.jpg');
frame = find_face_landmarks(modelFile, I);
For video files:
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');
Multiple images (img_00.jpg, img_01.jpg, img_02.jpg, ...):
frames = find_face_landmarks(modelFile, 'dataset_dir/img_%02d.jpg');
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);
To initialize landmarks model file to save time for future calls:
find_face_landmarks(modelFile);
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);