pal*_*avi 6 python opencv surf
我正在尝试使用函数 SURF() 进行特征匹配的代码。执行时它会给出一个错误,说“AttributeError:'module' object has no attribute 'SURF'”。
如何为 Python (Windows) 下载此模块并修复此错误?
您可以在 open cv 中尝试ORB(Oriented FAST and Rotated Brief)作为 SURF 的替代。它几乎和 SURF 和 SIFT 一样好用,而且它是免费的,不像SIFT和SURF是专利的,不能用于商业用途。
您可以在此处的opencv-python 文档中了解更多
信息
这是为您提供方便的示例代码
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9437 次 |
| 最近记录: |