@@ -81,31 +81,19 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
8181 image = image [yOffset :yOffset + searchHeight , xOffset :xOffset + searchWidth ]
8282 else :
8383 xOffset = yOffset = 0
84-
85- ## OpenCv matchTemplates only support 8 or 32-bit ie cast 16-bit to 32-bit
86- if image .dtype == 'uint16' :
87- image = np .float32 (image )
88-
89- elif image .dtype == "float64" :
90- raise ValueError ("64-bit not supported, max 32-bit" )
91-
84+
9285 listHit = []
9386 for templateName , template in listTemplates :
9487
9588 #print('\nSearch with template : ',templateName)
9689
97- if template .dtype == "float64" : raise ValueError ("64-bit not supported, max 32-bit" )
98-
99- ## Make sure both images have same bittype and 8 or 32 bit
100- if (template .dtype == "uint8" and image .dtype == "float32" ) or template .dtype == 'uint16' :
101- template = np .float32 (template )
102-
103- # Separate if
104- if template .dtype == "float32" and image .dtype == "uint8" :
105- image = np .float32 (image )
90+ if template .dtype == "float64" or image .dtype == "float64" : raise ValueError ("64-bit not supported, max 32-bit" )
10691
10792 ## Compute correlation map
108- corrMap = cv2 .matchTemplate (template , image , method )
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 )
10997
11098 ## Find possible location of the object
11199 if N_object == 1 : # Detect global Min/Max
0 commit comments