2016-06-09 250 views
1

不绘制匹配。 Opencv 3.0,完全更新的Ubuntu。代码运行但不显示任何匹配。测试区域直接剪切并从图像中复制以匹配。Opencv。 cv2.drawMatches()不绘制匹配。 Opencv 3.0

import numpy as np 
import cv2 

cv2.ocl.setUseOpenCL(False) 


img1 = cv2.imread('images/ingrassroi.png',0) 
img2 = cv2.imread('images/ingrass.png',0) 

img3 = img1.copy() 

# Initiate ORB detector 
orb = cv2.ORB_create() 

# compute the descriptors with ORB 
kp1, des1 = orb.detectAndCompute(img1,None) 
kp2, des2 = orb.detectAndCompute(img2,None) 

# create BFMatcher object 
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) 

# Match descriptors. 
matches = bf.match(des1,des2) 

# Sort them in the order of their distance. 
matches = sorted(matches, key = lambda x:x.distance) 

# Draw first 10 matches. 
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2) 

cv2.imshow("Matches",img3) 
cv2.waitKey(-1) 

Picture to match

Test image

Matches

回答

0

事实证明,以配合图像太小了。在火车图像中找不到任何关键点。我放大了从测试图像中裁剪出的区域,发现匹配并正确识别图像中的烟蒂。如果你决定尝试在OpenCV的Python的教程在同一页上基于FLANN匹配只是一个供参考,请务必确定FLANN_INDEX_LSH = 6