Closed. This question needs to be more focused。它当前不接受答案。












想改善这个问题吗?更新问题,使其仅关注editing this post的一个问题。

3年前关闭。



Improve this question




我正在使用在教程中找到的特征点检测算法,如下所示。此代码的输出是在特征点匹配的两个图像之间绘制的线。

我想知道的是:有没有一种方法可以返回一些值(浮点值)来确定两个图像是否几乎相同,多少相似或不同?
def feature_matching():

    img1 = cv2.imread('image1.jpeg', 0)

    img2 = cv2.imread('image2.jpeg', 0)


    # 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.75*n.distance:
            good.append(m)


    #gray1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
    #gray2 = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
    # cv2.drawMatchesKnn expects list of lists as matches.
    img3 = drawMatches(img1,kp1,img2,kp2,good)



    plt.imshow(img3),plt.show()

最佳答案

您在代码本身中具有度量。您正在汇总列表中匹配的点。因此,您可以检查列表中是否有多个点,这表示图像匹配。
您也可以要求线中的点之间有更好的匹配度
如果m.distance good.append(m)
例如更改为较低的对应值
如果m.distance good.append(m)

07-24 09:47
查看更多