基于Halcon学习的一维码识别【七】barcode.param_meas_param_estimation.hdev

该程序演示了参数“meas_param_estimation”的使用。参数“meas_param_estimation”对于增加元素尺寸非常小的条形码的读取性能(1-1.5像素)以及其他图像瑕疵,例如模糊和噪音。在下面的示例中,显示了一系列这样的条形码图像阅读参数的两个设置的结 果比较了“meas_param


总代码:

*更新状态设置成off
dev_update_off ()
dev_close_window ()
*读取图片
read_image (Image, 'barcode/ean13/ean13_meas_param_estimation_01')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
dev_set_draw ('margin')
dev_set_line_width (3)

*打开一个文本窗口
*消息[0]:=“该程序演示了参数'meas_param_estimation\'的使用。”。\不
*消息[2]:=“参数'meas_param_estimation'”对于提高具有非常小的元素大小(1-1.5像素)
*的条形码的读取性能以及诸如模糊和噪声等附加图像伪影(如左图所示)特别有用
dev_open_window (0, Width + 10, 660, Height, 'white', WindowHandleText)
set_display_font (WindowHandleText, 14, 'mono', 'true', 'false')
Message[0] := 'This program demonstrates the use of the parameter \'meas_param_estimation\'.\n'
Message[1] := ' '
Message[2] := 'The parameter \'meas_param_estimation\' can be particularly useful to increase the reading performance for barcodes with a very small element size (1-1.5 pixels) together with additional image artifacts such as blur and noise, such as in the image shown to the left.\n'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,60})\\s','replace_all'],'$1\n')

*显示信息
disp_message (WindowHandleText, MessageWrapped, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandleText, 'black', 'false')
stop ()
* 

* Create barcode model.
*创建条形码模型。
create_bar_code_model ([], [], BarCodeHandle)
* 

* As we expect to read codes with a small element size, we set the
* parameter 'element_size_min' to 1.0.

*由于我们希望以较小的元素大小读取代码,我们设置
*参数'element_size_min'为1.0
*清除窗口
dev_clear_window ()
Message := []
Message[0] := 'As we expect to read codes with a small element size, we set the parameter \'element_size_min\' to 1.0.'
Message[1] := ' '
Message[2] := 'In the following example a series of such barcode images are read and the results for the two settings of the parameter \'meas_param_estimation\' are compared.'
* 
MessageWrapped := regexp_replace(Message + ' ',['(.{0,60})\\s','replace_all'],'$1\n')
*显示信息
disp_message (WindowHandleText, MessageWrapped, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandleText, 'black', 'false')
stop ()

*设置最小参数为1
set_bar_code_param (BarCodeHandle, 'element_size_min', 1.0)
* disable advanced post processing features, so effect of improved edge extraction
* is visible in this dataset
**禁用高级后处理功能,以便在此数据集中可以看到改进的边缘提取效果

*'merge_scanlines'
*如果无法成功读取足够多的扫描线(请参阅“最小相同扫描线”),也就是说,
*由于条形码部分被遮挡或损坏,正在尝试合并现有扫描线。然后,这些合并的扫描线被再次解码。
*此附加解码步骤仅对非堆叠条形码类型执行,并可出于性能原因禁用。
*值列表:[“真”、“假”]
*默认值:“true”
set_bar_code_param (BarCodeHandle, 'merge_scanlines', 'false')

