AttributeError:“模块"对象没有属性"ORB" [英] AttributeError: 'module' object has no attribute 'ORB'
问题描述
当我运行python代码时
when I run my python code
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
I am using python3 and opencv3
推荐答案
我也发现了这一点.我检查了cv2
模块的实际内容,发现是ORB_create()
而不是ORB()
I found this also. I checked the actual contents of the cv2
module and found ORB_create()
rather than ORB()
使用线路
orb = cv2.ORB_create()
代替orb = cv2.ORB()
,它将起作用.
使用OpenCV测试数据集box.png
和box_in_scene.png
在Windows 3.4上的Python 3.4,OpenCV 3上进行了验证,并具有以下结果. 注意 ,您还必须在img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)
行中为outImg
输入None
.-请参见
Verified on Python 3.4, OpenCV 3 on Windows, using the OpenCV test data set box.png
and box_in_scene.png
with the following results. Note you have to put in None
for outImg
in the line img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)
also - see my answer to your other question.
这篇关于AttributeError:“模块"对象没有属性"ORB"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!