BFMatcher match giving error

asked 2016-10-09 11:37:05 -0600

motiur_uw gravatar image

I am using SURF descriptors for image matching. I am planning to match a given image to a database of images.

import cv2
import numpy as np
surf = cv2.xfeatures2d.SURF_create(400)

img1 = cv2.imread('box.png',0)
img2 = cv2.imread('box_in_scene.png',0)

kp1,des1 = surf.detectAndCompute(img1,None)
kp2,des2 = surf.detectAndCompute(img2,None)


bf = cv2.BFMatcher(cv2.NORM_L1,crossCheck=True)
#I am planning to add more descriptors
bf.add(des1)

bf.train()

#This is my test descriptor
bf.match(des2)

The issue is with bf.match is that I am getting the following error:

OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in batchDistance, file /build/opencv/src/opencv-3.1.0/modules/core/src/stat.cpp, line 3749
Traceback (most recent call last):
  File "image_match4.py", line 16, in <module>
    bf.match(des2)
cv2.error: /build/opencv/src/opencv-3.1.0/modules/core/src/stat.cpp:3749: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function batchDistance

The error is similar to this post. The explanation given is incomplete and inadequate.I want to know how to resolve this issue. I have used ORB descriptors as well with BFMatcher having NORM_HAMMING distance. The error resurfaces. Any help will be appreciated.

The two images that I have used for this are:

box.png

box.png

box_in_scene.png

box_in_scene.png

I am using Python 3.5.2 and OpenCV 3.1.x in linux.

edit retag flag offensive close merge delete

Comments

for a start, NORM_L2 would be more adequate.

berak gravatar imageberak ( 2016-10-09 12:00:16 -0600 )edit

It does not work, still giving the same error.

motiur_uw gravatar imagemotiur_uw ( 2016-10-09 12:44:06 -0600 )edit
1

I am planning to match a given image to a database of images.

apart from your current problems, you might be on the wrong track entirely.

feature matching answers the "where" question (where in image B are the features from image A), what you want is "what" (classification), and you will need some more sophisticated "matching" for this, like bow + svm

berak gravatar imageberak ( 2016-10-09 23:43:49 -0600 )edit

I asked the question is stackoverflow - I think I got my answer: http://stackoverflow.com/questions/39...

motiur_uw gravatar imagemotiur_uw ( 2016-10-10 02:33:22 -0600 )edit