-
Notifications
You must be signed in to change notification settings - Fork 2
/
apply_detector_to_imgs.m
94 lines (88 loc) · 3.13 KB
/
apply_detector_to_imgs.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function apply_detector_to_imgs(badacost_detector, imgs_path, imgs_ext, first_image_index, ...
min_score_shown, fast_detection, ...
save_results, save_path)
if (fast_detection)
save_path = [save_path '_Faster'];
% Much faster detections.
if iscell(badacost_detector)
for i=1:length(badacost_detector)
%badacost_detector{i}.opts.cascThr = badacost_detector{i}.opts.cascThr * 0.25;
badacost_detector{i}.opts.pPyramid.nApprox = 7;
badacost_detector{i}.opts.pPyramid.nPerOct = 8;
badacost_detector{i}.opts.pPyramid.nOctUp = 0; % Loose too small detections.
end
else
badacost_detector.opts.cascThr = badacost_detector.opts.cascThr * 0.1;
badacost_detector.opts.pPyramid.nApprox = 7;
badacost_detector.opts.pPyramid.nPerOct = 8;
badacost_detector.opts.pPyramid.nOctUp = 0; % Loose too small detections.
end
else
if iscell(badacost_detector)
for i=1:length(badacost_detector)
%badacost_detector{i}.opts.cascThr = badacost_detector{i}.opts.cascThr * 0.25;
badacost_detector{i}.opts.pPyramid.nApprox = 9;
badacost_detector{i}.opts.pPyramid.nPerOct = 10;
badacost_detector{i}.opts.pPyramid.nOctUp = 1; % Loose too small detections.
end
else
%badacost_detector.opts.cascThr = badacost_detector.opts.cascThr * 0.1;
badacost_detector.opts.pPyramid.nApprox = 9;
badacost_detector.opts.pPyramid.nPerOct = 10;
badacost_detector.opts.pPyramid.nOctUp = 1; % Loose too small detections.
end
end
if save_results
mkdir(save_path);
end
i = first_image_index;
h = figure;
while (true)
file_name = sprintf(['%05d.' imgs_ext], i);
% file_name = sprintf(['%04d.' imgs_ext], i);
file_path = fullfile(imgs_path, file_name);
disp(file_path)
% try
I = imread(file_path);
% --- Imges 640x480.
% 5.75 fps from 1X pyramid: BAdaCost
% 1.5 fps from 2X pyramid: BAdaCost
%
% 5.4 fps from 1X pyramid: K-Binary
% 1.5 fps from 2X pyramid: K-Binary
% I = imresize(I, [NaN 640]);
% Display badacost results.
showResOpts ={'evShow',0,'gtShow',0, 'dtShow',1, 'isMulticlass', 1, 'showScore', 1, 'dtLs', '-', 'cols', 'krg'};
if iscell(badacost_detector)
tic;
bbs = acfDetect(I, badacost_detector);
toc
else
tic;
[bbs, labels] = acfDetectBadacost(I, badacost_detector);
toc
end
if (save_results)
save(fullfile(save_path, sprintf('BADACOST_%05d.mat', i)), 'bbs');
end
bbs_nice = bbs(bbs(:,5)>=min_score_shown, :);
if ~iscell(badacost_detector)
if ~isempty(bbs_nice)
bbs_nice(:,6) = bbs_nice(:,6)-ones(size(bbs_nice, 1), 1);
end
end
imshow(I, 'Border', 'tight');
hs = bbGt('showRes', [], [], bbs_nice, showResOpts);
hold off;
drawnow;
set(gca, 'XLim', [1, size(I,2)]);
set(gca, 'YLim', [1, size(I,1)])
if (imgs_path)
saveas(gca, fullfile(save_path, file_name), imgs_ext);
end
% catch
% warning('Error ocurred. File does not exists?');
% break;
% end
i = i + 1;
end