From 6ba776c8f08018b9b79bfee2b17c7cf03a6d9871 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 15 Apr 2019 20:05:04 -0400 Subject: [PATCH] Reorganize Sift_Distance.py * Put Shift_Distance code into sift_distance function * Add import statements for numpy and opencv --- src/Sift_Distance.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Sift_Distance.py b/src/Sift_Distance.py index dad454b..908de09 100644 --- a/src/Sift_Distance.py +++ b/src/Sift_Distance.py @@ -1,24 +1,28 @@ -sift = cv.xfeatures2d.SIFT_create() -original_kp, original_des = sift.detectAndCompute(left,None) -new_kp, new_des = sift.detectAndCompute(right,None) +import numpy as np +import cv2 -bf = cv2.BFMatcher() -matches = bf.knnMatch(original_des, new_des, k=2) -# Apply ratio test -good = [] -for m, n in matches: - if m.distance < 0.3 * n.distance: - good.append([m]) +def sift_distance(): + sift = cv2.xfeatures2d.SIFT_create() + original_kp, original_des = sift.detectAndCompute(left,None) + new_kp, new_des = sift.detectAndCompute(right,None) -# Featured matched keypoints from images 1 and 2 -pts1 = np.float32([original_kp[m.queryIdx].pt for m in good]) -pts2 = np.float32([new_kp[m.trainIdx].pt for m in good]) + bf = cv2.BFMatcher() + matches = bf.knnMatch(original_des, new_des, k=2) -#convert to complex number -z1 = np.array([[complex(c[0],c[1]) for c in pts1]]) -z2 = np.array([[complex(c[0],c[1]) for c in pts2]]) + # Apply ratio test + good = [] + for m, n in matches: + if m.distance < 0.3 * n.distance: + good.append([m]) -# Distance between featured matched keypoints -FM_dist = abs(z2 - z1) + # Featured matched keypoints from images 1 and 2 + pts1 = np.float32([original_kp[m.queryIdx].pt for m in good]) + pts2 = np.float32([new_kp[m.trainIdx].pt for m in good]) + #convert to complex number + z1 = np.array([[complex(c[0],c[1]) for c in pts1]]) + z2 = np.array([[complex(c[0],c[1]) for c in pts2]]) + + # Distance between featured matched keypoints + FM_dist = abs(z2 - z1)