分割并读取啤酒瓶上的数字

  • 引言
  • 一、结果
    • 1.1 读取图像
    • 1.2 Blob分析处理后
  • 二、Halcon代码
  • 三、案例主要算子分析
    • 1.create_text_model_reader (Operator)
      • 函数
    • 2.set_text_model_param (Operator)
      • 函数
    • 3.find_text
      • 函数
    • 4.get_text_object (Operator)
      • 函数
    • 5.get_text_result (Operator)
      • 函数
  • 步骤结果

引言


一、结果

1.1 读取图像

1.2 Blob分析处理后


二、Halcon代码

*
* bottle.hdev: Segment and read numbers on a beer bottle
*
* Step 0: Preparations
* Specify the name of the font to use for reading the date on the bottle.
* It is easiest to use the pre-trained font Industrial_0-9_NoRej. If you
* have run the program bottlet.hdev in this directory, you can activate
* the second line to use the font trained with this program.
FontName := 'Industrial_0-9_NoRej'
* FontName := 'bottle'
*
* Step 1: Segmentation
// 在程序执行期间打开或关闭图标输出对象的自动输出到图形窗口
dev_update_window ('off')
read_image (Bottle, 'bottle2')
get_image_size (Bottle, Width, Height)
dev_close_window ()
dev_open_window (0, 0, 2 * Width, 2 * Height, 'black', WindowID)
set_display_font (WindowID, 16, 'mono', 'true', 'false')
dev_display (Bottle)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*
* Create Automatic Text Reader and set some parameters
//create_text_model_reader — Create a text model.
create_text_model_reader ('auto', FontName, TextModel)
* The printed date has a significantly higher stroke width
//set_text_model_param — Set parameters of a text model
set_text_model_param (TextModel, 'min_stroke_width', 5)
* The "best before" date has a particular and known structure
set_text_model_param (TextModel, 'text_line_structure', '2 2 2')
*
* Read the "best before" date
//find_text — Find text in an image.
find_text (Bottle, TextModel, TextResultID)
*
* Display the segmentation results
*// get_text_object — 查询文本切分结果的一个图标值
get_text_object (Characters, TextResultID, 'all_lines')
dev_display (Bottle)
dev_display (Characters)
stop ()
* Display the reading results
* //get_text_result — 查询文本切分结果的控制值
get_text_result (TextResultID, 'class', Classes)
//area_center — Area and center of regions
area_center (Characters, Area, Row, Column)
for Index := 0 to |Classes| - 1 by 1disp_message (WindowID, Classes[Index], 'image', 80, Column[Index] - 3, 'green', 'false')
endfor
*
* Free memory
* //clear_text_result — 清除文本结果
clear_text_result (TextResultID)
//clear_text_model — Clear a text model
clear_text_model (TextModel)

三、案例主要算子分析

1.create_text_model_reader (Operator)

create_text_model_reader — 创建文本模型

函数

create_text_model_reader( : : Mode, OCRClassifierMLP : TextModel)
//参数 Mode (input_control)              //The Mode of the text model.Default value: 'auto'List of values: 'auto', 'manual'OCRClassifierMLP (input_control)  //OCR 分类器Default value: 'Industrial_Rej.omc'Suggested values: 'Document_A-Z+_NoRej.omc', 'Document_0-9A-Z_NoRej.omc', 'Document_0-9_NoRej.omc', 'Document_NoRej.omc', 'Document_A-Z+_Rej.omc', 'Document_0-9A-Z_Rej.omc', 'Document_0-9_Rej.omc', 'Document_Rej.omc', 'DotPrint_A-Z+.omc', 'DotPrint_0-9A-Z.omc', 'DotPrint_0-9.omc', 'DotPrint_0-9+.omc', 'DotPrint.omc', 'HandWritten_0-9.omc', 'Industrial_A-Z+_NoRej.omc', 'Industrial_0-9A-Z_NoRej.omc', 'Industrial_0-9_NoRej.omc', 'Industrial_0-9+_NoRej.omc', 'Industrial_NoRej.omc', 'Industrial_A-Z+_Rej.omc', 'Industrial_0-9A-Z_Rej.omc', 'Industrial_0-9_Rej.omc', 'Industrial_0-9+_Rej.omc', 'Industrial_Rej.omc', 'MICR.omc', 'OCRB_A-Z+.omc', 'OCRA_0-9A-Z.omc', 'OCRA_0-9.omc', 'OCRA.omc', 'OCRB_A-Z+.omc', 'OCRB_0-9A-Z.omc', 'OCRB_0-9.omc', 'OCRB.omc', 'OCRB_passport.omc', 'Pharma_0-9A-Z.omc', 'Pharma_0-9.omc', 'Pharma_0-9+.omc', 'Pharma.omc', 'SEMI.omc'TextModel (output_control)    //New text model.

