There is a FLANN implementation for Python OpenCV, I used it myself, and it works very well. Initially, it was not easy to understand, but this question helped me a lot, see Esteban Angers answer.
You can also see my answer to this question , where I quickly explained the code. I repeat the explanation here.
r_threshold = 0.6 FLANN_INDEX_KDTREE = 1
Build a parameter dictionary:
flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 4) flann = cv2.flann_Index(desc2, flann_params)
Search for nearby neighbors:
idx2, dist = flann.knnSearch(desc1, 2, params = {}) # bug: need to provide empty dict mask = dist[:,0] / dist[:,1] < r_threshold idx1 = np.arange(len(desc1)) pairs = np.int32( zip(idx1, idx2[:,0]) )
Returns descriptors that match:
return pairs[mask]
source share