halcon成长之路(二) ocr之英文数字“点”识别

识别图中的数字和英文

在这里插入图片描述

套路思路:

1.读取图片

2.字符分割

3.字符识别

具体操作如下:

dev_close_window()
read_image (Image2, 'D:/image1.jpg')

get_image_size (Image2, Width, Height)
 dev_open_window(0, 0, Width/2, Height/2, 'black', WindowHandle)
* 画区域
gen_rectangle1 (ROI_0, 175.442, 300.138, 670.685, 1149.25)

* 获取图片中的点点点
dots_image (Image2, DotImage, 15, 'dark', 0)
* 根据所画的区域获取方向
text_line_orientation (ROI_0, DotImage, 25, -0.523599, 0.523599, OrientationAngle)

*平移
vector_angle_to_rigid (Width, Height, OrientationAngle, Width, Height, 0, HomMat2D)

* 仿色变换
affine_trans_image (DotImage, ImageAffineTrans, HomMat2D, 'constant', 'false')

* 预处理
invert_image (ImageAffineTrans, ImageInvert)
reduce_domain (ImageInvert, ROI_0, ImageReduced)

* 快速二值化,前提是只有两种颜色
binary_threshold (ImageInvert, Region, 'max_separability', 'dark', UsedThreshold)

connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [281.15,150], [500,2000])
union1 (SelectedRegions, RegionUnion)

* 膨胀
dilation_rectangle1 (RegionUnion, RegionDilation, 10, 10)

connection (RegionDilation, ConnectedRegions1)

shape_trans (ConnectedRegions1, RegionTrans, 'rectangle1')

* 清楚冒号
select_shape (RegionTrans, SelectedRegions1, 'area', 'and', 2563.49, 20000)
 
* 区域划分,通过大小进行切割
partition_rectangle (SelectedRegions1, Partitioned, 43, 80)


* 区域一和区域二取交集
intersection (Partitioned, Region, RegionIntersection)


read_ocr_class_mlp ('D:/halcon/ocr/DotPrint_0-9A-Z_NoRej.omc', OCRHandle)

sort_region (RegionIntersection, SortedRegions, 'character', 'true', 'row')

*4识别显示
do_ocr_multi_class_mlp(SortedRegions, ImageInvert, OCRHandle, Class, Confidence)
count_obj(Partitioned,num)
dev_display(ImageInvert)
smallest_rectangle1 (SortedRegions, Row1, Column1, Row2, Column2)
count_obj (SortedRegions, NumberFinal)

for i := 1 to NumberFinal by 1
    disp_message(WindowHandle, Class[i - 1], 'image', Row2[i - 1]+120, Column1[i - 1], 'red', 'false')
endfor













  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值