Halcon项目OCR助手使用心得
read_image (Image1381Bcb4442e5fb68e9, 'F:/yuan/Image/13_81_bcb4442e5fb68e9.bmp')
- OCR 01: Code generated by OCR 01
- OCR 01:
- OCR 01: Prepare text model
- OCR 01:
create_text_model_reader ('manual', [], TextModel)
set_text_model_param (TextModel, 'manual_polarity', 'light_on_dark')//暗背景中亮文本
set_text_model_param (TextModel, 'manual_char_width', 37)//符号宽度
set_text_model_param (TextModel, 'manual_char_height', 74)//符号高度
set_text_model_param (TextModel, 'manual_stroke_width', 6.5)//笔画宽度
set_text_model_param (TextModel, 'manual_return_punctuation', 'false')//是否存在标点符号
set_text_model_param (TextModel, 'manual_return_separators', 'false')//是否有分隔符
set_text_model_param (TextModel, 'manual_uppercase_only', 'true')//是否全部大写
set_text_model_param (TextModel, 'manual_fragment_size_min', 5)//最小尺寸片段
set_text_model_param (TextModel, 'manual_add_fragments', 'false')
set_text_model_param (TextModel, 'manual_base_line_tolerance', 0.28)//基线公差
set_text_model_param (TextModel, 'manual_max_line_num', 3)//文本行的最大行,需要识别的字符文本行有多少行
set_text_model_param (TextModel, 'manual_eliminate_horizontal_lines', 'true')//是否消除背景横线 - OCR 01:
- OCR 01: Load classifier
- OCR 01:
read_ocr_class_mlp ('Industrial_NoRej.omc', OcrHandle) - OCR 01: ***************************************************************
- OCR 01: * The code which follows is to be executed once / image *
- OCR 01: ***************************************************************
- OCR 01:
- OCR 01: Load image
read_image (Image, 'F:/yuan/Image/13_81_bcb4442e5fb68e9.bmp') - OCR 01:
- OCR 01: Perform actual processing (once per ROI)
- OCR 01: Generate regions of interest
gen_rectangle1 (ROI_OCR_01_0, 130.125, 243.875, 367.625, 557.625) - OCR 01:
- OCR 01: Extract symbol regions (segmentation step)
- OCR 01: Only consider first channel for color images
*access_channel (Image, TmpObj_Mono, 1)
reduce_domain (Image, ROI_OCR_01_0, TmpObj_MonoReduced_OCR_01_0) - OCR 01:
- OCR 01: Orientation Correction (for consistent border and domain
- OCR 01: handling, this is always applied, even with no rotation)
- OCR 01:
*hom_mat2d_identity (TmpCtrl_MatrixIdentity) - OCR 01: Apply transformation to image and domain
*get_domain (TmpObj_MonoReduced_OCR_01_0, TmpObj_Domain)
*get_system ('clip_region', TmpCtrl_ClipRegion)
*set_system ('clip_region', 'false')
*dilation_circle (TmpObj_Domain, TmpObj_DomainExpanded, 32)
*affine_trans_region (TmpObj_DomainExpanded, TmpObj_DomainTransformedRaw, TmpCtrl_MatrixIdentity, 'true')
*smallest_rectangle1 (ROI_OCR_01_0, TmpCtrl_Row1, TmpCtrl_Col1, TmpCtrl_Row2, TmpCtrl_Col2)
*hom_mat2d_translate (TmpCtrl_MatrixIdentity, -TmpCtrl_Row1, -TmpCtrl_Col1, TmpCtrl_MatrixTranslation)
*hom_mat2d_compose (TmpCtrl_MatrixTranslation, TmpCtrl_MatrixIdentity, TmpCtrl_MatrixComposite)
*affine_trans_region (TmpObj_Domain, TmpObj_DomainTransformed, TmpCtrl_MatrixComposite, 'true')
*affine_trans_image (TmpObj_MonoReduced_OCR_01_0, TmpObj_ImageTransformed, TmpCtrl_MatrixComposite, 'constant', 'true')
*dilation_circle (TmpObj_Domain, TmpObj_DomainExpanded, 32)
*expand_domain_gray (TmpObj_ImageTransformed, TmpObj_ImageTransformedExpanded, 32)
*reduce_domain (TmpObj_ImageTransformed, TmpObj_DomainTransformed, TmpObj_ImageTransformedReduced)
*crop_part (TmpObj_ImageTransformedReduced, TmpObj_MonoReduced_OCR_01_0, 0, 0, TmpCtrl_Col2-TmpCtrl_Col1+1, TmpCtrl_Row2-TmpCtrl_Row1+1)
*set_system ('clip_region', TmpCtrl_ClipRegion)
find_text (TmpObj_MonoReduced_OCR_01_0, TextModel, TmpCtrl_ResultHandle_OCR_01_0) - OCR 01:
- OCR 01: Read text (classification step)
- OCR 01: Gray values for reading must be dark on bright
invert_image (TmpObj_MonoReduced_OCR_01_0, TmpObj_MonoInverted_OCR_01_0)
get_text_object (Symbols_OCR_01_0, TmpCtrl_ResultHandle_OCR_01_0, 'manual_all_lines')
clear_text_result (TmpCtrl_ResultHandle_OCR_01_0)
dev_display (TmpObj_MonoInverted_OCR_01_0)
dev_set_draw ('fill')
dev_set_colored (3)
dev_display (Symbols_OCR_01_0)
do_ocr_multi_class_mlp (Symbols_OCR_01_0, TmpObj_MonoInverted_OCR_01_0, OcrHandle, SymbolNames_OCR_01_0, Confidences_OCR_01_0) - OCR 01:
- OCR 01: Do something with the results
- OCR 01:
- OCR 01: Cleanup (global)
clear_text_model (TextModel)
clear_ocr_class_mlp (OcrHandle)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义