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?
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With