Repository navigation
Expand file tree
/
Copy pathscript.m
More file actions
55 lines (42 loc) · 1.49 KB
/
Copy pathscript.m
File metadata and controls
55 lines (42 loc) · 1.49 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
% load a training example image
Itrain = im2double(rgb2gray(imread('test2.jpg')));
%have the user click on some training examples.
% If there is more than 1 example in the training image (e.g. faces), you could set nclicks higher here and average together
nclick = 1;
figure(1); clf;
imshow(Itrain);
[x,y] = ginput(nclick); %get nclicks from the user
%compute 8x8 block in which the user clicked
blockx = round(x/8);
blocky = round(y/8);
%visualize image patches that the user clicked on
figure(2); clf;
for i = 1:nclick
patch = Itrain( 8*blocky(i) + (-63:64), 8*blockx(i)+(-63:64));
figure(2); subplot(3,2,i); imshow(patch);
end
% compute the hog features
f = hog(Itrain);
% compute the average template for the user clicks
template = zeros(16,16,9);
for i = 1:nclick
template = template + f(blocky(i)+(-7:8),blockx(i)+(-7:8),:);
end
template = template/nclick;
%
% load a test image
%
Itest= im2double(rgb2gray(imread('test1.jpg')));
% find top 5 detections in Itest
ndet = 2;
[x,y,score] = detect(Itest,template,ndet);
%display top ndet detections
figure(3); clf; imshow(Itest);
for i = 1:ndet
% draw a rectangle. use color to encode confidence of detection
% top scoring are green, fading to red
hold on;
% h = rectangle('Position',[x(i)-64 y(i)-64 128 128],'EdgeColor',[(i/ndet) ((ndet-i)/ndet) 0],'LineWidth',3,'Curvature',[0.3 0.3]);
h = rectangle('Position',[x(i)-64 y(i) 128 128],'EdgeColor',[(i/ndet) ((ndet-i)/ndet) 0],'LineWidth',3,'Curvature',[0.3 0.3]);
hold off;
end