【发布时间】:2017-02-17 20:11:54
【问题描述】:
我正在使用 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
错误类似于this 帖子。给出的解释不完整且不充分。我想知道如何解决此问题。我也使用了 ORB 描述符以及具有NORM_HAMMING 距离的 BFMatcher。错误再次出现。
任何帮助将不胜感激。
我为此使用的两张图片是:
box.png
box_in_scene.png
我在 linux 中使用 Python 3.5.2 和 OpenCV 3.1.x。
【问题讨论】:
-
所以
.detectAndCompute出现在 OpenCV 3x 及以上版本中?我使用的是 2.4,上面写着module object not found... -
取决于opencv版本。遵循 2.4 或 3.x。