python - 属性错误 : 'module' object has no attribute 'ORB'

标签 python opencv opencv3.0

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

最佳答案

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

使用线

orb = cv2.ORB_create()

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

在 Python 3.4、Windows 上的 OpenCV 3 上验证,使用 OpenCV 测试数据集 box.pngbox_in_scene.png 得到以下结果。 注意你必须在 img3 = cv2.drawMatches(img1 ,kp1,img2,kp2,matches[:10], flags=2) 也 - 见 my answer回答你的其他问题。

box scene output

关于python - 属性错误 : 'module' object has no attribute 'ORB' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31630559/

相关文章:

c++ - 无法将 IplImage 类作为参数传递

linux - 使用opencv在linux中点击事件

c++ - 如何在没有插值的情况下获得未失真的图像

opencv - 级联分类器无法训练。检查使用的训练参数

c# - 如何避免 MinAreaRect 检测到的矩形旋转?

python - 计算归并排序的反转

python - 如何获取字典中特定键最大的字典?

python - 从 flask 中的文件存储对象中提取文件

python - 如果用户输入他们想再次玩,我如何才能在 python 中选择你自己的冒险故事来重新开始?

python - 如何在CV2中的图像上使用orb?