我正在使用SURF描述符进行图像匹配。我计划将给定的图像与图像数据库进行匹配。
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)
问题出在 bf.match
上,我遇到了以下错误:
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
错误与此帖子相似。所给出的解释是不完整和不充分的。我想知道如何解决这个问题。我也使用了ORB描述符,并用NORM_HAMMING
距离的BFMatcher。但错误仍然存在。
非常感谢您的任何帮助。
我使用的两张图片为:
box.png
box_in_scene.png
我正在使用Python 3.5.2和OpenCV 3.1.x在linux上。
.detectAndCompute
是从OpenCV 3x及以上版本开始出现的吗?我正在使用2.4版本,但它显示“找不到模块对象”... - alisa