在我实验过程中发现,这种模板匹配如果不做任何处理只对原有图像进行匹配的话,好像效果很瓜
貌似是模板是1 那就只能检测出正常形态下的1,变大或者是 l 都不一定检测到,
也就是说,只能检测和模板图片大小尺寸颜色类别 一模一样的目标
这就表明,你如果用模板匹配做识别,不但要定位到目标,还要确保,定位到的位置和模板匹配图尺寸相同
简单匹配实现代码如下
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
def Template_img(input_img,trmplate):
img_rgb = cv.imread(input_img)
# img_rgb=cv.resize(img_rgbs,(1000,800),interpolation=cv.INTER_CUBIC)
img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)
template = cv.imread(trmplate,0)
w, h = template.shape[::-1]
res = cv.matchTemplate(img_gray,template,cv.TM_CCOEFF_NORMED)
#阈值
threshold = 0.98
loc = np.where( res >= threshold)
print(loc)
for pt in zip(*loc[::-1]):
cv.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
#保存结果
# cv.imwrite('re