《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脚本的更多相关文章

  1. 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别

    [<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...

  2. 【《zw版·Halcon与delphi系列原创教程》Halcon图层与常用绘图函数

    [<zw版·Halcon与delphi系列原创教程>Halcon图层与常用绘图函数 Halcon的绘图函数,与传统编程vb.c.delphi语言完全不同,     传统编程语言,甚至cad ...

  3. 《zw版Halcon与delphi系列原创教程》发布说明

    <zw版Halcon与delphi系列原创教程>发布说明 zw转载的<台湾nvp系列halcon-delphi教程>,虽然很多,不过基本上都是从cnc.数控角度的demo..  ...

  4. zw版·Halcon与delphi(兼谈opencv)

    zw版·Halcon与delphi(兼谈opencv) QQ群 247994767(delphi与halcon) <Halcon与delphi>系列,早两年就想写,不过一方面,因为Halc ...

  5. 《zw版·delphi与Halcon系列原创教程》THOperatorSetX版hello,zw

    <zw版·delphi与Halcon系列原创教程>THOperatorSetX版hello,zw 下面介绍v3版的hello,zw. Halcon两大核心控件,THImagex.THOpe ...

  6. 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版

    <zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...

  7. 《zw版·delphi与halcon系列原创教程》zw版_THImagex控件函数列表

    <zw版·delphi与halcon系列原创教程>zw版_THImagex控件函数列表 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就要7w多行,但核心控件就是两 ...

  8. 《zw版·ddelphi与halcon系列原创教程》Halcon的短板与delphi

    [<zw版·delphi与Halcon系列原创教程>Halcon的短板与delphi 看过<delphi与Halcon系列>blog的网友都知道,笔者对Halcon一直是非常推 ...

  9. 《zw版·delphi与halcon系列原创教程》hello,zw

    <zw版·delphi与halcon系列原创教程>hello,zw 按惯例,第一个程序是‘hello’ 毕竟,Halcon是专业的图像库,所以我们就不用纯文本版的,来一个专业版.Halco ...

随机推荐

  1. eclipse配置PHP开发环境

    下载 http://www.oracle.com/technetwork/java/javase/downloads/index.html下载JDK,Eclipse 安装需要JDK环境:http:// ...

  2. Node.js 手册查询-1-核心模块方法

    Node.js 学习手册 标签(空格分隔): node.js 模块 核心模块 核心模块是被编译成二进制代码,引用的时候只需require表示符即可 os 系统基本信息 os模块可提供操作系统的一些基本 ...

  3. BigDecimal 转换类型

    使用BigDecimal类来进行计算的时候,主要分为以下步骤: 1.用float或者double变量构建BigDecimal对象. 2.通过调用BigDecimal的加,减,乘,除等相应的方法进行算术 ...

  4. IE hack中主要的几个

    _: IE6; #*+.: IE6 IE7; black\0: IE8; black\9: IE所有; @media screen\9 { … }: IE6 IE7; @media \0screen\ ...

  5. oracle 连接查询,和(+)符号的用法

    --连接查询 左链接.右链接,全链接 --内链接select e.account 用户名, e.empname 名称, c.comname 公司名称  from employee e inner jo ...

  6. vim 基础命令

    第一部份:一般指令模式可用的按鈕說明,游標移動.複製貼上.搜尋取代等 移動游標的方法 h 或 向左方向鍵(←)                           游標向左移動一個字元 j 或 向下方 ...

  7. iframe自适应高度js

    <iframe src="http://www.fufuok.com/" id="iframepage" name="iframepage&qu ...

  8. 关于Jquery获取Table中td内的内容

    $(this).children().eq(1).text()获取的是显示的值$(this).children().eq(1).html()获取的是<td></td>之间的所有 ...

  9. Server Error in '/' Application

    在服务器部署了网站,然后访问的时候出现异常   Server Error in '/' Application,一般这样的异常都是不明确的,我们应当把网站根目录web.config<custom ...

  10. java四种内部类详解

    一般来说,有4中内部类:常规内部类.静态内部类.局部内部类.匿名内部类. 一.常规内部类:常规内部类没有用static修饰且定义在在外部类类体中.   1.常规内部类中的方法可以直接使用外部类的实例变 ...