一、待识别字符的图像:
二、运行环境:
Halcon-12.0
三、代码如下:
read_image (Image, 'C:/Users/研发/Desktop/捕获.PNG')
*缩小定义域
draw_rectangle1 (3600, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (Image, Rectangle, Image)
*增强孤立点或团状缺陷,金属上雕刻字符的图像,需要此算子处理后,才能容易的分割出来字符
gray_range_rect (Image, ImageResult, 7, 7)
*图像取反,字符识别特定是识别亮背景下的暗字符
invert_image (ImageResult, ImageResult)
threshold (ImageResult, Region, 0, 140)
*闭运算,填补细小孔洞
closing_rectangle1 (Region, RegionClosing, 2, 2)
connection (RegionClosing, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 500, 99999)
*将区域按照自定义大小分开,40,100表示字符大小(矩形)
partition_rectangle (SelectedRegions, Partitioned, 40,100)
*smallest_rectangle1 (Partitioned, Row11, Column11, Row21, Column21)
*gen_rectangle1 (Rectangle1, Row11, Column11, Row21, Column21)
sort_region (Partitioned, SortedRegions, 'first_point', 'true', 'column')
*根据字符类型选择合适的文件,也可以自己训练文件(可参照本人另一篇博客:Halcon字符识别)
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
count_obj (SortedRegions, Number)
*循环识别单个字符
for Index:=1 to Number by 1
select_obj (SortedRegions, ObjectSelected, Index)
do_ocr_multi_class_mlp (ObjectSelected, ImageResult,OCRHandle, Class, Confidence)
endfor
clear_ocr_class_mlp (OCRHandle)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。