Skip to content

Commit ab820ec

Browse files
committed
simpler if/else for tpye checking
1 parent a7744e6 commit ab820ec

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

MTM/__init__.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''
2+
Make sure the active directory is the directory of the repo when running the test in a IDE
3+
'''
14
from skimage.data import coins
25
import matplotlib.pyplot as plt
36
import MTM, cv2

0 commit comments

Comments
 (0)