Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV and Python: Problems with knnMatch arguments

I am trying to follow the opencv tutorial here. Unfortunately, it fails at flann.knnMatch(des1,des2,k=2). Here is my code:

import cv2
import time
import numpy as np

im1 = cv2.imread('61_a.tif')
im2 = cv2.imread('61_b.tif')

surf = cv2.SURF(500,3,4,1,0) 
print "Detect and Compute"
kp1 = surf.detect(im1,None)
kp2 = surf.detect(im2,None)

des1 = surf.compute(im1,kp1)
des2 = surf.compute(im2,kp2)

MIN_MATCH_COUNT = 5
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks = 50)

flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(des1,des2,k=2)

I get the error:

matches = matcher.knnMatch(des1,des2,k=2)
TypeError: Argument given by name ('k') and position (2)

I have tried to change the matching to mirror the fix in this question like so:

flann = cv2.flann_Index(des2, index_params)
matches = flann.knnMatch(des1,2,params={})

BUT then I get this error:

flann = cv2.flann_Index(des2, index_params)
TypeError: features is not a numerical tuple

I'm really not sure what I'm doing wrong. Can someone point me in the right direction?

If you happen to know of a working PYTHON example of SURF or ORB for panorama/stitching that's fairly straightforward, I would appreciate that too. I have googled around quite a bit and have only found pieces of operations about how it might be accomplished (or it's written in C) or have only found unfinished/broken examples.

Thanks!

click to hide/show revision 2
retagged

updated 2015-10-12 00:33:01 -0600

berak gravatar image

OpenCV and Python: Problems with knnMatch arguments

I am trying to follow the opencv tutorial here. Unfortunately, it fails at flann.knnMatch(des1,des2,k=2). Here is my code:

import cv2
import time
import numpy as np

im1 = cv2.imread('61_a.tif')
im2 = cv2.imread('61_b.tif')

surf = cv2.SURF(500,3,4,1,0) 
print "Detect and Compute"
kp1 = surf.detect(im1,None)
kp2 = surf.detect(im2,None)

des1 = surf.compute(im1,kp1)
des2 = surf.compute(im2,kp2)

MIN_MATCH_COUNT = 5
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks = 50)

flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(des1,des2,k=2)

I get the error:

matches = matcher.knnMatch(des1,des2,k=2)
TypeError: Argument given by name ('k') and position (2)

I have tried to change the matching to mirror the fix in this question like so:

flann = cv2.flann_Index(des2, index_params)
matches = flann.knnMatch(des1,2,params={})

BUT then I get this error:

flann = cv2.flann_Index(des2, index_params)
TypeError: features is not a numerical tuple

I'm really not sure what I'm doing wrong. Can someone point me in the right direction?

If you happen to know of a working PYTHON example of SURF or ORB for panorama/stitching that's fairly straightforward, I would appreciate that too. I have googled around quite a bit and have only found pieces of operations about how it might be accomplished (or it's written in C) or have only found unfinished/broken examples.

Thanks!