@@ -48,6 +48,7 @@ def _findLocalMin_(corrMap, score_threshold=0.4):
48
48
def computeScoreMap (template , image , method = cv2 .TM_CCOEFF_NORMED , mask = None ):
49
49
"""
50
50
Compute score map provided numpy array for template and image (automatically converts images if necessary).
51
+ The template must be smaller or as large as the image.
51
52
A mask can be provided to limit the comparison of the pixel values to a fraction of the template region.
52
53
The mask should have the same dimensions and image type than the template.
53
54
@@ -85,7 +86,8 @@ def computeScoreMap(template, image, method=cv2.TM_CCOEFF_NORMED, mask=None):
85
86
86
87
def findMatches (listTemplates , image , method = cv2 .TM_CCOEFF_NORMED , N_object = float ("inf" ), score_threshold = 0.5 , searchBox = None ):
87
88
"""
88
- Find all possible templates locations provided a list of templates to search and an image.
89
+ Find all possible templates locations satisfying the score threshold provided a list of templates to search and an image.
90
+ Returns a pandas dataframe with one row per detection.
89
91
90
92
Parameters
91
93
----------
@@ -107,7 +109,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
107
109
- score_threshold: float in range [0,1]
108
110
if N_object>1, returns local minima/maxima respectively below/above the score_threshold
109
111
110
- - searchBox : tuple (X, Y, Width, Height ) in pixel unit
112
+ - searchBox : tuple (x, y, width, height ) in pixel unit
111
113
optional rectangular search region as a tuple
112
114
113
115
Returns
@@ -120,7 +122,8 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
120
122
## Crop image to search region if provided
121
123
if searchBox is not None :
122
124
xOffset , yOffset , searchWidth , searchHeight = searchBox
123
- image = image [yOffset :yOffset + searchHeight , xOffset :xOffset + searchWidth ]
125
+ image = image [yOffset : yOffset + searchHeight , xOffset : xOffset + searchWidth ]
126
+
124
127
else :
125
128
xOffset = yOffset = 0
126
129
@@ -133,7 +136,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
133
136
templateName , template = tempTuple [:2 ]
134
137
mask = None
135
138
136
- if len (tempTuple )>= 3 :
139
+ if len (tempTuple )>= 3 : # ie a mask is also provided
137
140
if method in (0 ,3 ):
138
141
mask = tempTuple [2 ]
139
142
else :
0 commit comments