python - 使用python open cv(ORB)进行图像比较
问题描述
我的要求是匹配图像,并且应该显示该功能是否存在。这些是我正在使用的 2 张图片,
我使用下面的代码来匹配 2 个图像的特征,但它没有给出正确的匹配,所以你有任何匹配选项或任何其他想法,还是我需要更改下面给出的编码。
`enter code here`
import cv2
import matplotlib.pyplot as plt
cv2.__version__
img1 = cv2.imread('D:/Notsaved/naiduv/Images/img3.png')
img2 = cv2.imread('D:/Notsaved/naiduv/Images/img1.png')
#cv2.imshow('img',img1)
#sift = cv2.xfeatures2d.SIFT_create()
#kp = sift.detect(img1,None)
#img=cv2.drawKeypoints(gray,kp,img)
#cv2.imwrite('sift_keypoints.jpg',img)
#cv2.waitKey(0)
#cv2.destroyAllwindows()
orb = cv2.ORB_create()
kp1,des1 = orb.detectAndCompute(img1,None)
kp2,des2 = orb.detectAndCompute(img2,None)
for d in des2:
print(d)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
#matches = sorted(matches, key = lambda x:x.distance)
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:1],None, flags=2)
plt.imshow(img3)
plt.show()
https://i.stack.imgur.com/e8ljO.png
https://i.stack.imgur.com/cSuer.png
https://i.stack.imgur.com/6BDlK.png
解决方案
推荐阅读
- typescript - 为什么只有在 else 里面时打字稿不抱怨没有回报?
- python - 如何告诉 argparse 只允许一个参数一次?
- c# - 为什么 .net 核心 Web API 在 IIS 上发布时会收到损坏的数据,但使用 VS Studio+IIS express 可以?
- java - Tomcat崩溃没有错误
- javascript - finalData 不是函数
- python - 在数据框中的第一个下划线之后从值创建新列
- reactjs - 反应 - 单击按钮后状态设置为 null
- git - 我在 GitHub 上收到“您无权推送用户名/存储库”
- npm - npm WARN 已弃用 uuid@3.4.0:请升级到版本 7 或更高版本
- python - 尝试使用 Python 从 Google 表格中获取值时出现 RefreshError 异常