create_text_model_reader 创建了一个 TextModel,它描述了要使用 find_text 进行分割的文本。

Mode 的参数值决定了使用哪种文本切分方法。可能的值为“自动”和“手动”。

通常,参数 Mode 应设置为“auto”,因为此模式更稳定且需要更少的配置工作。请注意,在这种情况下,还必须在 OCRClassifierMLP 中传递 OCR 分类器。仅当以下限制之一适用时,模式必须设置为“手动”:

  • 需要对点阵进行分割。
  • 需要对极性具有强烈局部变化的文本进行分割。例如,由于反射,雕刻的文本通常具有很强的局部变化。
  • 没有合适的基于 MLP 的 OCR 分类器可用(见下文)。

如果 Mode = ‘auto’,则 find_text 能够提取任意大小的文本。可以将搜索限制为具有特定属性的字符,有关详细信息,请参阅 set_text_model_param。此外,必须在 OCRClassifierMLP 中传递 OCR 分类器。该 OCR 分类器必须基于多层感知器 (MLP)。此外,强烈建议使用提供拒绝类的 OCR 分类器(请参阅 set_rejection_params_ocr_class_mlp)并使用正则化参数进行训练(请参阅 set_regularization_params_ocr_class_mlp)。合适的 OCR 分类器可以使用 create_ocr_class_mlp 创建或使用 read_ocr_class_mlp 读取。还可以将包含路径的字符串传递到已使用 write_ocr_class_mlp 存储的 OCR 分类器。

要在 Mode = ‘manual’ 时启用文本分割,必须使用 set_text_model_param 设置文本模型的合理参数,包括预期的字符高度和宽度。在这种情况下,OCRClassifierMLP 的值将被忽略。

TextModel的参数可以通过set_text_model_param和get_text_model_param进行设置和查询。

2.set_text_model_param (Operator)

set_text_model_param — Set parameters of a text model.

函数

set_text_model_param( : : TextModel, GenParamName, GenParamValue : )
//参数TextModel (input_control, state is modified)      //Text model.GenParamName (input_control)      //要设置的参数的名称。Default value: 'min_contrast'List of values: 'add_fragments', 'base_line_tolerance', 'char_height', 'char_width', 'eliminate_border_blobs', 'eliminate_horizontal_lines', 'fragment_size_min', 'is_dotprint', 'is_imprinted', 'max_char_height', 'max_char_width', 'max_line_num', 'max_stroke_width', 'min_char_height', 'min_char_width', 'min_contrast', 'min_stroke_width', 'mlp_classifier', 'persistence', 'polarity', 'return_punctuation', 'return_separators', 'return_whole_line', 'stroke_width', 'text_line_separators', 'text_line_structure', 'text_line_structure_0', 'text_line_structure_1', 'text_line_structure_2', 'uppercase_only'GenParamValue (input_control)    //要设置的参数值Default value: 10List of values: 'auto', 'both', 'dark_on_light', 'false', 'light_on_dark', 'true'

set_text_model_param 设置文本模型的参数。 GenParamName 的允许参数值列表有所不同,具体取决于使用 create_text_model_reader 创建文本模型时设置的模式。 下面首先列出Mode = 'auto’的文本模型的参数值,然后是Mode = 'manual’的文本模型的参数值。

参数的名称和值必须在 GenParamName 和 GenParamValue 中给出。 以下值是可能的:
Mode = ‘auto’ 的文本模型参数


