0

I'm using a feature point detection algorithm I found in a tutorial as shown below. The output of this code are lines drawn between the two images where feature points match.

Here's what I would like to know: Is there a way to return some value (floating point value) to determine if the two images are almost same, somewhat similar or not same?

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()
tavalendo
  • 857
  • 2
  • 11
  • 30
akrama81
  • 341
  • 1
  • 7
  • 18
  • Short answer: yes there is. Long answer: too broad for a SO question. But I'm sure you can google it and find solutions in different tutorials. – Julien Jul 04 '17 at 02:18

2 Answers2

2

You have a measure in the code itself. You are aggrating points that match in the list good. So you can check that if you have more than several points in the list good it means that the images match. Also you can ask for a better match score between points in the line if m.distance < 0.75*n.distance: good.append(m) Change to a lower corresponding value for example if m.distance < 0.3*n.distance: good.append(m)

Amitay Nachmani
  • 3,259
  • 1
  • 18
  • 21
  • But, increasing it, increases the number of "good" points. Decreasing it to 0.5 or so decreases the number of "good" points. – akrama81 Jul 05 '17 at 17:16
  • Yes your are correct but it doesn't change the fact that this is a measurement of how good the correspondents between the image is – Amitay Nachmani Jul 06 '17 at 16:06
0

If you want a simple float value indicating the measure of the match, you can use some very simple techniques like template matching. If you have a lot of training images you can use a machine learning approach like the HOG SVMs

These are simpler techniques to performing feature detection, matching, etc

Shawn Mathew
  • 2,198
  • 1
  • 14
  • 31