我試圖爲特徵匹配其使用功能SURF代碼()。執行時,它會給出一個錯誤,說「AttributeError:'模塊'對象沒有屬性'SURF'」。如何利用海浪和篩選檢測器的OpenCV的Python
我怎麼可以下載這個模塊的Python(Windows)和解決這個錯誤?
我試圖爲特徵匹配其使用功能SURF代碼()。執行時,它會給出一個錯誤,說「AttributeError:'模塊'對象沒有屬性'SURF'」。如何利用海浪和篩選檢測器的OpenCV的Python
我怎麼可以下載這個模塊的Python(Windows)和解決這個錯誤?
您可以嘗試ORB(Oriented FAST and Rotated BRIEF)作爲SURF在開放式CV中的替代方案。它幾乎可以作爲SURF好過篩,它是免費的不像 SIFT 和 SURF 其中是專利並且不能用於商業用途。
可以OpenCV的-Python文檔 here
在這裏,更多的瞭解這對您的放心
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('text.png',cv2.COLOR_BGR2GRAY) # queryImage
img2 = cv2.imread('original.png',cv2.COLOR_BGR2GRAY) # trainImage
# Initiate SIFT detector
orb = cv2.ORB_create()
# 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],None, flags=2)
plt.imshow(img3),plt.show()
示例代碼起初
pip install opencv-contrib-python
,然後使用此技巧創建過篩對象
sift = cv2.xfeatures2d.SIFT_create()
我不知道那件事......會測試一下! – user1767754
它可以在opencv 2.7或2.4下運行嗎?因爲我得到了ORB的相同錯誤。 – pallavi
我用它打開cv 3.0 – Ahmed
@ pallavi請檢查編輯的答案。 – Ahmed