3

I'm training a BFMatcher with 4 descriptors:

bf = cv2.BFMatcher()

bf.clear()
bf.add(des1)
bf.add(des2)
bf.add(des3)
bf.add(des4)
bf.train()

bf.match(des1)

The code bf.match(des1) throws this error:

error: ..\..\..\..\opencv\modules\core\src\stat.cpp:2473: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function cv::batchDistance

What could be the cause of this ? The descriptors are ORB descriptors.

Tarantula
  • 19,031
  • 12
  • 54
  • 71

2 Answers2

4

You are right, you can add descriptors in lists but you can only match with single descriptors, so, go over the whole des1 array and match every single descriptor and save the matches in a list, or a set if you don't want them to be repeated!

matches = set()
for desc in desc1:
    matches_img = bf.knnMatch(desc,k=2)
    for match in matches_img:
        matches.add(match)
alex_vkcr
  • 64
  • 5
0

you should use:

    bf  = cv2.BFMatcher(cv2.NORM_HAMMING)

when using ORB. The error shows that the type used for ORB descriptor is not supported with the defualt L2 distance of the matcher.

QED
  • 808
  • 8
  • 11
  • I changed as you mentioned and the problem continues. The same error message is shown – Tarantula Jun 14 '14 at 23:19
  • okay, well, does the matching work at all on just two ORBs like bf.match(des1, des2), withou any training. like here: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html – QED Jun 14 '14 at 23:32
  • okay so now try training but only with those two des1 and des2. It may be one of those other desc is a different size, as in the error is has "src1.cols == src2.cols" – QED Jun 14 '14 at 23:42
  • All descriptors (des1, des2, des3, des4) have the same shape, which is 500 rows and 32 columns. – Tarantula Jun 14 '14 at 23:45
  • that's strange as the error seems to say either they are wrong types or sizes. Did it work when training just from desc1 and desc2. – QED Jun 14 '14 at 23:48
  • 1
    It seems that I haven't understood what is the correct input of the `match` method, if I run `ma = bf.match(des1[0])` it works fine. – Tarantula Jun 14 '14 at 23:51