Skip to content

Commit c4314ca

Browse files
committed
back to default N_object=inf
1 parent c479be2 commit c4314ca

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

MTM/NMS.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import cv2
1515

1616

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):
1818
'''
1919
Perform Non-Maxima supression : it compares the hits after maxima/minima detection, and removes the ones that are too close (too large overlap)
2020
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
4949
listScores = [1-score for score in listScores] # NMS expect high-score for good predictions
5050
scoreThreshold = 1-scoreThreshold
5151

52-
#indexes = cv2.dnn.NMSBoxes(listBoxes, listScores, scoreThreshold, maxOverlap, top_k=N_object) # weird result when top_k=N
5352
indexes = cv2.dnn.NMSBoxes(listBoxes, listScores, scoreThreshold, maxOverlap)
5453

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]
5960

6061
return outTable
6162

MTM/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def computeScoreMap(template, image, method=cv2.TM_CCOEFF_NORMED):
6464
return cv2.matchTemplate(template, image, method)
6565

6666

67-
def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=-1, score_threshold=0.5, searchBox=None):
67+
def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=float("inf"), score_threshold=0.5, searchBox=None):
6868
'''
6969
Find all possible templates locations provided a list of template to search and an image
7070
Parameters
@@ -140,7 +140,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=-1,
140140
return pd.DataFrame(listHit) # All possible hits before Non-Maxima Supression
141141

142142

143-
def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=-1, score_threshold=0.5, maxOverlap=0.25, searchBox=None):
143+
def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=float("inf"), score_threshold=0.5, maxOverlap=0.25, searchBox=None):
144144
'''
145145
Search each template in the image, and return the best N_object location which offer the best score and which do not overlap
146146
Parameters

0 commit comments

Comments
 (0)