License plate recognition program

 

*******************车牌识别程序  仅供学习使用*******
**说明:此程序识别的车牌是在网上随便找的,此程序中的二值化、形状选择和形态学处理的blob分析三步曲
**并不具有普遍性。因为位置、光照、车牌清洁状态等都会对车票识别造成很大的影响。只有使用MLP/SVM/CNN
**等人工智能算法训练的程序,才具有比较高的普适性。

**1.采集图像
read_image (Image, 'F:/7.机器视觉/Halcon/c#联合halcon开发/chepaishibie1.jpg')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)

*2.车牌定位及校正
**颜色转换
decompose3 (Image, Image1, Image2, Image3)
trans_from_rgb (Image1, Image1, Image1, Hue, Saturation, Intensity, 'hsv')
*二值化
threshold (Intensity, Regions, 0, 59)
connection (Regions, ConnectedRegions)
*形状选择
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4908.26, 8944.95)
**形态学处理
union1 (SelectedRegions, RegionUnion)
dilation_rectangle1 (RegionUnion, RegionDilation, 11, 11)
fill_up (RegionDilation, RegionFillUp)
**角度变换
orientation_region (RegionFillUp, Phi)
area_center (RegionFillUp, Area, Row, Column)
vector_angle_to_rigid (Row, Column, Area, Row, Column, Area, HomMat2D)
affine_trans_image (Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
affine_trans_region (RegionFillUp, RegionAffineTrans, HomMat2D, 'nearest_neighbor')

*3.抠图+字符识别
reduce_domain (ImageAffinTrans, RegionAffineTrans, ImageReduced)
rgb1_to_gray (ImageReduced, GrayImage)
invert_image (GrayImage, ImageInvert)
threshold (ImageInvert, Regions1, 56, 159)
connection (Regions1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, ['area','height'], 'and', [206.42,27.248], [426.61,40.275])
**给识别出来的字符串进行排序,'character'指的是按字符串的形式输出
sort_region (SelectedRegions1, SortedRegions, 'character', 'true', 'row')

*4.字符识别
read_ocr_class_mlp ('Document_0-9A-Z_NoRej.omc', OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, ImageInvert, OCRHandle, Class, Confidence)

*5.显示
smallest_rectangle1 (SortedRegions, Row1, Column1, Row2, Column2)
count_obj (SortedRegions, Number)
dev_display (Image)
for Index := 0 to |Class| - 1 by 1
    **每个数字的Y坐标一样,X坐标与打印的日期对应数字的X坐标值-3
    disp_message (WindowHandle, Class[Index], 'image', 210, Column2[Index] - 3, 'green', 'false')
endfor

 

Original program as follows:

Results are as follows:

        Talked about the beginning of the program, blob analysis is only applicable to stable condition and appropriate. Once conditions change, the situation is very wrong recognition may occur. Of course, artificial intelligence algorithm is not 100% accurate, but at least you can reduce the difficulty of artificial intelligence algorithm development and debugging, blob analysis requires a lot of testing and polish the code to find temporary adjustment appropriate method. The artificial intelligence algorithms can once and for all, although the design algorithm when there is some difficulty, but, if successful can be very efficiently ported to other projects. This is not easy to say the amount of code or less work, but very low maintenance costs later, non-standard equipment industry labor costs and travel costs are very expensive.
 

 

Guess you like

Origin blog.csdn.net/yuhaibao324/article/details/93294547