Skip to content

Instantly share code, notes, and snippets.

@saurabhpal97
Created March 23, 2019 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabhpal97/897cc9f3ed0e0e186b4ac26ce00ee4e6 to your computer and use it in GitHub Desktop.
Save saurabhpal97/897cc9f3ed0e0e186b4ac26ce00ee4e6 to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
#reading images in grayscale format
image1 = cv2.imread('messi.jpg',0)
image2 = cv2.imread('team.jpg',0)
#finding out the keypoints and their descriptors
keypoints1,descriptors1 = cv2.detectAndCompute(image1,None)
keypoints2,descriptors2 = cv2.detectAndCompute(image2,None)
#matching the descriptors from both the images
bf = cv2.BFMatcher()
matches = bf.knnMatch(ds1,ds2,k = 2)
#selecting only the good features
good_matches = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append([m])
image3 = cv2.drawMatchesKnn(image1,kp1,image2,kp2,good,flags = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment