The functions cv2.drawMatches and cv2.drawMatchesKnn are not available in newer versions of OpenCV 2.4. @rayryeng provided a lightweight alternative which works as is for the output of DescriptorMatcher.match. The difference with DescriptorMatcher.knnMatch is that the matches are returned as a list of lists. To use the @rayryeng alternative, the matches must be extracted into a 1-D list.

For example, the Brute-Force Matching with SIFT Descriptors and Ratio Test tutorial could be amended as such:

# 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:
       # Removed the brackets around m 
       good.append(m)

# Invoke @rayryeng's drawMatches alternative, note it requires grayscale images
gray1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
drawMatches(gray1,kp1,gray2,kp2,good)

转自  https://stackoverflow.com/questions/20172953/opencv-python-no-drawmatchesknn-function   参考链接:

相关文章:

  • 2021-12-20
  • 2021-12-30
  • 2022-12-23
  • 2022-01-20
  • 2021-05-26
  • 2022-01-22
  • 2021-09-24
  • 2022-12-23
猜你喜欢
  • 2021-10-19
  • 2022-12-23
  • 2021-09-08
  • 2022-01-16
  • 2021-06-22
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案