pythonopencvsifttemplate-matching

Finding the image with best matches from multiple images for SIFT BF-Match


I have read many questions about matching one image with a number of images using SIFT and Brute-Force matching like this and this. Is it possible to do many-with-one kind of matching? What I would like to do is the following.

  1. loop through query images in a directory
  2. for every image extract SIFT key-points and descriptors
  3. do a matching with every train/template image (again with SIFT)
  4. get the template image which has the best match (wrt minimum Euclidean distance for example?)
  5. use this best template image and compute the affine transformation between this template image and current query image.

Till now I am successful till step 3 and stuck at that point.

I am using Opencv 2.7.12 and python 2.7. Since there is no drawMatchesin this version, I am using this implementation.


Solution

  • Step 1: Run RANSAC on the matches you get from the BF-Match.

    Step 2: test the validity/goodness of the homography matrix like here

    Step 3: If the homography matrix is good, transform.

    Ofcourse Euclidean should work too