少有人走的路

勇哥的工业自动化技术网站

HALCON之喷码OCR识别案例

一个喷码识别的案例

image.png

read_image (Image, 'D:/用户目录/Desktop/2.png')
   
rgb1_to_gray(Image, Image)
   
get_image_size (Image, Width, Height)
   
* 获取喷码区域的方法很多 比如可以用mean+dyn的动态阈值
dots_image (Image, DotImage, 5, 'dark', 2)
threshold (DotImage, Region, 30, 255)
   
*这里是形态学运算操作 目的就是要将单体字符连在一起
*这里面用到的自定义核大家可以学习一下
closing_rectangle1 (Region, RegionClosing1, 1, 7)
closing_rectangle1 (RegionClosing1, RegionClosing2, 7, 1)
gen_rectangle2 (Rectangle, 10, 10, rad(45), 3, 0)
closing (RegionClosing2, Rectangle, RegionClosing3)
gen_rectangle2 (Rectangle, 10, 10, rad(135), 3, 0)
closing (RegionClosing3, Rectangle, RegionClosing4)
connection (RegionClosing4, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','height'], 'and', [100,50], [1000,70])
   
   
*排序为下步识别做准备
sort_region(SelectedRegions, SortedRegions, 'character', 'true', 'column')
area_center(SortedRegions, Area, Row, Column)
   
   
*识别阶段
FontName:='DotPrint.omc'
read_ocr_class_mlp(FontName, OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, Image, OCRHandle, RecNum, Confidence)
   
set_display_font (3600, 27, 'mono', 'true', 'false')
for i := 0 to |RecNum| - 1 by 1
    disp_message (3600, RecNum[i], 'image', 200,Column[i], 'green', 'false')
endfor
clear_ocr_class_mlp (OCRHandle)

halcon 的 DtoPrint 预设分类器不支持小写 ,可以使用Industrial.omc , 也可以自己训练


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«    2026年2月    »
1
2345678
9101112131415
16171819202122
232425262728
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接

Powered By Z-BlogPHP 1.7.3

Copyright www.skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864