《zw版·Halcon-delphi系列原创教程》 只有2行代码的超市收款单ocr脚本
《zw版·Halcon-delphi系列原创教程》 只有2行代码的超市收款单ocr脚本
只有2行代码的超市收款单ocr脚本
发了这么多教程,有网友问,为什么没有ocr的。
的确,在opencv教程当中,秀ocr的、与车牌识别、人脸识别,差不多是三大主流demo。
不过,Halcon内置的ocr模块非常彪悍,基本上,常规的工业、商业领域ocr,对于Halcon而言,已经成了标配,就象word的排版功能,实在太简单。
下面示例的脚本,不到100行,主要是图像分割太繁琐
真正用于ocr的,就两行
92 read_ocr_class_mlp ('DotPrint', OCRHandle)
93 do_ocr_multi_class_mlp (FinalCharacters, Rotated, OCRHandle, Class, Confidence)
图1,是原图
图2,字符切割
图3,最终识别结果,方框下面的字符是识别结果
ps,有兴趣的网友,可以自己改为delphi、vc、vb版
* dotprt.hdev: Segmentation of a dot printing
*
dev_update_window ('off')
read_image (Needle, 'needle1')
dev_close_window ()
get_image_size (Needle, Width, Height)
dev_open_window (, , * Width, * Height, 'black', WindowID)
set_display_font (WindowID, , 'mono', 'true', 'false')
dev_display (Needle)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* *
Row1 :=
Column1 :=
Row2 :=
Column2 :=
Px := Column1 + (Column2 - Column1) /
Py := Row1 + (Row2 - Row1) /
gen_rectangle1 (Rectangle1, Row1, Column1, Row2, Column2)
* orientation correction
text_line_orientation (Needle, Needle, , -0.523599, 0.523599, OrientationAngle)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, -OrientationAngle, Px, Py, HomMat2DRotate)
affine_trans_image (Needle, Rotated, HomMat2DRotate, 'constant', 'false')
dev_display (Rotated)
disp_continue_message (WindowID, 'black', 'true')
stop ()
threshold (Rotated, RawSegmentation, , )
connection (RawSegmentation, ConnectedRegions)
select_shape (ConnectedRegions, MinSizeRegions, 'area', 'and', , )
union1 (MinSizeRegions, RemovedNoise)
dev_display (Rotated)
dev_set_color ('green')
dev_set_draw ('fill')
dev_display (RemovedNoise)
disp_continue_message (WindowID, 'black', 'true')
stop ()
clip_region (RemovedNoise, RawSegmentation, , , , )
dev_display (Rotated)
dev_display (RawSegmentation)
disp_continue_message (WindowID, 'black', 'true')
stop ()
closing_circle (RawSegmentation, ClosedPatterns, )
opening_rectangle1 (ClosedPatterns, SplitPatterns, , )
connection (SplitPatterns, ConnPatterns)
select_shape (ConnPatterns, CharCandidates, 'area', 'and', , )
shape_trans (CharCandidates, CharBlocks, 'rectangle1')
dev_set_draw ('margin')
dev_set_line_width ()
dev_display (Rotated)
dev_display (CharBlocks)
disp_continue_message (WindowID, 'black', 'true')
stop ()
partition_rectangle (CharBlocks, CharCandidates, , )
intersection (CharCandidates, RawSegmentation, Characters)
closing_circle (Characters, IntermedCharacters, 2.5)
dev_set_colored ()
dev_display (Rotated)
dev_set_draw ('fill')
dev_display (IntermedCharacters)
disp_continue_message (WindowID, 'black', 'true')
stop ()
gen_empty_obj (Characters)
count_obj (IntermedCharacters, NumIntermediate)
dev_display (Rotated)
for i := to NumIntermediate by
dev_set_color ('red')
select_obj (IntermedCharacters, Char, i)
dev_display (Char)
connection (Char, CharParts)
select_shape (CharParts, CharCandidates, 'area', 'and', , )
union1 (CharCandidates, Char)
dev_set_color ('green')
dev_display (Char)
* disp_continue_message (WindowID, 'black', 'true')
* stop ()
concat_obj (Characters, Char, Characters)
endfor
select_shape (Characters, Heigh, 'height', 'and', , )
sort_region (Heigh, FinalCharacters, 'character', 'true', 'row')
dev_set_color ('red')
dev_set_draw ('margin')
dev_display (Rotated)
dev_display (FinalCharacters)
dev_set_color ('green')
dev_set_line_width ()
dev_set_shape ('rectangle1')
dev_display (FinalCharacters)
dev_set_shape ('original')
dev_set_line_width ()
dev_set_draw ('fill')
read_ocr_class_mlp ('DotPrint', OCRHandle)
do_ocr_multi_class_mlp (FinalCharacters, Rotated, OCRHandle, Class, Confidence)
smallest_rectangle1 (FinalCharacters, Row11, Column1, Row2, Column21)
count_obj (FinalCharacters, NumberFinal)
for i := to NumberFinal by
disp_message (WindowID, Class[i - ], 'image', Row2[i - ], Column1[i - ], 'green', 'false')
endfor
clear_ocr_class_mlp (OCRHandle)
dev_update_window ('on')
【《zw版·Halcon-delphi系列原创教程》,网址,cnblogs.com/ziwang/】
《zw版·Halcon-delphi系列原创教程》 只有2行代码的超市收款单ocr脚本的更多相关文章
- 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别
[<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...
- 【《zw版·Halcon与delphi系列原创教程》Halcon图层与常用绘图函数
[<zw版·Halcon与delphi系列原创教程>Halcon图层与常用绘图函数 Halcon的绘图函数,与传统编程vb.c.delphi语言完全不同, 传统编程语言,甚至cad ...
- 《zw版Halcon与delphi系列原创教程》发布说明
<zw版Halcon与delphi系列原创教程>发布说明 zw转载的<台湾nvp系列halcon-delphi教程>,虽然很多,不过基本上都是从cnc.数控角度的demo.. ...
- zw版·Halcon与delphi(兼谈opencv)
zw版·Halcon与delphi(兼谈opencv) QQ群 247994767(delphi与halcon) <Halcon与delphi>系列,早两年就想写,不过一方面,因为Halc ...
- 《zw版·delphi与Halcon系列原创教程》THOperatorSetX版hello,zw
<zw版·delphi与Halcon系列原创教程>THOperatorSetX版hello,zw 下面介绍v3版的hello,zw. Halcon两大核心控件,THImagex.THOpe ...
- 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版
<zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...
- 《zw版·delphi与halcon系列原创教程》zw版_THImagex控件函数列表
<zw版·delphi与halcon系列原创教程>zw版_THImagex控件函数列表 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就要7w多行,但核心控件就是两 ...
- 《zw版·ddelphi与halcon系列原创教程》Halcon的短板与delphi
[<zw版·delphi与Halcon系列原创教程>Halcon的短板与delphi 看过<delphi与Halcon系列>blog的网友都知道,笔者对Halcon一直是非常推 ...
- 《zw版·delphi与halcon系列原创教程》hello,zw
<zw版·delphi与halcon系列原创教程>hello,zw 按惯例,第一个程序是‘hello’ 毕竟,Halcon是专业的图像库,所以我们就不用纯文本版的,来一个专业版.Halco ...
随机推荐
- Centos 下安装Docker 遇到的一些错误
1.公司的服务器的内核版本:2.6.32-431.23.3.el6_x86_64 如何升级内核请参考前一篇文章 2.在这个地址上面下载 的 https://test.docker.com/builds ...
- mysql安装及卸载
一.关于mysql MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是 ...
- [CareerCup] 18.5 Shortest Distance between Two Words 两单词间的最短距离
18.5 You have a large text file containing words. Given any two words, find the shortest distance (i ...
- cloudsim安装,配置(到eclipse)
现在基本成功了.所以将这个过程尽量详细的,准确的分享出来,以供大家的需要. 一.Jdk,Eclipse的安装与配置. 本人下载的jdk版本是1.8,jdk的相关配置网上有很多,我就不赘述了 ...
- Neusoft(3)增加自己的内核模块
Linux版本 Ubuntu12.04LTS,内核版本为3.2.0-26-generic-ape 具体方法如下: 1.建立源文件,假设文件目录为path,文件名为hello.c源代码如下: #incl ...
- C++产生随机数四则运算
产生两位随机整数,随机四则运算符,生成30道运算题. 一.编程思路 看到要求,首先想到的是怎么运用随机数,因为自己对随机数的不熟练所以还要在查很多东西.在一个for循环内先产生两个30以内的随机数,在 ...
- A trip through the Graphics Pipeline 2011_13 Compute Shaders, UAV, atomic, structured buffer
Welcome back to what’s going to be the last “official” part of this series – I’ll do more GPU-relate ...
- A trip through the Graphics Pipeline 2011_12 Tessellation
Welcome back! This time, we’ll look into what is perhaps the “poster boy” feature introduced with th ...
- ajax+ashx
eg: $('.setIsEnableClosed').click(function(){ var id=$(id).attr("name"); var isChecked=$(t ...
- css3渐变之linear-gradient与-webkit-linear-gradient写法异同
语法background: linear-gradient(direction, color-stop1, color-stop2, ...); 通常只需要linear-gradient,兼容性较好. ...