2
我正在嘗試實現一個程序,該程序將輸入兩個立體圖像並找出具有功能匹配的關鍵點之間的距離。有什麼辦法可以做到嗎?我與SIFT/BFMatcher工作,我的代碼如下:Python - 功能匹配關鍵點與OpenCV之間的距離
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()