set_bar_code_param (BarCodeHandle, 'print_growth_inversion', 'false')
*设置条形码类型
CodeType := 'EAN-13'
* 变量为0
NumDecodedParamEst := 0
NumDecodedDefault := 0
for I := 1 to 10 by 1
    * Read image and reduce element size
    *读取图片
    read_image (Image, 'barcode/ean13/ean13_meas_param_estimation_' + (I$'.2'))
    * Read barcode with 'meas_param_estimation' == 'false'
    *设置参数为false
    set_bar_code_param (BarCodeHandle, 'meas_param_estimation', 'false')
    *开始寻找条形码
    find_bar_code (Image, SymbolRegions, BarCodeHandle, CodeType, DecodedDataStrings)
    
    * Read barcode with 'meas_param_estimation' == 'true'
    *设置参数为true
    set_bar_code_param (BarCodeHandle, 'meas_param_estimation', 'true')
    *开始寻找条形码
    find_bar_code (Image, SymbolRegionsParamEst, BarCodeHandle, CodeType, DecodedDataStringsParamEst)
    * 
    * 
    * Display results
    *显示结果
    get_image_size (Image, Width, Height)
    *设置活动窗口
    dev_set_window (WindowHandle)
    dev_display (Image)
    dev_set_color ('blue')
    
    *显示条形码区域
    dev_display (SymbolRegions)
    dev_set_color ('green')
    dev_display (SymbolRegionsParamEst)
    
    *设置活动窗口
    dev_set_window (WindowHandleText)
    *清除窗口
    dev_clear_window ()
    * 
    Message := 'Decoded data with \'meas_param_estimation\' == \'false\':'
    disp_message (WindowHandleText, Message, 'window', 12, 12, 'black', 'false')
    if (|DecodedDataStrings| > 0)
        disp_message (WindowHandleText, DecodedDataStrings, 'window', 42, 12, 'blue', 'false')
        NumDecodedDefault := NumDecodedDefault + |DecodedDataStrings|
    else
        disp_message (WindowHandleText, 'No decode', 'window', 42, 12, 'red', 'false')
    endif
    * 
    Message := 'Decoded data with \'meas_param_estimation\' == \'true\':'
    disp_message (WindowHandleText, Message, 'window', 92, 12, 'black', 'false')
    if (|DecodedDataStringsParamEst| > 0)
        disp_message (WindowHandleText, DecodedDataStringsParamEst, 'window', 122, 12, 'forest green', 'false')
        NumDecodedParamEst := NumDecodedParamEst + |DecodedDataStringsParamEst|
    else
        disp_message (WindowHandleText, 'No decode', 'window', 122, 12, 'red', 'false')
    endif
    wait_seconds (2)
endfor
clear_bar_code_model (BarCodeHandle)
* 
dev_clear_window ()
* 
Message := 'Reading performance:\n'
disp_message (WindowHandleText, Message, 'window', 12, 12, 'black', 'false')
Message := 'With \'meas_param_estimation\' == \'false\': ' + NumDecodedDefault + ' out of 10\n'
disp_message (WindowHandleText, Message, 'window', 42, 12, 'black', 'false')
Message := 'With \'meas_param_estimation\' == \'true\': ' + NumDecodedParamEst + ' out of 10\n'
disp_message (WindowHandleText, Message, 'window', 72, 12, 'black', 'false')

逐段分析:

*更新状态设置成off
dev_update_off ()
dev_close_window ()

*读取图片
read_image (Image, 'barcode/ean13/ean13_meas_param_estimation_01')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
dev_set_draw ('margin')
dev_set_line_width (3)

*打开一个文本窗口
*消息[0]:=“该程序演示了参数'meas_param_estimation\'的使用。”。\不
*消息[2]:=“参数'meas_param_estimation'”对于提高具有非常小的元素大小(1-1.5像素)
*的条形码的读取性能以及诸如模糊和噪声等附加图像伪影(如左图所示)特别有用

dev_open_window (0, Width + 10, 660, Height, 'white', WindowHandleText)
set_display_font (WindowHandleText, 14, 'mono', 'true', 'false')
Message[0] := 'This program demonstrates the use of the parameter \'meas_param_estimation\'.\n'
Message[1] := ' '
Message[2] := 'The parameter \'meas_param_estimation\' can be particularly useful to increase the reading performance for barcodes with a very small element size (1-1.5 pixels) together with additional image artifacts such as blur and noise, such as in the image shown to the left.\n'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,60})\\s','replace_all'],'$1\n')

*显示信息
disp_message (WindowHandleText, MessageWrapped, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandleText, 'black', 'false')
stop ()

*创建条形码模型。
create_bar_code_model ([], [], BarCodeHandle)

*由于我们希望以较小的元素大小读取代码,我们设置
*参数'element_size_min'为1.0
*清除窗口
dev_clear_window ()
Message := []
Message[0] := 'As we expect to read codes with a small element size, we set the parameter \'element_size_min\' to 1.0.'
Message[1] := ' '
Message[2] := 'In the following example a series of such barcode images are read and the results for the two settings of the parameter \'meas_param_estimation\' are compared.'

MessageWrapped := regexp_replace(Message + ' ',['(.{0,60})\\s','replace_all'],'$1\n')

*显示信息
disp_message (WindowHandleText, MessageWrapped, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandleText, 'black', 'false')
stop ()

*设置最小参数为1
set_bar_code_param (BarCodeHandle, 'element_size_min', 1.0)

