I want to perform Brute Force SIFT features matching in Python with opencv.
I found the following code on the opencv documentation.
import numpy as np import cv2 from matplotlib import pyplot as plt img1 = cv2.imread('box.png',0) # queryImage img2 = cv2.imread('box_in_scene.png',0) # trainImage # 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]) # cv2.drawMatchesKnn expects list of lists as matches. img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2) plt.imshow(img3),plt.show()
However, this code is only for two images. I tried feeding a list of descriptors but it doesn't seem to work. How can I perform the matching of multiple database images at once ?
1 Answer
BFMatcher only works for two descriptors at a time. If you check out the documentation here: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html
Brute-Force matcher is simple. It takes the descriptor of one feature in first set and is matched with all other features in second set using some distance calculation. And the closest one is returned.
I am quite unsure with what you mean by multiple descriptors. However, I know you can take the descriptor from image1 matching with image2. Then, match image1 with image3. Lastly,image2 with image3. Matching multiple images' descriptors needs to be done manually.
2ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobGtsZWuFeH2OqKeeppOreqOyzJqrnKCVp3qnu9FmpK6kpJ69rbGMoqSan5Wo