基于Halcon学习的车牌识别【二】

*采集图像
read_image (Image, 'C:/Users/gwd/Desktop/车牌3.png')
dev_clear_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image)
*将一幅rgb三通道图像转换为3幅单通道图像*注意这里的颜色通道转换是为了方便图像分割,也就是车牌定位
decompose3 (Image, Red, Green, Blue)
*rgb空间转hsv空间
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
threshold (Saturation, Regions, 120, 255)
*断成不同的连通域【阈值分割】
connection (Regions, ConnectedRegions)
*特征选择
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 267.24, 1243.1)
*联合
union1 (SelectedRegions, RegionUnion1)
*膨胀
dilation_rectangle1 (RegionUnion1, RegionDilation, 11, 11)
*填充
fill_up (RegionDilation, RegionFillUp)
*求填充区域的角度
orientation_region (RegionFillUp, Phi)
*求区域面积,旋转坐标
area_center (RegionFillUp, Area, Row, Column)
*phi 原kaishi 始点的角度  rad(180)转换点的角度
*求旋转矩阵--仿射变换矩阵
vector_angle_to_rigid (Row, Column, Phi, Row, Column, rad(180), HomMat2D)
*该方式实现较复杂,但是可以实现绕任意位置的旋转。
affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
affine_trans_region (RegionFillUp, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
*截取区域 图像Image相对于Region区域的图像
reduce_domain (ImageAffineTrans, RegionAffineTrans, ImageReduced)

*转化为灰度图像,注意这里翻转图像灰度值是因为我们后面用的是halcon自带的字库
*而halcon自带字库是白底黑字的
rgb1_to_gray (ImageReduced, GrayImage)
*图像取反,由于识别用到训练字库都是暗字体
invert_image (GrayImage, ImageInvert)
*开始二值化【灰度处理】
threshold (GrayImage, Regions1, 138, 255)
connection (Regions1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, ['area','column'], 'and', [22.7,153.157], [104.95,219.71])
*开始排序
sort_region (SelectedRegions1, SortedRegions, 'character', 'true', 'row')
*识别
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
*依据OCRHandle句柄,对提取体征进行识别与学习,把结果赋值给 Class
do_ocr_multi_class_mlp (SelectedRegions1, ImageInvert, OCRHandle, Class, Confidence)
*显示
*disp_message (WindowHandle, Class, 'window', 0, 0, 'blue' , 'true')
*计算字符个数Number,为显示所用
count_obj (SortedRegions, Number)
*计算面积的行列
area_center (SortedRegions, Area1, Row1, Column1)
for Index := 1 to Number by 1
    disp_message (WindowHandle, Class[Index-1], 'Image3', 400, Column1[Index-1], 'blue', 'true')
endfor

结果显示在对应字母的下方

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值