Halcon 学习笔记六:车牌识别案例
可以打开这个例子,颜色HSV变换的例子
二、车牌定位与识别
可以看到车牌是歪的
所以先要定位车牌的位置,然后方向转正,接着分割字符,最后识别字符
由于颜色比较显著,可以转换为HSV来处理.(一般来看H分量或者S分量)
最后识别的效果
完整代码
read_image (Image, 'C:/Users/xuheding/Desktop/图片/4.png') dev_close_window () dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) *拆通道 decompose3 (Image, Red, Green, Blue) *将rgb转为hsv trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv') *二值化 threshold (Saturation, Regions, 220, 255) *开操作(去噪) opening_rectangle1 (Regions, RegionOpening, 10, 10) *最小外接矩形 shape_trans (RegionOpening, RegionTrans, 'rectangle2') *获得角度 orientation_region (RegionTrans, Phi) *获得区域中心 area_center (RegionTrans, Area, Row, Column) *获得仿射变换矩阵 vector_angle_to_rigid (Row, Column, Phi, Row, Column, rad(180), HomMat2D) *分别对图片和区域进行仿射变换 affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false') affine_trans_region (RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor') *获得感兴趣区域 reduce_domain (ImageAffineTrans, RegionAffineTrans, ImageReduced) *对车牌的区域的图片变成灰度图 rgb1_to_gray (ImageReduced, GrayImage) *二值化 threshold (GrayImage, Regions1, 132, 210) *计算连通域 connection (Regions1, ConnectedRegions) *特征选择(blob分析) select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 750.46, 1480.73) *对区域排序 sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'column') *读取ocr模型 read_ocr_class_mlp ('DotPrint_0-9A-Z_NoRej.omc', OCRHandle) *反转图像的灰度(255-灰度) invert_image (GrayImage, ImageInvert) *使用模型就行预测() do_ocr_multi_class_mlp (SortedRegions, ImageInvert, OCRHandle, Class, Confidence) *显示类别(message) disp_message (WindowHandle, Class, 'window', 0, 0, 'blue', 'true')