-
Notifications
You must be signed in to change notification settings - Fork 1
/
mergeFourPoints.m
62 lines (56 loc) · 1.52 KB
/
mergeFourPoints.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
50
51
52
53
54
55
56
57
58
59
60
61
62
% mergeFourPoints merges multiple detection of same face
%
% dst = mergeFourPoints(src)
%
%Output parameter:
% dst: merged fourpoints data
%
%
%Input parameter:
% src: fourpoints data to be merged
%
%
%NOTE: This function is internally called in detectRotFaceParts
%
%Version: 20160607
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Face Parts Detection: %
% %
% Copyright (C) 2016 Masayuki Tanaka. All rights reserved. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dst = mergeFourPoints(src)
if( size(src,1) > 0 )
pos = zeros(size(src,1),2);
pos(:,1) = mean(src(:,[1,3,5,7]),2);
pos(:,2) = mean(src(:,[2,4,6,8]),2);
pos = horzcat(pos,[1:size(src,1)]');
dst = [];
while( ~isempty(pos) )
if( size(pos,1) == 1 )
dst = vertcat(dst,src(pos(1,3),:));
pos = [];
else
tmp = src(pos(1,3),:);
rad = norm(pos(1,1:2) - tmp(1,1:2)) + norm(pos(1,1:2) - tmp(1,3:4)) + norm(pos(1,1:2) - tmp(1,5:6)) + norm(pos(1,1:2) - tmp(1,7:8));
th = rad / 8;
p = 1;
for i=2:size(pos,1)
rad = norm(pos(1,1:2) - pos(i,1:2));
if( rad < th )
tmp = vertcat(tmp,src(pos(i,3),:));
p = horzcat(p,i);
end
end
if( size(tmp,1) > 1 )
num = tmp > 0;
tmp = sum(tmp) ./ sum(num);
end
dst = vertcat(dst,tmp);
pos(p,:) = [];
end
end
else
dst = src;
end