-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_backup2.m
79 lines (65 loc) · 2.43 KB
/
detect_backup2.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
function [boxes] = detect(input, model, thresh)
% boxes = detect(input, model, thresh)
% Detect objects in input using a model and a score threshold.
% Higher threshold leads to fewer detections.
%
% The function returns a matrix with one row per detected object. The
% last column of each row gives the score of the detection. The
% column before last specifies the component used for the detection.
% The first 4 columns specify the bounding box for the root filter and
% subsequent columns specify the bounding boxes of each part.
%
% If bbox is not empty, we pick best detection with significant overlap.
% If label and fid are included, we write feature vectors to a data file.
% NOTE: You'll need to implement the inference for the part filters in this
% file
% we assume color images
input = color(input);
% the feature pyramid
[feat, pyramidScales] = featpyramid(input, model.sbin, model.interval);
% score
[scores padx pady] = computeScores(feat, model, true);
% find all good bounding boxes
boxes = [];
for componentIdx=1:model.numcomponents
for pyramidLevelIdx=1:length(pyramidScales)
% get all good matches
scale = pyramidScales(pyramidLevelIdx);
rsize = model.rootfilters{model.components{componentIdx}.rootindex}.size;
score = scores{componentIdx}{pyramidLevelIdx};
I = find(score > thresh);
[Y, X] = ind2sub(size(score), I);
boxesEntry = zeros(length(I), 6);
for i = 1:length(I)
x = X(i);
y = Y(i);
b = getBoundingBox(x, y, scale, padx, pady, rsize);
boxesEntry(i,:) = [b componentIdx score(I(i))];
end
boxes = [boxes; boxesEntry];
end
end
end
%{
old code
[scores scales padx pady] = computeScores(input, model, true);
boxes = [];
for componentIdx=1:length(scores)
for pyramidLevelIdx=1:length(scores{componentIdx})
% get all good matches
scale = scales(pyramidLevelIdx);
rsize = model.rootfilters{model.components{componentIdx}.rootindex}.size;
score = scores{componentIdx}{pyramidLevelIdx};
I = find(score > thresh);
[Y, X] = ind2sub(size(score), I);
boxesEntry = zeros(length(I), 6);
for i = 1:length(I)
x = X(i);
y = Y(i);
b = getBoundingBox(x, y, scale, padx, pady, rsize);
boxesEntry(i,:) = [b componentIdx score(I(i))];
end
boxes = [boxes; boxesEntry];
end
end
%}