Ask Your Question
5

OpenCV and Python: Problems with knnMatch arguments

asked 2014-06-19 07:59:24 -0500

angel.spatial gravatar image

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

berak gravatar image

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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-10-11 20:44:04 -0500

This worked for me

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(np.asarray(des1,np.float32),np.asarray(des2,np.float32),k=2)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-06-19 07:59:24 -0500

Seen: 2,579 times

Last updated: Oct 11 '15