我正在尝试实现一个程序,该程序将输入两个立体图像并查找具有特征匹配的关键点之间的距离。是否有任何方法可以做到这一点?我正在使用SIFT/BFMatcher,并且我的代码如下:
import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = dst1
img2 = dst2
# Initiate SIFT detector
sift = cv2.SIFT()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
# Apply ratio test
good = []
for m, n in matches:
if m.distance < 0.3 * n.distance:
good.append([m])
# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, flags=2, outImg=img2)
plt.imshow(img3), plt.show()