'min_contrast':
角色与其周围背景的最小对比度.
值列表:字节图像的整数或浮点值介于 1 和 255 之间,
而 uint2 图像的整数或浮点值介于 1 和 65.535 之间
默认值:15

'polarity':
'dark_on_light'如果要分割的文本比它的背景暗,
'light_on_dark'如果要分割的文本比它的背景亮,'both'如果两种文本都被分割。
List of values: 'dark_on_light', 'light_on_dark', 'both'
Default value: 'both'

min_char_height':
字符的最小高度(以像素为单位)。 如果要分割任意高度的文本,可以传递'auto'。 请注意,
'min_char_height' 仅指字符。 标点符号或分隔符的高度不受“min_char_height”的限制。

'max_char_height':
字符的最小高度(以像素为单位)。 如果要分割任意高度的文本,可以传递'auto'。 请注意,
'min_char_height' 仅指字符。 标点符号或分隔符的高度不受“min_char_height”的限制。
List of values: integer or float value greater or equal to 1
Default value: 'auto'

'min_char_width':
字符的最小宽度(以像素为单位). 如果要分割任意宽度的文本,则可以传递 'auto'。 请注意,
'min_char_width' 仅指字符。 标点符号或分隔符的宽度不受“min_char_width”的限制。
List of values: integer or float value greater or equal to 1
Default value: 'auto'

'max_char_width':
字符的最大宽度(以像素为单位)。如果要分割任意宽度的文本,则可以传递 'auto'。 请注意,
“max_char_width”仅指字符。 标点符号或分隔符的宽度不受“max_char_width”的限制。
List of values: integer or float value greater or equal to 1
Default value: 'auto'

'min_stroke_width':
字符的最小笔画宽度(以像素为单位)。 如果要在文本分割过程中自动估计最小笔画宽度,
则可以传递“auto”。 请注意,“min_stroke_width”仅指字符。
标点符号或分隔符的笔画宽度不受“min_stroke_width”的限制。
List of values: integer or float value greater or equal to 1
Default value: 'auto''max_stroke_width':
字符的最大笔画宽度(以像素为单位)。 如果要在文本分割过程中自动估计最大笔画宽度,
则可以传递“auto”。 请注意,“max_stroke_width”仅指字符。
标点符号或分隔符的笔画宽度不受“max_stroke_width”的限制。
List of values: integer or float value greater or equal to 1
Default value: 'auto'

'eliminate_border_blobs':
如果应丢弃接触图像域边界的区域,则为“真”,否则为“假”。
List of values: 'true','false'
Default value: 'false'

'return_punctuation':
标点符号(例如,点或逗号)的'true'也应返回。 如果不应返回标点符号,则为 'false'。
List of values: 'true','false'
Default value: 'true''return_separators':
如果还应返回减号或等号等分隔符,则为 'true'。 如果不应返回分隔符,则为 'false'。
List of values: 'true','false'
Default value: 'true'

'add_fragments':
如果片段(例如“i”上的点)应添加到分段字符中,则为'true',否则为“假”。 请注意,
这可能会导致在分段字符中添加噪音。
List of values: 'true','false'
Default value: 'true'

'text_line_structure':
为了简化对分段文本中特定结构(例如日期或序列号)的搜索,可以定义文本行结构。
对于每个文本行,计算字符之间的距离,并根据这些距离将文本行划分为文本块。'.'、'_' 和 '-' 等短字符在此过程中将被忽略并被视为空格。此外,可以定义用户特定的分隔符,这些分隔符也被忽略。有关详细信息,请参阅“text_line_separators”的说明。然后测试任何用户定义的文本行结构是否适合生成的文本块。例如,如果要查找的文本是一个包含月、日和年两个字符的日期,则结构将为“2 2 2”。如果年份可能由两个或四个字符组成,则结构为“2 2 2-4”,表示最后一个字符块由两到四个字符组成。通过在参数名称后附加一个索引,可以提供多个结构来匹配,例如'text_line_structure_0'、'text_line_structure_1'。如果 'text_line_structure' 设置为空字符串 ' ',则要查找的文本可以具有任何结构。
请注意,找到的每个文本行结构都保存为文本结果中的唯一文本行。因此,
当调用 get_text_object 时,“行”将引用有效的文本行结构。
如果要返回包含文本行结构的整个文本行,则可以相应地设置 'return_whole_line'。
Default value: ' ''text_line_separators':
包含在查找文本行结构过程中要忽略的字符列表的字符串,有关详细信息,
请参阅“text_line_structure”。 请注意,用户特定的分隔符必须是所使用的 OCR 分类器
中的有效字符。 例如,如果要忽略 ':' 和 '\',则应传递 ':\\'。 请注意,
'\' 会转义任何特殊符号以将其视为文字,因此需要传递 '\\' 以使用 '\' 作为分隔符。
List of values: '/',':', ':\\' , '\\/:' ,...
Default value: ' '

