vlfeat's vl_ubcmatch
Hi, Is there any alternative in opencv for vlfeat's vl_ubcmatch for matching sifts between two images? If not, can you suggest an implementation that can be used from python?
Thanks!
Hi, Is there any alternative in opencv for vlfeat's vl_ubcmatch for matching sifts between two images? If not, can you suggest an implementation that can be used from python?
Thanks!
I ended up implementing vl_ubcmatch in python. Short and sweet :)
def find_matches(template_descriptors, current_img_descriptors, match_thresh):
flann_params = dict(algorithm=1, trees=4)
flann = cv2.flann_Index(current_img_descriptors, flann_params)
idx, dist = flann.knnSearch(template_descriptors, 2, params={})
del flann
matches = np.c_[np.arange(len(idx)), idx[:,0]]
pass_filter = dist[:,0]*match_thresh < dist[:,1]
matches = matches[pass_filter]
return matches
If you want a c++ version, this guy extracted the cpp code from vlfeat's mex code in his blog.
In the comments, he gives a link to his cpp file with the code (change the extension from txt to cpp).
Partially, you can use BFMatcher() for the first definition of vl_ubcmatch (http://www.vlfeat.org/matlab/vl_ubcmatch.html). Although not mentioned in the documentation of BFMatcher, it is also available under python (see also <your-opencv-folder>/samples/python2/find_obj.py):
>>> import cv2
>>> ? cv2.BFMatcher
Type: builtin_function_or_method
String Form:<built-in function BFMatcher>
Docstring: BFMatcher([, normType[, crossCheck]]) -> <BFMatcher object>
The second variant (i.e. the pruning of the results with a threshold) you would have to code yourself, this ratio-test is however pretty easy to accomplish see e.g. http://answers.opencv.org/question/4829/how-to-filter-freakbruteforcematcher-result/ .
In general, however, not each vlfeat-method is that easily adaptable with OpenCV, I wish there would be some work to fuse both great libraries...
Asked: 2013-11-03 04:33:15 -0600
Seen: 2,035 times
Last updated: Nov 05 '13