2016-09-20 124 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