HALCON例程:2d_data_codes_data_access.hdev

一、程序解读

* 程序描述:

        这个程序展示了如何在搜索数据代码时访问中间结果。这使我们可以获得有关如何增强搜索过程的运行时间的提示,或者为什么没有找到或解码符号。

        该程序首先创建一个2d数据代码模型,并查询可用参数的名称。在下一步中,在每个图像中搜索和解码数据代码符号。然后查询有关搜索过程和符号(候选)的进一步信息和一些更具体的信息,以获得关于运行时如何增强搜索过程的提示,或者为什么没有找到或解码符号。左侧显示可用参数列表,右侧显示参数值。

* ***************************************************************

总结:

        1.正常二维码图像:获得搜索的基础参数;分割为前景及背景模块,获得有关符号参数结果;获得解码字符串及其ASCII码值。

        2.找到但未解码符号,查询状态,decoding_error错误解码,显示模块的二进制符号数据。

        3.未搜索到二维码,查询状态,aborted Search 搜索失败,显示前3个无效候选并查询其信息;如果超过3个候选项,则显示所有候选项。

        4.显示设置:陈列所有参数,高亮显示获得的参数、图像信息、及参数信息。

搜索的基础参数:
'min_search_level'
'max_search_level'
'pass_num'
'result_num'  结果数
'candidate_num'  候选数
'undecoded_num'  解码符号数
'aborted_num'    中止搜索数

        5.程序的大量代码为显示设置。

二、代码详解

* Initialize image path.初始化图片路径。

dev_update_off ()
dev_close_window ()
ImagePath := 'datacode/ecc200/'
ImageFiles := ImagePath +
['ecc200_distorted_001','ecc200_distorted_002','ecc200_to_preprocess_002','ecc200_to_preprocess_004','ecc200_to_preprocess_003']

* 打开参数列表窗口。

dev_open_window (0, 0, 550, 600, 'black', ParamWindow)
set_display_font (ParamWindow, 14, 'mono', 'true', 'false')

* 简短描述
Message := 'This program shows how to access intermediate'
Message[1] := 'results while searching for ECC 200 data codes.'
Message[2] := ' '
Message[3] := 'This enables to obtain hints how the search process'
Message[4] := 'can be enhanced with respect to runtime or why a'
Message[5] := 'symbol is not found or decoded.'
disp_message (ParamWindow, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (ParamWindow, 'black', 'true')
stop ()

Step 1: Create a 2d data code model
* -------------------------------------------------------
*创建2d数据代码模型,并将模型设置为中间结果的持久存储。

create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters','enhanced_recognition', DataCodeHandle)
set_data_code_2d_param (DataCodeHandle, 'persistence', 1)
*
* Query the parameter names
*获取可用于查询搜索的字母数字结果和图标对象的参数列表
query_data_code_2d_params (DataCodeHandle, 'get_result_params', GenParamName)
query_data_code_2d_params (DataCodeHandle, 'get_result_objects', GenObjectNames)
*
*设置参数名称的颜色
*gen_tuple_const:生成特定长度的元组并初始化元素

ColorAlph := gen_tuple_const(|GenParamName|,'#808080')
ColorIcon := gen_tuple_const(|GenObjectNames|,'#808080')

* Open new windows
* ------------------------------
* Open window for iconic objects. 打开图标对象窗口
WWidth := 600
WHeight := 300
WRatio := real(WWidth) / WHeight
dev_open_window (0, 560, WWidth, WHeight, 'white', ImageWindow)
set_display_font (ImageWindow, 14, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
*
* Open window for alphanumeric results. 打开窗口以查看字母数字结果
dev_open_window (360, 560, 600, 240, 'white', ResultWindow)
set_display_font (ResultWindow, 14, 'mono', 'true', 'false')

* Step 2: Read the data codes 读取二维码
*搜索每个图像中的数据代码,并尝试解码符号。然后查询字母数字结果和图标对象的搜索和解码过程。

for Index := 0 to |ImageFiles| - 1 by 1
    dev_set_window (ImageWindow)
    dev_clear_window ()
    read_image (Image, ImageFiles[Index])

    * 在候选搜索或解码过程中,一些图像被修改以显示不同的问题。
    if (Index == 2)
        zoom_image_size (Image, Image, 230, 230, 'constant')
    endif
    if (Index == 4)
        gray_erosion_rect (Image, Image, 3, 3)
        gauss_filter (Image, Image, 3)
    endif
    *
    determine_part (Image, WRatio, WWidth, WHeight, Row1, Col1, Row2, Col2)
    dev_set_part (Row1, Col1, Row2, Col2)
    dev_display (Image)
    disp_message (ImageWindow, 'Example ' + (Index + 1) + ' of ' + |ImageFiles|, 'window', 12, 12, 'black', 'true')

    * Set parameters
    * 为特定图像设置模块的最小像素,以减少候选图像的数量。

    if (Index == 3)
        set_data_code_2d_param (DataCodeHandle, 'module_size_min', 24)
    endif
    if (Index == 4)
        set_data_code_2d_param (DataCodeHandle, 'module_size_min', 10)
    endif

*将Index == 2 的‘small_modules_robustness’设置为'high',因为模块太小了(~ 2像素)。

    if (Index == 2)
        set_data_code_2d_param (DataCodeHandle, 'small_modules_robustness', 'high')
    else
        set_data_code_2d_param (DataCodeHandle, 'small_modules_robustness', 'low')
    endif
    * Find and decode the data codes. 寻找并解码

    find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultH
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值