@@ -107,18 +107,18 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
107
107
if N_object == 1 : # Detect global Min/Max
108
108
minVal , maxVal , minLoc , maxLoc = cv2 .minMaxLoc (corrMap )
109
109
110
- if method == 1 :
110
+ if method in ( 0 , 1 ) :
111
111
Peaks = [minLoc [::- 1 ]] # opposite sorting than in the multiple detection
112
112
113
- elif method in ( 3 , 5 ) :
113
+ else :
114
114
Peaks = [maxLoc [::- 1 ]]
115
115
116
116
117
117
else :# Detect local max or min
118
- if method == 1 : # Difference => look for local minima
118
+ if method in ( 0 , 1 ) : # Difference => look for local minima
119
119
Peaks = _findLocalMin_ (corrMap , score_threshold )
120
120
121
- elif method in ( 3 , 5 ) :
121
+ else :
122
122
Peaks = _findLocalMax_ (corrMap , score_threshold )
123
123
124
124
@@ -150,7 +150,8 @@ def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=f
150
150
- image : Grayscale or RGB numpy array
151
151
image in which to perform the search, it should be the same bitDepth and number of channels than the templates
152
152
- method : int
153
- one of OpenCV template matching method (0 to 5), default 5=0-mean cross-correlation
153
+ one of OpenCV template matching method (1 to 5), default 5=0-mean cross-correlation
154
+ method 0 is not supported (no NMS implemented for non-bound difference score), use 1 instead
154
155
- N_object: int
155
156
expected number of objects in the image
156
157
- score_threshold: float in range [0,1]
@@ -173,8 +174,9 @@ def matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=f
173
174
174
175
tableHit = findMatches (listTemplates , image , method , N_object , score_threshold , searchBox )
175
176
176
- if method == 1 : sortAscending = True
177
- elif method in (3 ,5 ): sortAscending = False
177
+ if method == 0 : raise ValueError ("The method TM_SQDIFF is not supported. Use TM_SQDIFF_NORMED instead." )
178
+ elif method == 1 : sortAscending = True
179
+ else : sortAscending = False
178
180
179
181
return NMS (tableHit , score_threshold , sortAscending , N_object , maxOverlap )
180
182
0 commit comments