@@ -46,6 +46,23 @@ def _findLocalMin_(corrMap, score_threshold=0.4):
4646 return _findLocalMax_ (- corrMap , - score_threshold )
4747
4848
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+
4966
5067def findMatches (listTemplates , image , method = cv2 .TM_CCOEFF_NORMED , N_object = float ("inf" ), score_threshold = 0.5 , searchBox = None ):
5168 '''
@@ -87,13 +104,7 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
87104
88105 #print('\nSearch with template : ',templateName)
89106
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 )
97108
98109 ## Find possible location of the object
99110 if N_object == 1 : # Detect global Min/Max
0 commit comments