mirror of
https://github.com/balajsra/EECS-442-WN19-DIC-Project.git
synced 2025-09-03 01:13:15 +00:00
Reorganize Sift_Distance.py
* Put Shift_Distance code into sift_distance function * Add import statements for numpy and opencv
This commit is contained in:
@@ -1,24 +1,28 @@
|
|||||||
sift = cv.xfeatures2d.SIFT_create()
|
import numpy as np
|
||||||
original_kp, original_des = sift.detectAndCompute(left,None)
|
import cv2
|
||||||
new_kp, new_des = sift.detectAndCompute(right,None)
|
|
||||||
|
|
||||||
bf = cv2.BFMatcher()
|
|
||||||
matches = bf.knnMatch(original_des, new_des, k=2)
|
|
||||||
|
|
||||||
# Apply ratio test
|
def sift_distance():
|
||||||
good = []
|
sift = cv2.xfeatures2d.SIFT_create()
|
||||||
for m, n in matches:
|
original_kp, original_des = sift.detectAndCompute(left,None)
|
||||||
if m.distance < 0.3 * n.distance:
|
new_kp, new_des = sift.detectAndCompute(right,None)
|
||||||
good.append([m])
|
|
||||||
|
|
||||||
# Featured matched keypoints from images 1 and 2
|
bf = cv2.BFMatcher()
|
||||||
pts1 = np.float32([original_kp[m.queryIdx].pt for m in good])
|
matches = bf.knnMatch(original_des, new_des, k=2)
|
||||||
pts2 = np.float32([new_kp[m.trainIdx].pt for m in good])
|
|
||||||
|
|
||||||
#convert to complex number
|
# Apply ratio test
|
||||||
z1 = np.array([[complex(c[0],c[1]) for c in pts1]])
|
good = []
|
||||||
z2 = np.array([[complex(c[0],c[1]) for c in pts2]])
|
for m, n in matches:
|
||||||
|
if m.distance < 0.3 * n.distance:
|
||||||
|
good.append([m])
|
||||||
|
|
||||||
# Distance between featured matched keypoints
|
# Featured matched keypoints from images 1 and 2
|
||||||
FM_dist = abs(z2 - z1)
|
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)
|
||||||
|
Reference in New Issue
Block a user