OpenCV:BFmatcher由于不同的描述符形状而崩溃

2024-10-01 19:19:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用相同大小的二进制图像,提取ORB特征,但是当要比较描述符时,我收到一个:

错误

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

但是当我用

print img.dtype, np.shape(img), np.shape(descriptors)
print oldimg.dtype, np.shape(oldimg), np.shape(olddescriptors)

我明白了

^{pr2}$

显然这似乎是个错误。另一方面,我也无能为力。有人知道吗?至少网上有一些关于如何手动匹配描述符的教程?在

顺便说一句,如果我使用SIFT、SURF等,也是一样的

这是我的代码:

我正在使用python2.7和opencv2.4

    orb = cv2.ORB_create(edgeThreshold=3)
    oldkeypoints, olddescriptors = orb.detectAndCompute(oldimg,None)
    keypoints, descriptors = orb.detectAndCompute(img,None) 

    bf = cv2.BFMatcher(cv2.NORM_HAMMING)
    bf.clear()
    bf.add(olddescriptors)
    bf.train()

    matches = bf.match(descriptors) # crashes here
    matches = sorted(matches, key = lambda x:x.distance)

Tags: imgtype错误npcv2描述符descriptorsmatches

热门问题