daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest May 17th, 2018 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import cv2
  3. from matplotlib import pyplot as plt
  4.  
  5. #read original picture
  6. img = cv2.imread('maluch.jpg')
  7. gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  8.  
  9. #move picture
  10. rows,cols = gray_image.shape
  11. M = np.float32([[1,0,100],[0,1,50]])
  12. img_moved = cv2.warpAffine(img,M,(cols,rows))
  13. img_moved_grey = cv2.cvtColor(img_moved, cv2.COLOR_BGR2GRAY)
  14.  
  15. #initialize FAST and ORB
  16. fast = cv2.FastFeatureDetector_create()
  17. orb = cv2.ORB_create()
  18.  
  19. #draw points on original image
  20. #fast
  21. kp = fast.detect(gray_image,None)
  22. print("Total Keypoints with nonmaxSuppression: ", len(kp));
  23. #img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))
  24. #cv2.imshow('original FAST', img2)
  25. #orb
  26. kp1, des1 = orb.compute(img, kp)
  27. #img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))
  28. #cv2.imshow('original ORB', img2)
  29.  
  30. #draw points on moved image
  31. #fast
  32. kp = fast.detect(img_moved_grey,None)
  33. print("Total Keypoints with nonmaxSuppression: ", len(kp));
  34. #img2 = cv2.drawKeypoints(img_moved, kp, None,color=(255,0,0))
  35. #cv2.imshow("Moved FAST",img2)
  36. #orb
  37. kp2, des2 = orb.compute(img_moved, kp)
  38. #img2 = cv2.drawKeypoints(img_moved, kp, None,color=(255,0,0))
  39. #cv2.imshow('moved ORB', img2)
  40.  
  41. # create BFMatcher object
  42. bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
  43.  
  44. # Match descriptors.
  45. matches = bf.match(des1,des2)
  46.  
  47. # Sort them in the order of their distance.
  48. matches = sorted(matches, key = lambda x:x.distance)
  49.  
  50. # Draw first 10 matches.
  51. img3 = cv2.drawMatches(img,kp1,img_moved,kp2,matches[:1000],None)
  52.  
  53. cv2.imshow('Compared', img3)
  54.  
  55.  
  56. cv2.waitKey(0)
  57. cv2.destroyAllWindows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top