-
Notifications
You must be signed in to change notification settings - Fork 5
/
detect_pedestrian.m
executable file
·65 lines (55 loc) · 2.12 KB
/
detect_pedestrian.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
function NMSwindows = detect_pedestrian(image_path,model_name,number_scales,overlap_pixels,scaling_factor,toSRS)
% 'detect_pedestrian' runs the main algorithm to detect a pedestrian in the image
%
% detect_pedestrian(image_path,model_name,number_scales,overlap_pixels,scaling_factor,toSRS)
% a) image_path gives the relative or absolute string location of the input image
% b) model_name is the name of the classifier model: mod2 if loaded from startup.m
% c) number_scales looks at the top 'n' scales. a value of 0 implies parsing all scales.
% d) overlap_pixels is the number of pixels between the current and the next window.
% e) scaling_factor indicates the amount of scaling done to the image. Best value is 0.8.
% f) toSRS is the option of computing the Single Response Suppression of each input image.
img = imread(image_path);
if length(size(img)) == 3 % if RGB
f = single(rgb2gray(img));
else % if grayscale
f = single(img);
end
windows = create_windows(f,overlap_pixels,scaling_factor);
if (number_scales > length(windows) || number_scales == 0)
number_scales = length(windows);
end
%%
results = cell(size(windows));
for index = 1:size(windows,1)
results{index,1} = -ones(size(windows{index}));
end
%%
count = 1;
for l = size(windows,1):-1:size(windows,1)-number_scales+1
for i = 1:size(windows{l},1)
for j = 1:size(windows{l},2)
im_temp = windows{l}(i,j).pixels;
% hog = vl_hog(im_temp,8,'variant','dalaltriggs');
% imhog = vl_hog('render',hog,'variant','dalaltriggs');
% featval = imhog(:)';
% feat(count,:) = featval;
imhog = extractHOGFeatures(im_temp);
feat(count,:) = imhog;
count = count+1;
end
end
end
res = predict(model_name,feat);
count = 1;
for l = size(windows,1):-1:size(windows,1)-number_scales+1
for i = 1:size(windows{l},1)
for j = 1:size(windows{l},2)
results{l}(i,j) = res(count);
count = count+1;
end
end
end
figure(1), plot_boxes(imread(image_path),windows,results);
NMSwindows = NMS(windows,results,toSRS);
figure(2),plot_boxes_NMS(imread(image_path),NMSwindows);
end