车牌识别
以车牌识别结束字符识别的内容,后续开启颜色识别的新篇章。本文在进行车牌识别时,汉字与特殊符号自行训练,英文字符采用预设分类器,注意程序中字符分割方法以及如何使用自行训练分类器与预设分类器交叉识别。
网上某车牌
从车牌上可看出
难点在于如何将字母“E”和“P”与圆形钉分割
提取hsv空间某通道图像
白底黑字最好的一张
阈值分割并计算连通域
E和P与背景相连
通过形态学与eliminate_runs算子的配合,成功将字符与背景分割
筛选特征,排除干扰
膨胀、联合、求交集,使得一个字符对应一个区域
排序后如下
选择汉字“苏”和字符“.”单独训练
结合自行训练库与官方库进行字符识别
核心代码如下
*(1)字符分割
*读图并显示
dev_close_window ()
read_image (Chepai, 'chepai.jpg" ')
dev_open_window (0, 0, 600, 400, 'black', WindowHandle)
dev_display (Chepai)
*rgb颜色空间转换至hsv空间
decompose3 (Chepai, Image1, Image2, Image3)
trans_from_rgb (Image1, Image2, Image3, ImageResult1, ImageResult2, ImageResult3, 'hsv')
*结果图像2对于“白底黑字”的要求最明显
dev_display (ImageResult2)
*阈值分割
threshold (ImageResult2, Regions, 0, 200)
connection (Regions, ConnectedRegions)
*各种图像处理操作,断开金属圆钉区域与字母区域的连接
*消除给定宽度的顺串,第一次尝试断开两个金属扣字母E和P的连接
eliminate_runs (ConnectedRegions, RegionClipped, 16, 100000)
*计算连通域,利用形态学处理进一步断开割圆钉与字母的连接
connection (RegionClipped, ConnectedRegions1)
dilation_circle (ConnectedRegions1, RegionDilation1, 1.5)
union1 (RegionDilation1, RegionUnion1)
connection (RegionUnion1, ConnectedRegions2)
eliminate_runs (ConnectedRegions2, RegionClipped, 19, 100000)
erosion_circle (RegionClipped, RegionDilation1, 1.5)
connection (RegionDilation1, ConnectedRegions3)
*选择背景区域
select_shape (ConnectedRegions3, SelectedRegions, 'area', 'and', 810, 2e+007)
*作差,求出包含车牌区域
difference (ConnectedRegions, SelectedRegions, RegionDifference)
*计算连通域,根据特征排除干扰项
connection (RegionDifference, ConnectedRegions4)
select_shape (ConnectedRegions4, SelectedRegions1, 'area', 'and', 50, 2000)
select_shape (SelectedRegions1, SelectedRegions5, 'row', 'and', 219.36, 301.38)
select_shape (SelectedRegions5, SelectedRegions6, 'column', 'and', 0.56, 457.27)
*膨胀、联合、求交集,使得一个字符对应一个区域
dilation_rectangle1 (SelectedRegions6, RegionDilation, 5, 1)
union1 (RegionDilation, RegionUnion)
connection (RegionUnion, ConnectedRegions5)
intersection (ConnectedRegions5, RegionDifference, RegionIntersection)
erosion_circle (RegionIntersection, RegionErosion, 1.5)
*排序,从左到右识别
sort_region (RegionErosion, SortedRegions, 'character', 'true', 'column')
*选择汉字和符号‘.’,并组成一个区域,为了后续单独训练
select_shape (SortedRegions, SelectedRegions3, 'column', 'and', 0, 180)
select_shape (SortedRegions, SelectedRegions4, 'column', 'and', 200, 250)
concat_obj (SelectedRegions3, SelectedRegions4, ObjectsConcat)
*(2)字符标识关联
charact := ['苏','.']
for Index := 1 to 2 by 1
select_obj (ObjectsConcat, ObjectSelected,Index)
append_ocr_trainf (ObjectSelected, ImageResult2, charact[Index-1], 'train_ocr')
endfor
*(3)字符训练
create_ocr_class_mlp (8, 10, 'constant', 'default', charact, 80, 'none', 10, 42, OCRHandle)
trainf_ocr_class_mlp (OCRHandle, 'train_ocr', 200, 1, 0.01, Error, ErrorLog)
*保存训练结果并清除训练句柄
write_ocr_class_mlp (OCRHandle, 'train_ocr')
*(4)字符识别
*读取汉字字库文件
read_ocr_class_mlp ('train_ocr.omc', OCRHandle)
*读取数字与英文字符字库文件
read_ocr_class_mlp ('Pharma_0-9A-Z_NoRej.omc', OCRHandle1)
*逐字识别,并连接成字符串
charaNull := ''
count_obj (SortedRegions, Number)
for Index1 := 1 to Number by 1