Reputation:
I am trying to use the code from this link: OpenCV python's API: FlannBasedMatcher
However, I am receiving the error:
File "C:\Users\User\Desktop\lktracker\lktrack.py", line 22, in match_flann
flann = cv2.flann_Index(desc2, flann_params)
TypeError: features is not a numpy array, neither a scalar
Here is the part of my code that makes a call to the FLANN function:
for i in range(rowsInOrigDes):
for j in range(rowsInNextDes):
origDesArr = np.array(origDes[i,:])
nextDesArr = np.array(nextDes[j,:])
origDesArr = [float(x) for x in origDesArr]
nextDesArr = [float(x) for x in nextDesArr]
b = match_flann(origDesArr, nextDesArr, r_threshold = 0.6)
if b:
print b
Am I using this function correctly? I'm not sure what to declare b
either..
If anyone can help out with this, I'd greatly appreciate it.
Upvotes: 1
Views: 2094
Reputation:
The problem is that features
is a list, not a numpy array. That's what the TypeError tells you.
Flann only accepts numpy arrays of type float32.
It's a little hard to give you a solution without seeing your entire code, but it is quite simple. Here is a complete tutorial for OpenCV FLANN based matching in Python: https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html
Note that it based on OpenCV 3.0.0 dev version, but it should be pretty easy to adapt to the version of your choice.
Upvotes: 3