A clarification with BFMatcher.knnMatch

asked 2015-09-03 10:35:09 -0600

desri gravatar image

updated 2015-09-03 12:01:53 -0600

LBerger gravatar image

Hi,

I am using Opencv-3.0.0 beta through Python 2.7.x , under Ubuntu 14.04 LTS. I am using the descriptor matching between two images through BFMatcher.knnMatch. I am doing the following commands:

orb = cv2.ORB_create(nfeatures=60);
kp1, des1 = orb.detectAndCompute(img1, None);
kp2, des2 = orb.detectAndCompute(img2, None);
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True);

Now when I issue the following command:

matches = bf.knnMatch(des1,des2); I get the following error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: only length-1 arrays can be converted to Python scalars

Can someone explain to me what does this mean? is it possible that ORB descriptors and keypoints are not compatible with knnMatch method?

Thanks

edit retag flag offensive close merge delete

Comments

1

when in doubt, - try the builtin help :

>>> help(bf.knnMatch)
Help on built-in function knnMatch:

knnMatch(...)
    knnMatch(queryDescriptors, trainDescriptors, k[, mask[, compactResult]]) ->
matches  or  knnMatch(queryDescriptors, k[, masks[, compactResult]]) -> matches

so, it pretty much looks like you forgot to supply the k param, and it mistook your des2 for k (version2)

berak gravatar imageberak ( 2015-09-04 01:04:41 -0600 )edit

I tried that and it still didn't work. It gave another error: cv2.error: /home/s0r2637/Downloads/opencv/modules/core/src/stat.cpp:3731: error: (-215) K == 1 && update == 0 && mask.empty() in function batchDistance

desri gravatar imagedesri ( 2015-09-04 11:26:09 -0600 )edit

what exactly did you do now?

berak gravatar imageberak ( 2015-09-04 12:15:25 -0600 )edit
1

I am sorry I did the following:

matches = bf.knnMatch(des1,des2, k=10);

desri gravatar imagedesri ( 2015-09-05 22:13:47 -0600 )edit