AttributeError:“模块”对象没有属性“ORB”

Posted

技术标签:

【中文标题】AttributeError:“模块”对象没有属性“ORB”【英文标题】:AttributeError: 'module' object has no attribute 'ORB' 【发布时间】:2015-10-16 07:24:19 【问题描述】:

当我运行我的 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】:

我也发现了这个。我检查了cv2模块的实际内容,发现ORB_create()而不是ORB()

使用线

orb = cv2.ORB_create()

而不是orb = cv2.ORB(),它会起作用。

使用 OpenCV 测试数据集 box.pngbox_in_scene.png 在 Windows 上的 Python 3.4、OpenCV 3 上验证,结果如下。 注意您还必须在 img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2) 行中输入 None for outImg - 请参阅 my answer 到您的其他问题。

【讨论】:

这是create_ORB() 还是ORB_create()?您在文本中使用一个,而在代码中使用另一个。 对不起 - 错字。 @berak 好心地编辑了一个实例,但错过了另一个。我输入的时候已经很晚了,这是我唯一的借口:) 都更正为ORB_create() 可以实时匹配特征吗?

以上是关于AttributeError:“模块”对象没有属性“ORB”的主要内容,如果未能解决你的问题,请参考以下文章

AttributeError:“模块”对象没有属性

AttributeError:“模块”对象没有属性“百分位”

AttributeError:“模块”对象没有属性

无法安装模块 - AttributeError: 'NoneType' 对象没有属性 'loader'

AttributeError:“模块”对象没有属性“urlopen”

AttributeError:“模块”对象没有属性“ORB”