属性错误:'module'对象没有属性'ORB'。

20

当我运行我的Python代码时

import numpy as np
import cv2
import matplotlib.pyplot as plt

img1 = cv2.imread('/home/shar/home.jpg',0)          # queryImage
img2 = cv2.imread('/home/shar/home2.jpg',0) # trainImage

# Initiate SIFT detector
orb = cv2.ORB()

# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

# Match descriptors.
matches = bf.match(des1,des2)

# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)

# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)

plt.imshow(img3),plt.show()

我遇到了这个错误:

AttributeError: 'module' object has no attribute 'ORB' 

我正在使用Python3和OpenCV3

1个回答

54

我也发现了这个问题。我查看了 cv2 模块的实际内容,发现应该使用 ORB_create() 而不是 ORB()

请使用以下代码:

orb = cv2.ORB_create()

改为 orb = cv2.ORB_create() 就可以了。

在Windows上使用Python 3.4和OpenCV 3,使用OpenCV测试数据集box.pngbox_in_scene.png进行验证,结果如下。请注意,在img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)行中,还需要将outImg参数设置为None,参见我的回答中对于你的另一个问题的解答。

box scene output


create_ORB() 还是 ORB_create()?你在文本中使用了一个,但在代码中使用了另一个。 - kindall
1
抱歉 - 打错字了。@berak 友好地编辑了一个实例,但是错过了另一个。当我打字时,这里已经很晚了,这是我的唯一借口 :) 两个都更正为 ORB_create() - J Richard Snape
我能实时匹配特征吗? - Allan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接