I am getting an error:
line 33, in <module>
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches,None,flags=2)
TypeError: Expected cv::DMatch for argument 'matches1to2'
When I try to execute this code. It is supposed to be a simple image comparison in SIFT and plot the matches. I previously had the code working for ORB, but when I converted it to work for SIFT this error occurred. Can someone please help me out with this? The code is below:
#import os
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
import cv2
import time
import glob, os
import numpy as np
import matplotlib.pyplot as plt
img1 = cv2.imread("/home/undead/Documents/TestSpectro/test.png",0)
img2 = cv2.imread("/home/undead/Documents/LibrarySpectro/ThankYouAud.png",0)
sift = cv2.xfeatures2d.SIFT_create(3000)
kp1,des1 = sift.detectAndCompute(img1,None)
kp2,des2 = sift.detectAndCompute(img2,None)
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2,k=2)
good = []
for m,n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
#img3 = cv2.drawMatches(img1,kp1,img2,kp2,good,None,flags=2)
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches,None,flags=2)
plt.imshow(img3),plt.show()
UPDATE Found the problem, the line in question should be:
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,flags=2)