3.find_text

find_text — Find text in an image.

函数

find_text(Image : : TextModel : TextResultID)
//参数Image (input_object)       //Input image.TextModel (input_control)  //指定要分割的文本的文本模型TextResultID (output_control)  //Result of the segmentation.
find_text 在 Image 中查找 TextModel 指定的文本,并在 TextResultID 中返回结果。
TextResultID的具体结果可以通过get_text_result和get_text_object得到。TextResultID 中的文本结果会有所不同,具体取决于使用 create_text_model_reader
创建 TextModel 时 Mode 的设置方式。对于 Mode = 'auto' 的文本模型, find_text 提取并分类图像中任意大小的文本。
可以将搜索限制为具有特定属性的字符,有关详细信息,请参阅 set_text_model_param。对于Mode = 'manual'的文本模型,文本模型的合理参数,包括预期的字符高度和宽度,
需要使用set_text_model_param进行设置。此外,对图像进行了预处理,
从而增强了类似字符的结构。如果在 TextModel 中将“persistence”设置为“true”,
则可以从 TextResultID 查询生成的补偿图像。Mode = 'auto' 和 Mode = 'manual' 的文本模型都将各种阈值应用于输入图像并根据区域和
灰度值特征分割候选字符。这些候选者进一步聚类为行。如果每行满足文本行的约束,
则单独完成并测试每一行。模式设置为“自动”的文本模型要求文本行至少包含两个字符,
而模式设置为“手动”的文本模型要求文本行至少包含三个字符。在进一步的步骤中,
如果相应的参数是通过 set_text_model_param 设置的,则会添加标点和分隔符。
最后,如果 TextModel 包含“text_line_structure”条目,则完成的行将拟合到这些结构中。find_text 查找在 Image 中大致水平对齐的文本。 text_line_orientation 和
rotate_image 可用于实现这种对齐。

4.get_text_object (Operator)

get_text_object — 查询文本切分结果的图标值。

函数

get_text_object( : Characters : TextResultID, ResultName : )

5.get_text_result (Operator)

get_text_result — 查询文本切分结果的控制值

函数

get_text_result( : : TextResultID, ResultName : ResultValue)
//参数TextResultID (input_control)    //Text result.ResultName (input_control)      //Name of the result to be returned.Default value: 'class'List of values: 'class', 'class_line', 'confidence', 'confidence_line', 'num_lines', 'polarity', 'polarity_line', 'thresholds'ResultValue (output_control)   //Value of ResultName.
get_text_result 查询find_text 返回的TextResultID 的控制结果ResultName。
ResultName 的可能参数值会有所不同,
具体取决于 find_text 的文本分割过程中使用的文本模型。
下面首先列出Mode = 'auto'的文本模型的可能参数值,
然后是Mode = 'manual'的文本模型的参数值:

步骤结果

  1. Step 1: Segmentation

  1. Display the segmentation results

  1. Display the reading results

