# FlannBasedMatcher does not always return match

Hello, I am trying to use a Bag of Words approach using ORB with opencv. I have implemented it with SURF but I want an open source implementation (patent free). Because ORB uses int descriptors and the BoW uses float I am having to workaround the issue.

Although I am not sure is formally correct ( as far as I have read in some forums), I am trying the approach of converting the ints to floats, if just to understand better the library, what produces consistent results with my understanding of the algorithm. For each of the of the images I have a set of features and when matched to the vocabulary(BoW) I get for each element of it a distance:

flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
matcher = cv2.FlannBasedMatcher(flann_params, {})
matches = np.array(map(lambda x:matcher.match(vocabulary, x),features))
print map(lambda x:map(lambda x:x.distance, x),matches)

[[266.196044921875, 307.2073059082031, 259.8791809082031, 261.4696350097656, 287.9962158203125], [305.16058349609375, 286.4377746582031, 257.6868896484375, 262.8175354003906, 236.08583068847656], [308.6315612792969, 249.69607543945312, 296.937255859375, 271.01116943359375, 271.5191345214844], [318.60693359375, 336.37493896484375, 370.28155517578125, 266.39111328125, 249.41949462890625], [324.78857421875, 315.8425598144531, 334.93133544921875, 272.6943359375, 293.9166564941406], [266.48431396484375, 341.8405456542969, 265.0736389160156, 268.8377685546875, 298.9530334472656]]


But when I do it for the case in which I convert to ints the vocabulary, the list is not complete, meaning that I do not always obtain 5 results. I have tried modifying the flann parameters but I haven´t obtained any change in the behaviour:

flann_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 12, # 12 # 6
key_size = 20,     # 20 # 12
multi_probe_level = 2) #2  #1
matcher = cv2.FlannBasedMatcher(flann_params, {})
matches = np.array(map(lambda x:matcher.match(vocabulary, x),features))
print map(lambda x:map(lambda x:x.distance, x),matches)

[[124.0, 118.0], [114.0, 125.0], [125.0, 116.0, 115.0], [126.0], [], [117.0, 120.0]]


What am I doing or understanding wrong? Is this a good approach ? Is there a threshold to be tuned to force that there is always a value returned? I am using version 2.4.10 of opencv (I can´t migrate to 3.0 for environment issues) with the WinPython 2.7.10.1 64 bits distribution

edit retag close merge delete