|
14 | 14 | import cv2 |
15 | 15 |
|
16 | 16 |
|
17 | | -def NMS(tableHit, scoreThreshold=0, sortAscending=False, N_object=-1, maxOverlap=0.5): |
| 17 | +def NMS(tableHit, scoreThreshold=0, sortAscending=False, N_object=float("inf"), maxOverlap=0.5): |
18 | 18 | ''' |
19 | 19 | Perform Non-Maxima supression : it compares the hits after maxima/minima detection, and removes the ones that are too close (too large overlap) |
20 | 20 | This function works both with an optionnal threshold on the score, and number of detected bbox |
@@ -49,13 +49,14 @@ def NMS(tableHit, scoreThreshold=0, sortAscending=False, N_object=-1, maxOverlap |
49 | 49 | listScores = [1-score for score in listScores] # NMS expect high-score for good predictions |
50 | 50 | scoreThreshold = 1-scoreThreshold |
51 | 51 |
|
52 | | - #indexes = cv2.dnn.NMSBoxes(listBoxes, listScores, scoreThreshold, maxOverlap, top_k=N_object) # weird result when top_k=N |
53 | 52 | indexes = cv2.dnn.NMSBoxes(listBoxes, listScores, scoreThreshold, maxOverlap) |
54 | 53 |
|
55 | | - if N_object>0: indexes = indexes[:N_object] # alternative to keep the N best detections (ie after the actual NMS) |
56 | | - |
57 | | - indexes = [index[0] for index in indexes] # ordered by score |
58 | | - outTable = tableHit[tableHit.index.isin(indexes)].sort_values(by=['Score'], ascending=False) |
| 54 | + if N_object == float("inf"): |
| 55 | + indexes = [ index[0] for index in indexes ] # ordered by score |
| 56 | + else: |
| 57 | + indexes = [ index[0] for index in indexes[:N_object] ] |
| 58 | + |
| 59 | + outTable = tableHit.iloc[indexes] |
59 | 60 |
|
60 | 61 | return outTable |
61 | 62 |
|
|
0 commit comments