-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyour_dataset_setting.m
More file actions
55 lines (48 loc) · 2.09 KB
/
your_dataset_setting.m
File metadata and controls
55 lines (48 loc) · 2.09 KB
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
50
51
52
53
54
55
% This method was setting to work with MUG dataset. If you will use another dataset,
% please check if (face, eyes, eyebrows, and mouth)regions are being
% detected correctly using the code below.
%% Input Image
I = imread('face.jpg'); % read an image of your dataset
I = imresize(I, [224,224]);
imshow(I)
%% Face Detect
FDetect = vision.CascadeObjectDetector;
Face = step(FDetect,I);
imgFace = (I(Face(1,2):Face(1,2)+Face(1,4),Face(1,1):Face(1,1)+Face(1,3),:));
imshow(imgFace)
%% Left Eye Detect
EyeDetect = vision.CascadeObjectDetector('LeftEye');
Eye=step(EyeDetect,imgFace);
LeftEye = Eye(1,:);
imgLeftEye = (imgFace(LeftEye(1,2):LeftEye(1,2)+LeftEye(1,4),LeftEye(1,1):LeftEye(1,1)+LeftEye(1,3),:));
imshow(imgLeftEye)
%% Right Detect
EyeDetect = vision.CascadeObjectDetector('RightEye');
Eye=step(EyeDetect,imgFace);
RightEye = Eye(2,:);
imgRightEye = (imgFace(RightEye(1,2):RightEye(1,2)+RightEye(1,4),RightEye(1,1):RightEye(1,1)+RightEye(1,3),:));
imshow(imgRightEye)
%% Mouth Detect
MouthDetect = vision.CascadeObjectDetector('haarcascade/haarcascade_smile.xml');
findMouth=step(MouthDetect,imgFace);
orderMouth= sortrows(findMouth,2);
posMouth = size(findMouth,1);
Mouth = orderMouth(posMouth,:);
imgMouth = (imgFace(Mouth(1,2):Mouth(1,2)+Mouth(1,4),Mouth(1,1):Mouth(1,1)+Mouth(1,3),:));
imshow(imgMouth)
%% Left Eyebrow Detect
LeftEyebrow = LeftEye;
LeftEyebrow(4) = (LeftEyebrow(4)/2)-4;
LeftEyebrow(3) = LeftEyebrow(3);
LeftEyebrow(4) = uint8(LeftEyebrow(4));
LeftEyebrow(3) = uint8(LeftEyebrow(3));
imgLeftEyebrow = (imgFace(LeftEyebrow(1,2):LeftEyebrow(1,2)+LeftEyebrow(1,4),LeftEyebrow(1,1):LeftEyebrow(1,1)+LeftEyebrow(1,3),:));
imshow(imgLeftEyebrow)
%% Right Eyebrow Detect
RightEyebrow = RightEye;
RightEyebrow(4) = (RightEyebrow(4)/2);
RightEyebrow(3) = RightEyebrow(3);
RightEyebrow(4) = uint8(RightEyebrow(4));
RightEyebrow(3) = uint8(RightEyebrow(3));
imgRightEyebrow = (imgFace(RightEyebrow(1,2):RightEyebrow(1,2)+RightEyebrow(1,4),RightEyebrow(1,1):RightEyebrow(1,1)+RightEyebrow(1,3),:));
imshow(imgRightEyebrow)