import numpy as np
import cv2
from matplotlib import pyplot as plt

img1 = cv2.imread('fieldc.jpg', cv2.IMREAD_COLOR)
img2 = cv2.imread('excard.jpg', cv2.IMREAD_COLOR)

# Initiate SIFT detector
sift = cv2.SIFT()

# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)

# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)

# Apply ratio test
good = []
for m,n in matches:
    if m.distance < 0.75*n.distance:
        good.append([m])

# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)

plt.imshow(img3),plt.show()
721f914f91ddbb0a1d6661039f7c391d90f35e8c
<mask token>

<mask token>
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good.append([m])
<mask token>
plt.imshow(img3), plt.show()

<mask token>
img1 = cv2.imread('fieldc.jpg', cv2.IMREAD_COLOR)
img2 = cv2.imread('excard.jpg', cv2.IMREAD_COLOR)
sift = cv2.SIFT()
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
good = []
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good.append([m])
img3 = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, flags=2)
plt.imshow(img3), plt.show()

import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('fieldc.jpg', cv2.IMREAD_COLOR)
img2 = cv2.imread('excard.jpg', cv2.IMREAD_COLOR)
sift = cv2.SIFT()
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
good = []
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good.append([m])
img3 = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, flags=2)
plt.imshow(img3), plt.show()

import numpy as np
import cv2
from matplotlib import pyplot as plt

img1 = cv2.imread('fieldc.jpg', cv2.IMREAD_COLOR)
img2 = cv2.imread('excard.jpg', cv2.IMREAD_COLOR)

# Initiate SIFT detector
sift = cv2.SIFT()

# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)

# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)

# Apply ratio test
good = []
for m,n in matches:
    if m.distance < 0.75*n.distance:
        good.append([m])

# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)

plt.imshow(img3),plt.show()