赞
踩
上篇文章
介绍了如何通过CNN来识别车牌的字母和数字,接下来我们尝试通过模板匹配的方式进行识别。
for match_ite in os.listdir(match_path):
for (i, template) in enumerate(os.listdir(template_path)):
# 0 , 1, 2, 3
for (index,template_img) in enumerate(os.listdir(template_path + template)):
# 1, 2, 3, 4张图片
template_img_arr = cv.imread(template_path + template + "/" + template_img)
result = cv.matchTemplate(template_img_arr, match_img, cv.TM_CCOEFF_NORMED)
min_val,max_val,min_loc,max_loc = cv.minMaxLoc(result)
# 取每个文件夹最大的置信度
if max_val > max_confidence:
max_confidence = max_val
num_list[match_ite] = i
car_number = ''
for i in confidence_list:
car_number += template_obj[i]
return car_number
template_find()
import cv2 as cv
import os
def template_find():
template_obj = ['0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z',
'京','闽','粤','苏','沪','浙']
# 模板匹配
# 设置 模板
#遍历所有的模板
template_path = './tf_car_license_dataset/train_images/training-set/'
match_path = './split/'
confidence_list = []
for match_ite in os.listdir(match_path):
match_img = cv.imread(match_path + match_ite)
match_img = cv.resize(match_img, (32, 40))
num_list = {match_ite: -1}
max_confidence = 0
for (i, template) in enumerate(os.listdir(template_path)):
# 0 , 1, 2, 3
for (index,template_img) in enumerate(os.listdir(template_path + template)):
# 1, 2, 3, 4张图片
# if index >= 15:
# break
# print(template + template_img)
template_img_arr = cv.imread(template_path + template + "/" + template_img)
result = cv.matchTemplate(template_img_arr, match_img, cv.TM_CCOEFF_NORMED)
min_val,max_val,min_loc,max_loc = cv.minMaxLoc(result)
# 取每个文件夹最大的置信度
if max_val > max_confidence:
max_confidence = max_val
num_list[match_ite] = i
confidence_list.append(num_list[match_ite])
print(confidence_list)
car_number = ''
for i in confidence_list:
car_number += template_obj[i]
return car_number
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。