From 527be26305aa6f5bcefbbc6571eb049f3af4dfb7 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Wed, 24 Apr 2019 19:49:20 -0400 Subject: [PATCH] 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. --- src/__main__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index c713667..dc08d63 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -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