当前位置: 首页 > news >正文

Halcon OCR字符识别(极坐标转换,字符识别)

Halcon OCR字符识别(极坐标转换,字符识别)

请添加图片描述

代码

* 1.加载图片 ***************************************************
dev_close_window ()
read_image (Image, './img')
get_image_size (Image, Width, Height)
dev_get_window (WindowHandle)
dev_set_colored (12)
dev_set_draw ('margin')
dev_display (Image)* 2.获取字符区域 ***************************************************
rgb1_to_gray (Image, GrayImage)
get_image_size (GrayImage, Width, Height)
threshold (GrayImage, Region, 40, 140)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 13000, 99999)
fill_up (SelectedRegions, RegionFillUp)
opening_circle (RegionFillUp, RegionOpening, 5.5)* 3.字符环形区域 ***************************************************
gen_contour_region_xld (RegionOpening, Contours, 'border')
segment_contours_xld (Contours, ContoursSplit, 'lines_circles', 5, 4, 2)
length_xld (ContoursSplit, Lengths)
LengthIndex := sort_index(Lengths)[|Lengths| - 1]
select_obj(ContoursSplit, ObjectSelected, LengthIndex + 1)fit_circle_contour_xld (ObjectSelected, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
gen_circle (Circle, Row, Column, Radius)dilation_circle (Circle, RegionDilation, 5.0)
erosion_circle (Circle, RegionErosion, 30)difference (RegionDilation, RegionErosion, RegionDifference)
reduce_domain (GrayImage, RegionDifference, ImageReduced)
stop()* 4.极坐标转换与旋转 ***************************************************
polar_trans_image_ext (ImageReduced, PolarTransImage, Row, Column, \rad(85), rad(280), Radius-100, Radius, \750, 250, 'nearest_neighbor')
rotate_image (PolarTransImage, ImageRotate, 90, 'constant')* 5.获取文本区域 ***************************************************
threshold (ImageRotate, RegionText, 160, 255)
threshold (ImageRotate, RegionBack, 35, 80)
fill_up (RegionBack, RegionBack)
connection (RegionBack, ConnectedRegions1)
select_shape_std (ConnectedRegions1, SelectedBack, 'max_area', 70)intersection (RegionText, SelectedBack, RegionIntersection)
connection (RegionIntersection, ConnectedRegions2)
select_shape (ConnectedRegions2, SelectedTexts, 'area', 'and', 10, 99999)* 6. 获取文本外接矩形***************************************************
opening_circle (SelectedTexts, SelectedTexts, 1.5)
union1 (SelectedTexts, RegionUnion)closing_rectangle1 (RegionUnion, RegionClosing, 80, 3)
fill_up (RegionClosing, RegionFillUp1)
connection (RegionFillUp1, ConnectedRegions3)
shape_trans (ConnectedRegions3, RegionTrans, 'rectangle1')
dilation_rectangle1 (RegionTrans, RegionDilation1, 15, 5)
sort_region (RegionDilation1, SortedRegions, 'first_point', 'true', 'row')invert_image (ImageRotate, ImageInvert)* 7.循环识别字符 ***************************************************
* 读取OCR
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)* 存放结果字典
create_dict (DictHandle)count_obj (SortedRegions, Number)
for Index := 1 to Number by 1* 获取区域内文本select_obj (SortedRegions, SubRect, Index)intersection (SubRect, SelectedTexts, SubRegion)connection (SubRegion, ConnectedRegions4)sort_region (ConnectedRegions4, SortedRegions1, 'first_point', 'true', 'column')* 字符识别do_ocr_multi_class_mlp (SortedRegions1, ImageInvert, OCRHandle, Class, Confidence)area_center (SubRect, Area, RowRect, ColumnRect)tuple_mean (Confidence, MeanConfidence)* 拼接结果Concat := ''if(|Class| == 1)Concat := Classelsefor Index1 := 1 to |Class|by 1Concat := Concat + Class[Index1-1] endforendif* 结果写入字典set_dict_tuple (DictHandle, Index, [RowRect, ColumnRect, Concat, MeanConfidence])endfor* 8.显示结果 ***************************************************
dev_clear_window ()
dev_display (ImageRotate)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
* 循环解析字典
get_dict_param (DictHandle, 'keys', [], AllKeys)
for Index := 0 to |AllKeys| - 1 by 1NextKey := AllKeys[Index]* 获取数据get_dict_param (DictHandle, 'key_data_type', NextKey, NextKeyDataType)get_dict_tuple (DictHandle, NextKey, ResultTuple)* 显示区域RowText := ResultTuple[0] - 15CloumnText := ResultTuple[1] + 20* 显示结果result_msg := ResultTuple[2] + ' ' +   ResultTuple[3] $ '.3f'disp_message (WindowHandle, result_msg, 'image', RowText, CloumnText, 'blue', 'true')endfor

结果显示

请添加图片描述

http://www.lryc.cn/news/391446.html

相关文章:

  • 【管理咨询宝藏139】某大型快消集团公司多渠道销售管理体系方案
  • 大模型提问中包括时间的实战方案
  • 【算法】(C语言):堆排序
  • ffmpeg下载/配置环境/测试
  • C# 异步编程详解(Task,async/await)
  • qt结合vs2022安装
  • Kafka集群部署(手把手部署图文详细版)
  • 阿里Qwen2-72B大模型已是开源榜的王者,为什么还要推出其他参数模型,被其他模型打榜?
  • 7.基于SpringBoot的SSMP整合案例-表现层开发
  • 【server】3、注册中心与配置中心
  • 【大数据】—量化交易实战案例(海龟交易策略)
  • 014-GeoGebra基础篇-快速解决滑动条的角度无法输入问题
  • Diffusion模型的微调和引导
  • 零基础学MySQL:从入门到实践的完整指南
  • 澳蓝荣耀时刻,6款产品入选2024年第一批《福州市名优产品目录》
  • Frrouting快速入门——OSPF组网(一)
  • 记录通过Cloudflare部署属于自己的docker镜像源
  • 波动方程 - 在三维图中动态显示二维波动方程的解就像水面波澜起伏
  • yum命令提示 错误:rpmdb: BDB0113 Thread/process 4153/139708200269632
  • 欢乐钓鱼大师游戏攻略:在什么地方掉称号鱼?云手机游戏辅助!
  • 什么是构造函数?Java 中构造函数的重载如何实现?
  • Linux内核 -- ARMv7 与 ARMv8 中的 asmlinkage 作用及使用
  • GPT提示词模板
  • WRF学习——使用CMIP6数据驱动WRF/基于ncl与vdo的CMIP6数据处理
  • 机器人控制系列教程之Delta机器人动力学分析
  • VIM介绍
  • 课设:选课管理系统(Java+MySQL)
  • 动态规划 剪绳子问题
  • 上位机图像处理和嵌入式模块部署(mcu项目1:实现协议)
  • 【NLP学习笔记】load_dataset加载数据