一.原理
通过对已经纵向定位的车牌进行窗口搜索,滑动窗口,遍历窗口内的每一行的跳变点数,若符合则加入候选区域,若最后候选区域为0,则将图片的高度缩减,因为图片在进行纵向定位时,背景的变化造成的灰度跳变数也可能大于14;若最后候选区域数大于1,将窗口宽度减少,直到候选区域只有一个。但该方法的车牌定位时间较长。
二.部分代码
水平定位函数
def hor_locate(image):
jump_list = []
flag = False
for x in range(h):
jump = 0
start = image[x][0]
for y in range(w):
if abs(int(image[x][y]) - start) > 250:
jump += 1
start = image[x][y]
jump_list.append(jump)
jump_list.reverse()
flag1 = False
flag2 = False
area = []
license_hor_start = 0
license_hor_end = 0
for i in range(len(jump_list)):
if flag1 is False and jump_list[i] >= 14:
license_hor_start = i
flag1 = True
if flag1 is True and jump_list[i] < 14:
license_hor_end = i - 1
flag1 = False
if license_hor_end - license_hor_start > 20:
flag2 = True
result_start = license_hor_start
result_end = license_hor_end
if flag2 is False:
continue
break
# print(jump_list[result_start: result_end])
return result_start, result_end
垂直定位函数
def ver_locate(image):
h, w = image.shape[:2]
# 定义搜索窗口的长度和宽度
window_h = h
window_w = h * 6 # 因为我国车牌的标准尺寸为440mm*140mm 所以根据已有的高度,预估车牌区域的宽度
result = False
ver_start = 0
ver_end = 0
candidate_list = []
while len(candidate_list) != 1:
h, w = image.shape[:2]
for i in range(0, w - window_w, 3):
result = isvalid(image, i, i + window_w)
if result is False:
continue
ver_start = i
ver_end = i + window_w
candidate_list.append((ver_start, ver_end))
result = False
print(len(candidate_list))
if len(candidate_list) == 0:
image = image[0 + 1:h - 1, 0:w]
if len(candidate_list) > 1:
window_w = window_w - 3
candidate_list = [] # 重置候选区域
return ver_start, ver_end
三.测试结果
原图一
预处理后的图
纵向定位的车牌图
横向定位后的车牌图
原图二
预处理后的图
纵向定位的车牌图
横向定位后的车牌图
工作了,没时间进行后续更新了,卡在倾斜矫正上了
四.参考文献
[1]龚成清. 一种简单快速的车牌定位算法[J]. 计算机系统应用, 2011, 20(9):214-217.
[2]蒋欣欣. 彩色车牌图像定位及字符分割方法研究[D]. 湖南师范大学, 2011.
[3]刘丽新, 刘京刚. 行扫描进行车牌上下边界定位的研究[J]. 仪器仪表学报, 2005, 26(8):177-179.
加权灰度化链接:
https://blog.csdn.net/a15206087013/article/details/90736722
纵向定位车牌链接:
https://blog.csdn.net/a15206087013/article/details/91409793