title: How to improve/modify parameters of Feature Matching - SIFT SURF - Opencv
body: <p>I am trying to use feature matching to determine if two images are similar. I have tried SIFT, SURF, and ORB with similar results from each. I am first trying to display the matches between these two images. <a href="https://i.stack.imgur.com/SvlbA.png" rel="nofollow noreferrer">Image1</a> <a href="https://i.stack.imgur.com/g9rl4.png" rel="nofollow noreferrer">Image2</a> I have tried both brute force matching and knn matching but with both implementations, I get around 10 matches with little to no <a href="https://i.stack.imgur.com/15M5I.png" rel="nofollow noreferrer">accuracy</a>. Are the two images too different in terms of scale, transformation, and perspective to generate accurate matches? What parameters could I modify to improve performance? The matching often produces a lot of matches but only a few pass ratio test.</p>
  
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  import numpy as np
  
  model = cv2.imread("path")
  modelg = cv2.cvtColor(model,cv2.COLOR_BGR2GRAY)
  modelg = cv2.GaussianBlur(modelg,(7,7),0)
  height, width = modelg.shape[:2]
  print(str(height)+ " " + str(width))
  
  
  frame = cv2.imread("Path")
  plt.imshow(frame)
  plt.show()
  
  #frame = cv2.imread("Path")
  
  frame = cv2.resize(frame,(width,height))
  frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
  blur = cv2.GaussianBlur(frame,(7,7),0)
  
  
  #blur = cv2.blur(frame,(7,7))
  plt.imshow(blur,cmap='gray')
  plt.show()
  plt.imshow(modelg,cmap='gray')
  plt.show()
  
  # Initiate SIFT detector
  surf = cv2.xfeatures2d.SURF_create()
  # find the keypoints and descriptors with SIFT
  orb = cv2.ORB_create()
  # find the keypoints and descriptors with ORB
  kp1, des1 = surf.detectAndCompute(modelg,None)
  kp2, des2 = surf.detectAndCompute(blur,None)
  #kp1, des1 = surf.detectAndCompute(,None)
  #kp2, des2 = surf.detectAndCompute(blur,None)
  # BFMatcher with default params
  
  bf = cv2.BFMatcher()
  matches = bf.knnMatch(des1,des2,k=2)
  print(len(matches))
  # Apply ratio test
  good = []
  for m,n in matches:
      if m.distance &lt; 0.75*n.distance:
          good.append([m])
  print(len(good))
  # cv.drawMatchesKnn expects list of lists as matches.
  img3 = cv2.drawMatchesKnn(modelg,kp1,blur,kp2,good,None,flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
  plt.imshow(img3),plt.show()
  </code></pre>