Tuesday, 15 July 2014

OpenCV and Python: Problems with knnMatch arguments -



OpenCV and Python: Problems with knnMatch arguments -

i trying follow opencv tutorial here. unfortunately, fails @ flann.knnmatch(des1,des2,k=2). here code:

import cv2 import time import numpy np im1 = cv2.imread('61_a.tif') im2 = cv2.imread('61_b.tif') surf = cv2.surf(500,3,4,1,0) print "detect , 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 error:

matches = matcher.knnmatch(des1,des2,k=2) typeerror: argument given name ('k') , position (2)

i have tried alter matching mirror fix in question so:

flann = cv2.flann_index(des2, index_params) matches = flann.knnmatch(des1,2,params={})

but error:

flann = cv2.flann_index(des2, index_params) typeerror: features not numerical tuple

i'm not sure i'm doing wrong. can point me in right direction?

if happen know of working python illustration of surf or orb panorama/stitching that's straightforward, appreciate too. have googled around quite bit , have found pieces of operations how might accomplished (or it's written in c) or have found unfinished/broken examples.

thanks!

surf.compute() returns both keypoints , descriptors lists. flann.knnmatch() gets confused because des1 pair of lists , instead of k=1 finds pair of lists (namely des2). check shape() of des1 , des2.

either pass des1[1] , des2[1] flann.knnmatch() or utilize surf.detectandcompute() in replacement of surf.detect() , surf.compute().

python opencv image-processing

No comments:

Post a Comment