title: Use of a FLANN index to match a picture with a database
body: <p>I would like to match a picture with a database that contains about 1000 images.
  I would like that after receiving an image as an input the program returns the most similar picture in the database.</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import cv2
  import os
  
  scanned = 'input.jpg'
  orb = cv2.ORB_create()
  FLANN_INDEX_LSH = 6
  flann_params = dict(algorithm = FLANN_INDEX_LSH, table_number = 10, key_size = 20, multi_probe_level = 0)
  search_params = dict(checks=50)
  flann = cv2.FlannBasedMatcher(flann_params,search_params)
  
  des_all = None
  for filename in os.listdir('images'):
      img2 = cv2.imread('images/' + filename, 0)
      kp2, des2 = orb.detectAndCompute(img2,None)
      flann.add([des2])
      
  print (&quot;Training...&quot;)
  flann.train()                    
  
  img1 = cv2.imread(scanned, 0)
  kp1, des1 = orb.detectAndCompute(img1,None)
  print (&quot;Matching...&quot;)
  matches = flann.knnMatch(des1,k=2)
  
  </code></pre>
  <p>After that what I have to do to get which of my images has the best match?
  How can I use the matches results?
  I can't find any useful documentation about it
  Thanks for your help.</p>