《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 ...
随机推荐
- Windows Phone 8 Sync
A lot of the below depends on the types of data, how often it is changing, and how often it is likel ...
- Java语言基础
Java 语言是面向对象的程序设计语言,Java 程序的基本组成单元是类,类体中又包括属性与方法两部分.每一个应用程序都必须包含一个main()方法,含有main()方法的类成为主类. 一.Java ...
- Handler消息传递机制
引言: 出于性能优化考虑,Android的UI操作并不是线程安全的,这意味着如果有多个线程并发操作UI组件,可能导致线程安全问题. 为了解决这个问题,Android制定了一条简单的规则:只允许UI线程 ...
- [LintCode] Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- LeetCode(43. Multiply Strings)
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...
- 一款查看mysql QPS的脚本
本脚本黏贴就可以使用绝对不坑人!!! (此脚本来源如一位大神网友) 执行效果: 脚本: #!/bin/bashPW=Eqipay20150504@mysqladmin -P3306 -uroot -p ...
- POJ2488 dfs
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41972 Accepted: 14 ...
- apache本地域名ip重定向vhosts
apache本地域名ip重定向,使本机通过指定域名访问到指定ip路径. 1.apache配置apache/conf/httpd.conf : 开启配置 Include conf/extra/http ...
- select的5中子句where,group by, havaing, order by, limit的使用顺序及实例
-- 语法: SELECT select_list FROM table_name [ WHERE search_condition ] [ GROUP BY group_by_expression ...
- java 与c#比较
1.开发周期方面:c#比java开发周期更快2.java出现的时间更长.开源性广.跨平台性好3.c#较为封闭.后出于java4.c#有无符号类型.java没有5.java与c#都有值类型.但是java ...