@@ -46,6 +46,23 @@ def _findLocalMin_(corrMap, score_threshold=0.4):
46
46
return _findLocalMax_ (- corrMap , - score_threshold )
47
47
48
48
49
+ def computeScoreMap (template , image , method = cv2 .TM_CCOEFF_NORMED ):
50
+ '''
51
+ Compute score map provided numpy array for template and image.
52
+ Automatically converts images if necessary
53
+ return score map as numpy as array
54
+ '''
55
+ if template .dtype == "float64" or image .dtype == "float64" :
56
+ raise ValueError ("64-bit not supported, max 32-bit" )
57
+
58
+ # Convert images if not both 8-bit (OpenCV matchTempalte is only defined for 8-bit OR 32-bit)
59
+ if not (template .dtype == "uint8" and image .dtype == "uint8" ):
60
+ template = np .float32 (template )
61
+ image = np .float32 (image )
62
+
63
+ # Compute correlation map
64
+ return cv2 .matchTemplate (template , image , method )
65
+
49
66
50
67
def findMatches (listTemplates , image , method = cv2 .TM_CCOEFF_NORMED , N_object = float ("inf" ), score_threshold = 0.5 , searchBox = None ):
51
68
'''
@@ -87,13 +104,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
87
104
88
105
#print('\nSearch with template : ',templateName)
89
106
90
- if template .dtype == "float64" or image .dtype == "float64" : raise ValueError ("64-bit not supported, max 32-bit" )
91
-
92
- ## Compute correlation map
93
- if template .dtype == "uint8" and image .dtype == "uint8" :
94
- corrMap = cv2 .matchTemplate (template , image , method )
95
- else :
96
- corrMap = cv2 .matchTemplate (np .float32 (template ), np .float32 (image ), method )
107
+ corrMap = computeScoreMap (template , image , method )
97
108
98
109
## Find possible location of the object
99
110
if N_object == 1 : # Detect global Min/Max
0 commit comments