我正在使用SIFT特征提取进行OCR。
import cv2
import matplotlib.pyplot as plt
import numpy as np
img1=cv2.imread('/Users/amuly/Desktop/Soap/training data/d000.jpg')
img_temp=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
img2=cv2.imread('/Users/amuly/Desktop/Soap/test/dot matrix/5.jpg')
img_scene=cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
sift=cv2.xfeatures2d.SIFT_create()
kps1, descs1 = sift.detectAndCompute(img_temp, None)
kps2, descs2 = sift.detectAndCompute(img_scene, None)
# create BFMatcher object
bf = cv2.BFMatcher()
# Match descriptors.
matches = bf.knnMatch(descs1,descs2,k=2)
print matches
#Apply Ratio test
good = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append([m])
print good
# Draw matches which is giving me an error
img3 = cv2.drawMatches(img1,kps1,img2,kps2,good,None,flags=2)
错误是
预期的cv :: DMatch for argument&#39;匹配1to2&#39;
我在good[]
中有匹配,然后在drawMatches()
传递。
plt.imshow(img3)
plt.show()
答案 0 :(得分:0)
使用img3 = cv2.drawMatchesKnn(img1,kps1,img2,kps2,good,None,flags = 2)代替,它应该可以工作。