forked from gidariss/LocNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnms.m
More file actions
76 lines (64 loc) · 1.72 KB
/
nms.m
File metadata and controls
76 lines (64 loc) · 1.72 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function pick = nms(boxes, overlap, use_gpu)
% top = nms(boxes, overlap)
% Non-maximum suppression. (FAST VERSION)
% Greedily select high-scoring detections and skip detections
% that are significantly covered by a previously selected
% detection.
%
% NOTE: This is adapted from Pedro Felzenszwalb's version (nms.m),
% but an inner loop has been eliminated to significantly speed it
% up in the case of a large number of boxes
% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
%
% This file is part of the Exemplar-SVM library and is made
% available under the terms of the MIT license (see COPYING file).
% Project homepage: https://github.com/quantombone/exemplarsvm
if isempty(boxes)
pick = [];
return;
end
if ~exist('use_gpu', 'var')
use_gpu = false;
end
if use_gpu
s = boxes(:, end);
if ~issorted(s(end:-1:1))
[~, I] = sort(s, 'descend');
boxes = boxes(I, :);
else
I = (1:numel(s))';
end
pick = nms_gpu_mex(single(boxes)', double(overlap));
pick = I(pick);
return;
end
if size(boxes, 1) < 50000
pick = nms_mex(double(boxes), double(overlap));
return;
end
x1 = boxes(:,1);
y1 = boxes(:,2);
x2 = boxes(:,3);
y2 = boxes(:,4);
s = boxes(:,end);
area = (x2-x1+1) .* (y2-y1+1);
[vals, I] = sort(s);
pick = s*0;
counter = 1;
while ~isempty(I)
last = length(I);
i = I(last);
pick(counter) = i;
counter = counter + 1;
xx1 = max(x1(i), x1(I(1:last-1)));
yy1 = max(y1(i), y1(I(1:last-1)));
xx2 = min(x2(i), x2(I(1:last-1)));
yy2 = min(y2(i), y2(I(1:last-1)));
w = max(0.0, xx2-xx1+1);
h = max(0.0, yy2-yy1+1);
inter = w.*h;
o = inter ./ (area(i) + area(I(1:last-1)) - inter);
I = I(find(o<=overlap));
end
pick = pick(1:(counter-1));