@@ -45,12 +45,26 @@ def NMS(tableHit, scoreThreshold=0, sortAscending=False, N_object=float("inf"),
45
45
listBoxes = tableHit ["BBox" ].to_list ()
46
46
listScores = tableHit ["Score" ].to_list ()
47
47
48
- if sortAscending :
48
+ if N_object == 1 :
49
+
50
+ # Get row with highest or lower score
51
+ if sortAscending :
52
+ outTable = tableHit [tableHit .Score == tableHit .Score .min ()]
53
+ else :
54
+ outTable = tableHit [tableHit .Score == tableHit .Score .max ()]
55
+
56
+ return outTable
57
+
58
+
59
+ # N object > 1 -> do NMS
60
+ if sortAscending : # invert score to have always high-score for bets prediction
49
61
listScores = [1 - score for score in listScores ] # NMS expect high-score for good predictions
50
62
scoreThreshold = 1 - scoreThreshold
51
-
63
+
64
+ # Do NMS
52
65
indexes = cv2 .dnn .NMSBoxes (listBoxes , listScores , scoreThreshold , maxOverlap )
53
66
67
+ # Get N best hit
54
68
if N_object == float ("inf" ):
55
69
indexes = [ index [0 ] for index in indexes ] # ordered by score
56
70
else :
@@ -69,6 +83,6 @@ def NMS(tableHit, scoreThreshold=0, sortAscending=False, N_object=float("inf"),
69
83
{'TemplateName' :1 ,'BBox' :(1074 , 530 , 680 , 390 ), 'Score' :0.4 }
70
84
]
71
85
72
- FinalHits = NMS ( pd .DataFrame (ListHit ), scoreThreshold = 0.61 , sortAscending = True , maxOverlap = 0.8 , N_object = 2 )
86
+ FinalHits = NMS ( pd .DataFrame (ListHit ), scoreThreshold = 0.61 , sortAscending = False , maxOverlap = 0.8 , N_object = 1 )
73
87
74
88
print (FinalHits )
0 commit comments