Skip to content

Commit bc92369

Browse files
committed
replace default N_object with -1
1 parent d7cd0da commit bc92369

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

MTM/__init__.py

Lines changed: 6 additions & 10 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=float("inf"), score_threshold=0.5, searchBox=None):
67+
def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=-1, 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
@@ -76,7 +76,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
7676
- method : int
7777
one of OpenCV template matching method (0 to 5), default 5=0-mean cross-correlation
7878
- N_object: int
79-
expected number of objects in the image
79+
expected number of objects in the image, -1 if unknown
8080
- score_threshold: float in range [0,1]
8181
if N>1, returns local minima/maxima respectively below/above the score_threshold
8282
- searchBox : tuple (X, Y, Width, Height) in pixel unit
@@ -89,9 +89,6 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
8989
if N_object!=float("inf") and type(N_object)!=int:
9090
raise TypeError("N_object must be an integer")
9191

92-
elif N_object<1:
93-
raise ValueError("At least one object should be expected in the image")
94-
9592
## Crop image to search region if provided
9693
if searchBox != None:
9794
xOffset, yOffset, searchWidth, searchHeight = searchBox
@@ -143,7 +140,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
143140
return pd.DataFrame(listHit) # All possible hits before Non-Maxima Supression
144141

145142

146-
def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=float("inf"), score_threshold=0.5, maxOverlap=0.25, searchBox=None):
143+
def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=-1, score_threshold=0.5, maxOverlap=0.25, searchBox=None):
147144
'''
148145
Search each template in the image, and return the best N_object location which offer the best score and which do not overlap
149146
Parameters
@@ -176,12 +173,11 @@ def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=f
176173

177174
tableHit = findMatches(listTemplates, image, method, N_object, score_threshold, searchBox)
178175

179-
if method == 1: bestHits = NMS(tableHit, N_object=N_object, maxOverlap=maxOverlap, sortAscending=True)
176+
if method == 1: sortAscending = True
177+
elif method in (3,5): sortAscending = False
180178

181-
elif method in (3,5): bestHits = NMS(tableHit, N_object=N_object, maxOverlap=maxOverlap, sortAscending=False)
179+
return NMS(tableHit, score_threshold, sortAscending, N_object, maxOverlap)
182180

183-
return bestHits
184-
185181

186182
def drawBoxesOnRGB(image, tableHit, boxThickness=2, boxColor=(255, 255, 00), showLabel=False, labelColor=(255, 255, 0), labelScale=0.5 ):
187183
'''

0 commit comments

Comments
 (0)