2016-09-20 57 views

回答

0

模板匹配不工作你的情況。模板匹配僅適用於源代碼中幾乎相同的模板。 我建議使用dlib http://dlib.net/ml.html進行深度學習。 這很容易學習,你不需要寫很多代碼。如果你仍然想使用模板匹配,你可以嘗試以下操作:

import cv2 

source = cv2.imread("/source/of/your_stop_sign") 
template = cv2.imread("our/template") 
(tempH, tempW) = template.shape[:2] 

試圖找到模板:

result = cv2.matchTemplate(source, template, cv2.TM_CCOEFF) 
(minVal, maxVal, minLoc, (x, y)) = cv2.minMaxLoc(result) 

繪製邊框

cv2.rectangle(source, (x, y), (x + tempW, y + tempH), (0, 255, 0), 2) 

顯示結果

cv2.imshow("source", source) 
cv2.imshow("template", template) 
cv2.waitKey(0) 

Template Source Result