Halcon学习之OCR字符识别

该文详细介绍了OCR技术的基本流程,包括图像采集、字符区域提取以及使用Halcon的字库进行多类和单类字符识别。还讨论了环形字符的极坐标转换方法。此外,文章提到了自训练字符库的步骤,如创建分类器、训练和保存。另外,文章展示了Text方式的创建模板、参数设置及结果获取。最后,提到了基于OCV的字符检测方法,包括创建投影模型和检测过程。
摘要由CSDN通过智能技术生成

一、基本流程
1.采集图像、提取字符区域
2.读取字库句柄
read_ocr_class_mlp( : : FileName : OCRHandle)
3.识别时注意Halcon提供的字库为白底黑字
读取多个:do_ocr_multi_class_mlp(Character, Image : : OCRHandle : Class, Confidence)
读取单个:do_ocr_single_class_mlp(Character, Image : : OCRHandle, Num : Class, Confidence)
4.清除句柄
clear_ocr_class_mlp (OCRHandle)

二、环形字符识别
需先将环形字符通过极坐标转换到直角坐标系下,
由直角转极坐标:
polar_trans_image_ext (Image, PolarTransImage, Row, Column, 0, 6.28319, OutRadius, InRadius, 23.14OutRadius, 50, ‘nearest_neighbor’)
由极坐标转直角
polar_trans_region_inv (RegionMirror, XYTransRegion, Row, Column, 0, 6.28319, OutRadius, InRadius, 23.14OutRadius, 50, Width, Height, ‘nearest_neighbor’)

三、自训练字符库
1.提取字符区域
2.写入训练文件
write_ocr_trainf(Character, Image : : Class, TrainingFile : )
3.读取训练文件
read_ocr_trainf_names( : : TrainingFile : CharacterNames, CharacterCount)
4.创建分类器
create_ocr_class_mlp( : : WidthCharacter, HeightCharacter, Interpolation, Features, Characters, NumHidden, Preprocessing, NumComponents, RandSeed : OCRHandle)
获取句柄参数
get_params_ocr_class_mlp( : : OCRHandle : WidthCharacter, HeightCharacter, Interpolation, Features, Characters, NumHidden, Preprocessing, NumComponents)
获取句柄特征
get_features_ocr_class_mlp(Character : : OCRHandle, Transform : Features)

5.开始训练
trainf_ocr_class_mlp( : : OCRHandle, TrainingFile, MaxIterations, WeightTolerance, ErrorTolerance : Error, ErrorLog)

6.保存分类器
write_ocr_class_mlp( : : OCRHandle, FileName : )

追加的方式:
append_ocr_trainf (SortedRegions, ImageReduced, names, ‘train_ocr’)

四、Text方式
read_image (Image, ‘./bottle2.png’)

*1.创建模板
create_text_model_reader (‘auto’, ‘Universal_Rej.occ’, TextModel)
*2.设置模板参数
set_text_model_param (TextModel, ‘min_char_width’, 10)
set_text_model_param (TextModel, ‘min_char_height’, 30)
set_text_model_param (TextModel, ‘text_line_structure’, ‘2 2 2’)
set_text_model_param (TextModel, ‘min_stroke_width’, 6)
*3.查找
find_text (Image, TextModel, TextResultID)
*4.获取结果
get_text_result (TextResultID, ‘class’, ResultValue)

dev_get_window (WindowHandle)
set_display_font (WindowHandle, 25, ‘mono’, ‘true’, ‘false’)
disp_message (WindowHandle, sum(ResultValue), ‘window’, 12, 12, ‘black’, ‘true’)

clear_text_model (TextModel)

效果图如下:
在这里插入图片描述

五、字符检测OCV
根据图像水平、垂直的灰度投影来检测;
1.创建投影模型
create_ocv_proj (‘A’, OCVHandle)
2 .训练标准
traind_ocv_proj (ImageReduced, OCVHandle, ‘A’, ‘single’)
3.检测
do_ocv_simple (ImageReduced1, OCVHandle, ‘A’, ‘true’, ‘true’, ‘true’, ‘true’, 5, Quality)
4.清除
close_ocv(OCVHandle);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值