*禁用高级后处理功能,以便在此数据集中可以看到改进的边缘提取效果

*'merge_scanlines'
*如果无法成功读取足够多的扫描线(请参阅“最小相同扫描线”),也就是说,
*由于条形码部分被遮挡或损坏,正在尝试合并现有扫描线。然后,这些合并的扫描线被再次解码。
*此附加解码步骤仅对非堆叠条形码类型执行,并可出于性能原因禁用。
*值列表:[“真”、“假”]
*默认值:“true”

set_bar_code_param (BarCodeHandle, 'merge_scanlines', 'false')
set_bar_code_param (BarCodeHandle, 'print_growth_inversion', 'false')

*设置条形码类型
CodeType := 'EAN-13'

* 变量为0
NumDecodedParamEst := 0
NumDecodedDefault := 0

*对十张图片进行循环
for I := 1 to 10 by 1
    * Read image and reduce element size
    *读取图片
    read_image (Image, 'barcode/ean13/ean13_meas_param_estimation_' + (I$'.2'))

    *设置参数为false
    set_bar_code_param (BarCodeHandle, 'meas_param_estimation', 'false')

    *开始寻找条形码
    find_bar_code (Image, SymbolRegions, BarCodeHandle, CodeType, DecodedDataStrings)
 

    *设置参数为true
    set_bar_code_param (BarCodeHandle, 'meas_param_estimation', 'true')

    *开始寻找条形码
    find_bar_code (Image, SymbolRegionsParamEst, BarCodeHandle, CodeType, DecodedDataStringsParamEst)

    *显示结果
    get_image_size (Image, Width, Height)

    *设置活动窗口
    dev_set_window (WindowHandle)
    dev_display (Image)
    dev_set_color ('blue')
    
    *显示条形码区域
    dev_display (SymbolRegions)
    dev_set_color ('green')
    dev_display (SymbolRegionsParamEst)

    *设置活动窗口
    dev_set_window (WindowHandleText)

    *清除窗口
    dev_clear_window ()
    

    *下方的if语句是为了计算出参数设置成false或者true是能够正确识别的次数

    Message := 'Decoded data with \'meas_param_estimation\' == \'false\':'
    disp_message (WindowHandleText, Message, 'window', 12, 12, 'black', 'false')
    if (|DecodedDataStrings| > 0)
        disp_message (WindowHandleText, DecodedDataStrings, 'window', 42, 12, 'blue', 'false')
        NumDecodedDefault := NumDecodedDefault + |DecodedDataStrings|
    else
        disp_message (WindowHandleText, 'No decode', 'window', 42, 12, 'red', 'false')
    endif
    

    Message := 'Decoded data with \'meas_param_estimation\' == \'true\':'
    disp_message (WindowHandleText, Message, 'window', 92, 12, 'black', 'false')
    if (|DecodedDataStringsParamEst| > 0)
        disp_message (WindowHandleText, DecodedDataStringsParamEst, 'window', 122, 12, 'forest green', 'false')
        NumDecodedParamEst := NumDecodedParamEst + |DecodedDataStringsParamEst|
    else
        
        *显示信息
        disp_message (WindowHandleText, 'No decode', 'window', 122, 12, 'red', 'false')
    endif
    
    *等待2秒
    wait_seconds (2)
endfor

*清除模型句柄
clear_bar_code_model (BarCodeHandle)

*清空窗口
dev_clear_window ()
*
Message := 'Reading performance:\n'
disp_message (WindowHandleText, Message, 'window', 12, 12, 'black', 'false')
Message := 'With \'meas_param_estimation\' == \'false\': ' + NumDecodedDefault + ' out of 10\n'

*显示信息
disp_message (WindowHandleText, Message, 'window', 42, 12, 'black', 'false')
Message := 'With \'meas_param_estimation\' == \'true\': ' + NumDecodedParamEst + ' out of 10\n'
disp_message (WindowHandleText, Message, 'window', 72, 12, 'black', 'false')


'merge_scanlines'
*如果无法成功读取足够多的扫描线(请参阅“最小相同扫描线”),也就是说,由于条形码部分被遮挡或损坏,正在尝试合并现有扫描线。然后,这些合并的扫描线被再次解码。
此附加解码步骤仅对非堆叠条形码类型执行,并可出于性能原因禁用。
*值列表:[“真”、“假”]
*默认值:“true”

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值