使用OpenCV Python在三张图像中匹配Sift特征

3

目标是使用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_2goodmatches2_3,它们包含从图像1->2和2->3的匹配点。那么是否有一种方法可以匹配1->2->3,仅使用三张图像中的对应点呢? 任何提示都会很有帮助。
1个回答

0

我有同样的问题,这是我的解决方法,但我认为应该有更好的方法:

据我所知,图像的SIFT点始终相同,也就是说,在goodmatches1_2 = [[sift1, sift2], ...]goodmatches2_3 = [[sift2, sift3], ...]中的所有匹配对中,这两个列表中的sift2将完全相同。因此,我只需要执行以下操作:

goodmatches123 = []
for i, sift12 in enumerate(goodmatches1_2):
    for j, sift23 in enumerate(goodmatches2_3):
        if sift12 == sift23:
            goodmatches123.append(goodmatches1_2[i],sift12,goodmatches2_3[j])

希望这能给你一些启发!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接