- 想针对蓝底白字的车牌做一个提取蓝色区域的适应度更广的halcon程序,进行了第二次车牌识别程序编写
图1 蓝底白字,有倾斜度,两个固定钉子
图2 蓝底白字,无倾斜度,四个固定钉- 相对上一篇的程序,使用了select_shape算子提取蓝色区域,再进行抠图,程序如下
dev_update_window ('off') *读取图像 * Image Acquisition 01: Code generated by Image Acquisition 01 read_image (Image, 'C:/Users/Administrator/Pictures/车牌5.JPG') * read_image (Image, 'C:/Users/Administrator/Pictures/车牌4.PNG') get_image_size(Image, Width, Height) *打开图像窗口,并显示图像 dev_close_window() dev_open_window(0, 0, Width, Height, 'black', WindowHandle) dev_display (Image) disp_continue_message (WindowHandle, 'black', 'true') stop () *按颜色分层,灰度化,二值化 decompose3 (Image, Red, Green, Blue) trans_from_rgb(Red, Green, Blue, ImageResult1, ImageResult2, ImageResult3, 'hsv') threshold (ImageResult2, Regions, 225, 255) *填成方块 fill_up(Regions, RegionFillUp) connection(RegionFillUp, ConnectedRegions) *当图片中的车牌像素不一样时,select_shape就不能顺利按照area选择 select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 14368.3, 50000) * select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1503.56, 10000) shape_trans(SelectedRegions,RegionTrans,'rectangle2') disp_continue_message (WindowHandle, 'black', 'true') stop () *测量车牌是否有倾斜 orientation_region(RegionTrans, Phi) area_center(RegionTrans, Area, Row, Column) *Phi<0,Angle=0;Phi>0,Angle=3.14 vector_angle_to_rigid(Row, Column, Phi, Row, Column, 3.14, HomMat2D) *将原图中的车牌进行旋转 affine_trans_image(Image, ImageAffineTrans, HomMat2D, 'constant', 'false') *对区域旋转 affine_trans_region(RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor') *对被旋转之后的车牌进行裁剪 reduce_domain(ImageAffineTrans, RegionAffineTrans, ImageReduced) *halcon训练时是拿黑色字符训练的,所以识别时也要拿黑色的字符区域去进行识别,即转换为白底黑字 invert_image(ImageReduced, ImageInvert) rgb1_to_gray(ImageReduced, GrayImage) threshold (GrayImage, Regions1, 180, 255) connection(Regions1, ConnectedRegions1) select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 567.78, 1000) sort_region(SelectedRegions1, SortedRegions, 'character', 'true', 'column') read_ocr_class_mlp('Document_0-9A-Z_NoRej.omc',OCRHandle) do_ocr_multi_class_mlp(SortedRegions, ImageInvert, OCRHandle, Class, Confidence) dev_display (Image) disp_message(WindowHandle, Class, 'Image', 120, 60, 'green', 'true')
- 图1检测结果
- 图2检测两处报错后,放弃尝试
上图为图2车牌被钉子影响,无法做下一步算子处理,下图为图1 理想结果
- 1)大小不一样,蓝色区域的灰度值数量不一样;2)钉子将车牌截成两段
- 总结:1)要对图像预处理,将图像大小,分辨率等进行归一化,才能有效实现适应度增加;2)要增加判断语句,进行膨胀或开处理等形态学处理。还要继续努力