Skip to content

Commit 0b3ddff

Browse files
committed
Check that template are smaller than image
fixes #11
1 parent 3a06ae2 commit 0b3ddff

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

MTM/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,21 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
126126

127127
else:
128128
xOffset=yOffset=0
129-
130-
listHit = []
131-
for tempTuple in listTemplates:
132-
129+
130+
# Check that the template are all smaller are equal to the image (original, or cropped if there is a search region)
131+
for index, tempTuple in enumerate(listTemplates):
132+
133133
if not isinstance(tempTuple, tuple) or len(tempTuple)==1:
134134
raise ValueError("listTemplates should be a list of tuples as ('name','array') or ('name', 'array', 'mask')")
135+
136+
templateSmallerThanImage = all(templateDim <= imageDim for templateDim, imageDim in zip(tempTuple[1].shape, image.shape))
137+
138+
if not templateSmallerThanImage :
139+
fitIn = "searchBox" if (searchBox is not None) else "image"
140+
raise ValueError("Template '{}' at index {} in the list of templates is larger than {}.".format(tempTuple[0], index, fitIn) )
141+
142+
listHit = []
143+
for tempTuple in listTemplates:
135144

136145
templateName, template = tempTuple[:2]
137146
mask = None

0 commit comments

Comments
 (0)