识别车牌
摘要
功能
提取并识别车牌号,注意:不识别汉字
基本步骤如下
1.加载图像
2.预处理
3.分割提取
(1)分割
(2)旋转
(3)抠图
4.识别
5.显示
Halcon代码:识别车牌
*1 加载图像
read_image (Image, '微信图片_20190401160631.jpg')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image)
*2 预处理
decompose3 (Image, R, G, B)
trans_from_rgb (R,G,B,H, S, V, 'hsv')
threshold (S, Regions, 216, 255)
opening_rectangle1 (Regions, RegionOpening, 3, 3)
*3 分割提取(分割-旋转-抠图)
*分割
connection (RegionOpening, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','row','column'], 'and', [0,546.75,342.69], [8506.1,770.33,575.15])
union1 (SelectedRegions, RegionUnion)
shape_trans (RegionUnion, RegionTrans, 'rectangle2')
* area_center (RegionTrans, Area, Row, Column)
* orientation_region (RegionTrans, Phi)
* vector_angle_to_rigid (Row, Column, Phi, Row, Column,rad(180), HomMat2D)
* affine_trans_image (Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
* affine_trans_region (RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
*旋转
smallest_rectangle2 (RegionTrans, Row, Col, Phi, Length1, Length2)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, -Phi, Col, Row, HomMat2D)
affine_trans_image (Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
affine_trans_region (RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
*抠图
reduce_domain (ImageAffinTrans, RegionAffineTrans, ImageReduced)
rgb1_to_gray (ImageReduced, GrayImage)
invert_image (GrayImage, ImageInvert)
threshold (GrayImage, Regions1, 158, 255)
opening_rectangle1 (Regions1, RegionOpening1, 3, 3)
connection (RegionOpening1, ConnectedRegions2)
select_shape (ConnectedRegions2, SelectedRegions1, 'area', 'and', 300, 660.04)
*4 识别
sort_region (SelectedRegions1, SortedRegions, 'character', 'true', 'column')
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, ImageInvert, OCRHandle, Class, Confidence)
*5 显示
dev_display (ImageAffinTrans)
disp_message (WindowHandle, Class, 'image', Row, Col, 'black', 'true')
更多详情了解:https://blog.youkuaiyun.com/qq_32015315/article/details/141663063