This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
procedure.m~
54 lines (41 loc) · 1.27 KB
/
procedure.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
template = im2bw(imresize(imread('template.jpg'), 0.1), 0.6);
% sample = rgb2gray(imresize(imread('p_ul.jpg'), 0.1));
% sample = rgb2gray(imresize(imread('p_ur.jpg'), 0.1));
% sample = rgb2gray(imresize(imread('p_ll.jpg'), 0.1));
% sample = rgb2gray(imresize(imread('p_lr.jpg'), 0.1));
sample = rgb2gray(imresize(imread('p_c.jpg'), 0.1));
c = normxcorr2(template,sample);
figure, surf(c), shading flat
[ypeak, xpeak] = find(c==max(c(:)));
yoffSet = ypeak-size(template,1);
xoffSet = xpeak-size(template,2);
xPos = xoffSet + 0.5*size(template,2);
yPos = yoffSet + 0.5*size(template,1);
hAx = axes;
imshow(sample,'Parent', hAx);
imrect(hAx, [xoffSet, yoffSet, size(template,2), size(template,1)]);
imrect(hAx, [xPos, yPos, 10, 10]);
imrect(hAx, [5, 5, 10, 10]);
imellipse(
r = 0.25*(size(template, 2) + size(template, 1))/2;
disp('xPos');
disp(xPos);
disp('yPos');
disp(yPos);
disp('size(template, 1)/2');
disp(size(template, 1)/2);
if (xPos - 0.5*size(template, 2))^2 + (yPos - 0.5*size(template, 1))^2 < r^2
disp('center');
else
if (0 < yPos) & (yPos < (size(template, 1)/2))
disp('upper');
end
if size(template, 1)/2 <= yPos
disp('lower');
end
if 0 < xPos & xPos < size(template, 2)/2
disp('left');
else
disp('right');
end
end