Fixed Displacement Calculation

* Changed displacement calculation to account for the template matching function returning the upper-left corner of the matching window rather than the center.
This commit is contained in:
Sravan Balaji
2019-04-24 19:49:20 -04:00
parent cbb8e954e8
commit 527be26305

View File

@@ -111,8 +111,8 @@ def find_displacement(match_method):
plt.figure(1)
reference = images[8]
compare_img = images[9]
reference = images[560]
compare_img = images[561]
plt.imshow(reference, cmap="gray", vmin=0, vmax=255)
@@ -138,18 +138,18 @@ def find_displacement(match_method):
res = cv2.matchTemplate(image=search, templ=subset, method=match_method)
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res)
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(src=res)
dx = None
dy = None
if match_method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
dx = minLoc[0] - search_size
dy = minLoc[1] - search_size
dx = (minLoc[0] + (subset_size // 2)) - search_size
dy = (minLoc[1] + (subset_size // 2)) - search_size
elif match_method in [cv2.TM_CCORR, cv2.TM_CCORR_NORMED,
cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED]:
dx = maxLoc[0] - search_size
dy = maxLoc[1] - search_size
dx = (maxLoc[0] + (subset_size // 2)) - search_size
dy = (maxLoc[1] + (subset_size // 2)) - search_size
im_data.dx[j, i] = dx
im_data.dy[j, i] = dy