@@ -81,31 +81,19 @@ def findMatches(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=floa
81
81
image = image [yOffset :yOffset + searchHeight , xOffset :xOffset + searchWidth ]
82
82
else :
83
83
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
+
92
85
listHit = []
93
86
for templateName , template in listTemplates :
94
87
95
88
#print('\nSearch with template : ',templateName)
96
89
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" )
106
91
107
92
## 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 )
109
97
110
98
## Find possible location of the object
111
99
if N_object == 1 : # Detect global Min/Max
0 commit comments