2016-06-09 255 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