AttributeError:“module”对象没有属性“ORB”

2024-06-16 09:31:11 发布

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

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


Tags: theimporthomeaspltcv2jpgimg1
1条回答
网友
1楼 · 发布于 2024-06-16 09:31:11

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

使用线条

orb = cv2.ORB_create()

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

在Python 3.4上验证,在Windows上验证opencv3,使用OpenCV测试数据集box.pngbox_in_scene.png,结果如下。注意您必须在第img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)行中为outImg输入None,另一个问题请参见my answer

box scene output

相关问题 更多 >