Guest User

Untitled

a guest
Jun 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. print(rgb.shape, rotated.shape)
  2. H = cv2.findHomography(rgb, rotated)
  3. print(H)
  4.  
  5. (1080, 1920, 3) (1080, 1920, 3)
  6. ---------------------------------------------------------------------------
  7. error Traceback (most recent call last)
  8. <ipython-input-37-26874dc47f1f> in <module>()
  9. 1 print(rgb.shape, rotated.shape)
  10. ----> 2 H = cv2.findHomography(rgb, rotated)
  11. 3 print(H)
  12.  
  13. error: OpenCV(3.4.1) C:projectsopencv-pythonopencvmodulescalib3dsrcfundam.cpp:372: error: (-5) The input arrays should be 2D or 3D point sets in function cv::findHomography
  14.  
  15. def findHomography(img1, img2):
  16.  
  17. # define constants
  18. MIN_MATCH_COUNT = 10
  19. MIN_DIST_THRESHOLD = 0.7
  20. RANSAC_REPROJ_THRESHOLD = 5.0
  21.  
  22. # Initiate SIFT detector
  23. sift = cv2.xfeatures2d.SIFT_create()
  24.  
  25. # find the keypoints and descriptors with SIFT
  26. kp1, des1 = sift.detectAndCompute(img1, None)
  27. kp2, des2 = sift.detectAndCompute(img2, None)
  28.  
  29. # find matches
  30. FLANN_INDEX_KDTREE = 1
  31. index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
  32. search_params = dict(checks=50)
  33.  
  34. flann = cv2.FlannBasedMatcher(index_params, search_params)
  35. matches = flann.knnMatch(des1, des2, k=2)
  36.  
  37. # store all the good matches as per Lowe's ratio test.
  38. good = []
  39. for m, n in matches:
  40. if m.distance < MIN_DIST_THRESHOLD * n.distance:
  41. good.append(m)
  42.  
  43.  
  44. if len(good) > MIN_MATCH_COUNT:
  45. src_pts = np.float32([kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
  46. dst_pts = np.float32([kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
  47.  
  48. H, _ = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, RANSAC_REPROJ_THRESHOLD)
  49. return H
  50.  
  51. else: raise Exception("Not enough matches are found - {}/{}".format(len(good), MIN_MATCH_COUNT))
Add Comment
Please, Sign In to add comment