2015-07-25 40 views
16

quando eseguo il mio codice PythonAttributeError: oggetto 'modulo' non ha alcun attributo 'ORB'

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() 

ottengo questo errore:

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

Sto usando python3 e opencv3

risposta

48

Ho trovato anche questo. Ho controllato il contenuto effettivo del modulo cv2 e ho trovato ORB_create() piuttosto che ORB()

Utilizzare la linea

orb = cv2.ORB_create() 

invece di orb = cv2.ORB() e funzionerà.

Verificato su Python 3.4, OpenCV 3 su Windows, utilizzando il set di dati di prova OpenCV box.png e box_in_scene.png con i seguenti risultati. Nota devi inserire None per outImg nella riga img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2) anche - vedi my answer per la tua altra domanda.

box scene output

+0

Il che è vero, 'create_ORB()' o 'ORB_create()'? Ne usi uno nel tuo testo ma l'altro nel tuo codice. – kindall

+1

Mi spiace - errore di battitura. @berak ha gentilmente curato un'istanza, ma ha mancato l'altra. Era tardi quando ho digitato è la mia unica scusa :) Entrambi corretti per 'ORB_create()' –

+0

posso abbinare la funzione in tempo reale? – Allan

Problemi correlati