首页 > 解决方案 > 使用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

标签: pythoncv2

解决方案


推荐阅读