Halcon Blob分析之分割并读取啤酒瓶上的数字——bottle.hdev相关推荐

  1. Halcon Blob分析(二值化图像分割)

    Blob分析 Blob分析 算子 示例 示例 使用场合 示例 Blob分析 Blob分析的目的在于对图像中的2D形状进行检测和分析,得到诸如目标位置.形状.方向.Blob分析流程如下: #mermai ...

  2. Halcon实例分析——autobahn.hdev快速检测道路标志

    这是运行代码的结果,下面我们每条代码过一遍,下面的代码路径为打开halcon,浏览实例程序,方法中的Blob分析, 有些重点代码会详细讲解, * autobahn.hdev: Fast detecti ...

  3. Halcon之Blob分析

    文章目录 Blob Analysis 1.基本概念 1.1 获取图像 1.2 分割图像 1.3 提取特征 1.4 A First Example 2.扩展概念 2.1 使用感兴趣区域 2.2 对齐 R ...

  4. halcon基础学习(2)—blob分析

    这段时间在学halcon,项目又紧,只能晚上回来学习学习,现在在看着视屏学点基础,其实对我来说学习软件到时很快,视屏里说学视觉还是以项目为主.以下是官方实例,原图 程序跑完之后的效果,其实就是一个典型 ...

  5. 数字图像处理:blob分析、阈值分割

    1.Blob分析: 1.1.blob分析概念在计算机视觉中的Blob(Binary large object)是指图像中的具有相似颜色.纹理等特征所组成的一块连通区域,一般来说,该区域就是图像中的前景 ...

  6. Halcon学习路线——Blob分析(1)

    Blob分析 1. 谈谈Blob分析 2. 看一张图片 3. 处理图像效果 4. Halcon代码 5. 资源下载 1. 谈谈Blob分析 Blob可以说是图像处理中最简单.最常用的方法了.虽说简单, ...

  7. 【Halcon】Blob分析的形态学算子应用(count_pellets.hdev)

    Halcon中 Blob分析 之count_pellets.hdev 示例 * This programs demonstrates the use of basic morphology * ope ...

  8. Halcon缺陷检测——Blob分析特征

    blob分析+定位+特征 案例1:检测破碎的小饼干 案例2:检测胶囊药粒 案例3:检查塑料网是否破损 资源下载地址 案例1:检测破碎的小饼干 check_hazeInut_wafers.hdev 这个 ...

  9. Halcon例程分析8:投影变换矫正倾斜图像

    打开halcon,按下ctrl+e打开halcon自带例程.方法->二维码识别->2d_data_codesrectify_symbol.hdev *This program demons ...

最新文章

  1. Django连接数据mysql
  2. Tool之curl:curl的简介、安装、使用方法之详细攻略
  3. python 学习5--matplotlib画图实践
  4. 我去德国出差后学习的一些德语
  5. 我们可以覆盖Java中的main()方法吗?
  6. #开工新姿势#开启一年新征程,云社区叫你来充电啦!
  7. m1芯片MacBook Air安装arm版MacTeX及配置
  8. linux shell脚本监控内存,shell脚本监控内嵌linux系统业务、CPU、内存等
  9. iOS 关于TouchID指纹解锁的实现
  10. 安装IAR ewarm
  11. android im腾讯云,腾讯云即时通信 IMSDK 相关问题
  12. 电脑耳机有声外放无声的解决方法
  13. Several alternative term weighting methods for text representation and ~~ ——1. Introduction 引言
  14. 收集广州周边徒步线路
  15. 扫描枪中文输入法导致乱码问题
  16. opporeno6pro+和reno5pro+参数配置详细
  17. ASCII码中不同字符分类、含义及相关技巧
  18. 新课程上线 | 学习使用 Kotlin 进行 Android 开发的最佳时机!
  19. 虎年啦,小老虎带你4.5分钟彻底掌握Linux中的创建-目录-文件(mkdir-touch)
  20. LC145 Binary Tree Postorder Traversal

热门文章

  1. HBuilderX自定义外部命令 - 右键复制文件相对路径/绝对路径
  2. Apache Spark 在eBay 的优化
  3. java 飞秋 demo_Java实现仿QQ、飞秋聊天程序
  4. 小Biu的骰子(概率dp)
  5. 会议录音转文字app有哪些?教你三种录音转文字的方法
  6. 学习用Python分析股票数据(入门)
  7. Scrapy 框架获取豆瓣电影的信息(包括图片)和电影评论-1
  8. 太空大战-第14届蓝桥杯国赛Scratch真题中级组第6题
  9. Go语言基础(10)-- 文件流
  10. ES中mapping讲解