Guest User

Untitled

a guest
Jul 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. img1 = cv2.imread('opencv-feature-matching-template.jpg',0) # provide 2 images, one for image and another for template
  6. img2 = cv2.imread('opencv-feature-matching-image.jpg',0)
  7.  
  8. orb = cv2.ORB_create()
  9.  
  10. kp1, des1 = orb.detectAndCompute(img1, None)
  11. kp2, des2 = orb.detectAndCompute(img2, None)
  12.  
  13. bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck = True)
  14.  
  15. matches = bf.match(des1, des2)
  16. matches = sorted(matches, key = lambda x: x.distance)
  17.  
  18. img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2)
  19.  
  20. plt.imshow(img3)
  21. plt.show()
Add Comment
Please, Sign In to add comment