-
Notifications
You must be signed in to change notification settings - Fork 51
/
facepp_demo.m
52 lines (42 loc) · 1.53 KB
/
facepp_demo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%
% Face++ Matlab SDK demo
%
clc; clear;
% Load an image, input your API_KEY & API_SECRET
img = 'demo.jpg';
API_KEY = 'd45344602f6ffd77baeab05b99fb7730';
API_SECRET = 'jKb9XJ_GQ5cKs0QOk6Cj1HordHFBWrgL';
% If you have chosen Amazon as your API sever and
% changed API_KEY&API_SECRET into yours,
% pls reform the FACEPP call as following :
% api = facepp(API_KEY, API_SECRET, 'US')
api = facepp(API_KEY, API_SECRET);
% Detect faces in the image, obtain related information (faces, img_id, img_height,
% img_width, session_id, url, attributes)
rst = detect_file(api, img, 'all');
img_width = rst{1}.img_width;
img_height = rst{1}.img_height;
face = rst{1}.face;
fprintf('Totally %d faces detected!\n', length(face));
im = imread(img);
imshow(im);
hold on;
for i = 1 : length(face)
% Draw face rectangle on the image
face_i = face{i};
center = face_i.position.center;
w = face_i.position.width / 100 * img_width;
h = face_i.position.height / 100 * img_height;
rectangle('Position', ...
[center.x * img_width / 100 - w/2, center.y * img_height / 100 - h/2, w, h], ...
'Curvature', 0.4, 'LineWidth',2, 'EdgeColor', 'blue');
% Detect facial key points
rst2 = api.landmark(face_i.face_id, '83p');
landmark_points = rst2{1}.result{1}.landmark;
landmark_names = fieldnames(landmark_points);
% Draw facial key points
for j = 1 : length(landmark_names)
pt = getfield(landmark_points, landmark_names{j});
scatter(pt.x * img_width / 100, pt.y * img_height / 100, 'g.');
end
end