├── .gitignore ├── README.md └── nms.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | 21 | # Installer logs 22 | pip-log.txt 23 | 24 | # Unit test / coverage reports 25 | .coverage 26 | .tox 27 | nosetests.xml 28 | 29 | # Translations 30 | *.mo 31 | 32 | # Mr Developer 33 | .mr.developer.cfg 34 | .project 35 | .pydevproject 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nms-python 2 | ========== 3 | 4 | Python Implementation of Non-maximum suppression -------------------------------------------------------------------------------- /nms.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy import * 3 | 4 | # boxes is a list of size (n x 5) 5 | # trial is a numpy array of size (n x 5) 6 | # Author: Vicky 7 | 8 | def nms (boxes,overlap): 9 | if not boxes: 10 | pick = [] 11 | else: 12 | trial = zeros((len(boxes),5),dtype=float64) 13 | trial[:] = boxes[:] 14 | x1 = trial[:,0] 15 | y1 = trial[:,1] 16 | x2 = trial[:,2] 17 | y2 = trial[:,3] 18 | score = trial[:,4] 19 | area = (x2-x1+1)*(y2-y1+1) 20 | 21 | #vals = sort(score) 22 | I = argsort(score) 23 | pick = [] 24 | count = 1 25 | while (I.size!=0): 26 | #print "Iteration:",count 27 | last = I.size 28 | i = I[last-1] 29 | pick.append(i) 30 | suppress = [last-1] 31 | for pos in range(last-1): 32 | j = I[pos] 33 | xx1 = max(x1[i],x1[j]) 34 | yy1 = max(y1[i],y1[j]) 35 | xx2 = min(x2[i],x2[j]) 36 | yy2 = min(y2[i],y2[j]) 37 | w = xx2-xx1+1 38 | h = yy2-yy1+1 39 | if (w>0 and h>0): 40 | o = w*h/area[j] 41 | print "Overlap is",o 42 | if (o >overlap): 43 | suppress.append(pos) 44 | I = delete(I,suppress) 45 | count = count + 1 46 | return pick 47 | --------------------------------------------------------------------------------