目标是使用Python和(不是必须的)OpenCV匹配超过2张图像。一开始,三张图像足够好。 是否有一般的方法来实现这个目标?目前,我正在使用SIFT算法将1->2和2->3进行匹配,并使用以下代码:
img1 = cv2.imread('picture1.jpg', cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread('picture2.jpg', cv2.IMREAD_GRAYSCALE)
img3 = cv2.imread('picture3.jpg', cv2.IMREAD_GRAYSCALE)
#-- Step 1: Detect the keypoints using SIFT Detector, compute the descriptors
sift = cv2.xfeatures2d.SIFT_create()
keypoints1, descriptors1 = sift.detectAndCompute( img1, None)
keypoints2, descriptors2 = sift.detectAndCompute( img2, None)
keypoints3, descriptors3 = sift.detectAndCompute( img3, None)
#-- Step 2: Matching descriptor vectors with a FLANN based matcher for image pair 1 -> 2
matcher = cv2.DescriptorMatcher_create(cv2.DescriptorMatcher_FLANNBASED)
knn_matches1_2 = matcher.knnMatch(descriptors1, descriptors2, 2)
#-- Filter matches using the Lowe's ratio test
ratio_thresh = 0.4
good_matches1_2 = []
for m,n in knn_matches1_2:
if m.distance < ratio_thresh * n.distance:
good_matches1_2.append(m)
#-- Step 3: Matching descriptor vectors with a FLANN based matcher for image pair 2 -> 3
knn_matches2_3 = matcher.knnMatch(descriptors2, descriptors3, 2)
#-- Filter matches using the Lowe's ratio test
ratio_thresh = 0.4
good_matches2_3 = []
for m,n in knn_matches2_3:
if m.distance < ratio_thresh * n.distance:
good_matches2_3.append(m)
这让我剩下了
goodmatches1_2
和goodmatches2_3
,它们包含从图像1->2和2->3的匹配点。那么是否有一种方法可以匹配1->2->3,仅使用三张图像中的对应点呢?
任何提示都会很有帮助。