Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Argument given by name ('k') and position (2)

Find below my opencv3 Python3 code to match objects which raises the following error:

TypeError: Argument given by name ('k') and position (2)

Here's the code:

import numpy as np
import cv2
import time
import distance
camera = cv2.VideoCapture(0)
sift = cv2.xfeatures2d.SIFT_create()
img = cv2.imread('/home/shar/bo.jpg')
imgTrainGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kpTrain = sift.detect(imgTrainGray,None)
kpTrain, desTrain = sift.compute(imgTrainGray, kpTrain)
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(kpTrain,desTrain,k=2)

Ideas on how to fix it?

like image 916
shar Avatar asked Jul 31 '15 06:07

shar


2 Answers

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)
like image 98
Tarun Avatar answered Oct 11 '22 16:10

Tarun


You are trying to match keypoints and the descriptors - which is wrong. You need two images, first you find the keypoints in both of the images (points of interest). Then for each point you calculate a descriptor (again in both images). Finally, you use the Flann to find matches between the two images. See the example here.

like image 22
GStav Avatar answered Oct 11 '22 15:10

GStav