-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFaceFinderMatlab.m
More file actions
33 lines (27 loc) · 792 Bytes
/
Copy pathFaceFinderMatlab.m
File metadata and controls
33 lines (27 loc) · 792 Bytes
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
clear all; clear clc; close all;
facesPath = '/Users/rlaubscher/Dropbox/BFH/CPVR2-3-CP/Exercises/Images/cpvr_classes/2016HS/_DSC0380.JPG';
I = imread(facesPath);
faceDetector = vision.CascadeObjectDetector;
bboxes = step(faceDetector, I);
numRows = size(bboxes, 1);
means = [];
k = 0;
for i=1:1:numRows
% [x, y, width, height]
bbox = bboxes(i,:);
if bbox(3) < 100
continue;
end;
bbox(2) = bbox(2) - 50;
bbox(4) = bbox(4) + 50;
subImage = imcrop(I, bbox);
hsvI = rgb2hsv(subImage);
h = hsvI(:,:,1);
if mean2(h) > 0.3
continue;
end;
k = k + 1;
imwrite(subImage, sprintf('./images/search/%d.png', k));
end;
IFaces = insertObjectAnnotation(I, 'rectangle', bboxes, 'Face');
figure, imshow(IFaces), title('Detected faces');