-
Notifications
You must be signed in to change notification settings - Fork 15
/
detect.m
78 lines (73 loc) · 1.82 KB
/
detect.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function Y = detect(windowsize, X, detector, progress, scale, factor)
% function Y = detect(X,detector)
% This function detects objects into images.
% Parameters:
% - windowsize: the size of the window used to learn the classifiers
% - X: The image to process
% - detector: The trained cascade of classifier
if nargin < 4
progress = 0;
end
if nargin < 6
factor = 1;
end
minscale = 1;
imwidth = size(X,2);
imheight = size(X,1);
maxscale = floor(min(imwidth,imheight)/windowsize);
scalesteps = (maxscale-minscale)/20;
initial_curstep = 4;
detected = [];
det_cnt = 0;
Xsrc = X;
if nargin >= 5
minscale = scale;
maxscale = scale;
end
if size(X,3) == 3
X = double(rgb2gray(X));
else
X = double(X);
end
if progress
fprintf('|');
for i=minscale:scalesteps:maxscale
fprintf('-');
end
fprintf('|\n|');
end
cnt=0;
for scale = minscale:scalesteps:maxscale
if progress
fprintf('.');
end
cursize = round(windowsize * scale);
cursteps = round(initial_curstep * scale);
curimg = zeros(cursize+1);
for cury=1:cursteps:imheight-cursize+1
for curx=1:cursteps:imwidth-cursize+1
cursrc = X(cury:cury+cursize-1,curx:curx+cursize-1);
cursrc = normalize_img(cursrc);
curimg = ii(cursrc);
cnt = cnt+1;
if(classifyimg(windowsize,curimg,detector,factor))
det_cnt = det_cnt + 1;
detected(det_cnt,:) = [curx cury cursize];
end
end
end
end
fprintf('|\nmarking detected objects...\n');
Y = Xsrc;
for i=1:size(detected,1)
det = detected(i,:);
top = det(2);
left = det(1);
bottom = top + det(3) - 1;
right = left + det(3) - 1;
Y(top, left:right) = 255;
Y(bottom, left:right) = 255;
Y(top:bottom, left) = 255;
Y(top:bottom, right) = 255;
end
end