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

使用条形码参数'meas_thresh_abs'的示例程序;该参数可用于在查找我们希望具有高对比度的条形码符号区域时减少误报的数量。为了人工证明这一点,我们试图找到条形码类型的药典,它没有检查字符,因此在噪声中很容易识别。作为“噪音”,我们使用完全不包含任何条形码的图像。通过使用值大于0.0的“meas_thresh_abs”,我们强制条形码阅读器仅使用绝对对比度至少为该值的扫描线部分,从而减少误报的数量。


总代码:

* Create bar code reader model
create_bar_code_model ([], [], BarCodeHandle)
* 
* Initialization
*设置变量、pc、窗口为off状态
dev_update_var ('off')
dev_update_pc ('off')
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
* 
* Read and display example images without any visible bar codes
*读取并显示没有任何可见条形码的示例图像
ExampleImages := ['zeiss1','patras','fabrik']
for Index := 0 to |ExampleImages| - 1 by 1
    FileName := ExampleImages[Index]
    read_image (Image, FileName)
    rgb1_to_gray (Image, Image)
    * 
    * Set display defaults
    *设置显示默认值
    get_image_size (Image, Width, Height)
    *设置图像的宽高与窗口保持一致
    dev_set_window_extents (-1, -1, Width, Height)
    dev_display (Image)
    * 
    * First, disable absolute thresholds by setting the value 0.0
    * for the parameter 'meas_thresh_abs'
    *首先,通过设置值0.0禁用绝对阈值
    *参数'meas_thresh_abs'

    MeasThreshAbsValue := 0.0
    set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
    * 
    * The bar code reader finds many (wrong) potential bar codes using
    * scanlines that have a low absolute contrast
    *条形码阅读器使用绝对对比度低的扫描线
    *寻找区域
    find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
    dev_set_color ('red')
    dev_display (SymbolRegions)
    disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes','  with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 12, 12, '', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * 
    * Now, set the bar code reader parameter 'meas_thresh_abs' to a value
    * greater than 0.0 to use only parts of a scanline having an absolute
    * contrast of at least that value.
    
    *现在,将条形码阅读器参数“meas_thresh_abs”设置为一个值
    *大于0.0以仅使用具有绝对至少是这个值的对比度。
    
    MeasThreshAbsValue := 10.0
    set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
    * 
    * Look again for a bar code. Now, significant less scanlines should be found.
    find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
    dev_set_color ('lime green')
    dev_display (SymbolRegions)
    disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes','  with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 5 * 12, 12, '', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
endfor
* 
*把不是很明显的区域去掉,比较明显的提取出来
* Close the bar code reader
clear_bar_code_model (BarCodeHandle)

逐段分析:

*创建模型
create_bar_code_model ([], [], BarCodeHandle)

*初始化
*设置变量、pc、窗口为off状态
dev_update_var ('off')
dev_update_pc ('off')
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
*读取并显示没有任何可见条形码的示例图像
ExampleImages := ['zeiss1','patras','fabrik']

for Index := 0 to |ExampleImages| - 1 by 1
    FileName := ExampleImages[Index]

    *读取图片
    read_image (Image, FileName)

    *灰度化
    rgb1_to_gray (Image, Image)
    
    *设置显示默认值
    get_image_size (Image, Width, Height)

    *设置图像的宽高与窗口保持一致
    dev_set_window_extents (-1, -1, Width, Height)
    dev_display (Image)

    *首先,通过设置值0.0禁用绝对阈值
    *参数'meas_thresh_abs'

    MeasThreshAbsValue := 0.0
    set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)

    *条形码阅读器使用绝对对比度低的扫描线寻找区域
    find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
    dev_set_color ('red')

    *显示寻找到的区域
    dev_display (SymbolRegions)

    *显示信息
    disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes','  with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 12, 12, '', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()

    *现在,将条形码阅读器参数“meas_thresh_abs”设置为一个值
    *大于0.0以仅使用具有绝对至少是这个值的对比度。
    
    *阈值改为10.0
    MeasThreshAbsValue := 10.0
    set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
  
    *再次查找条形码。现在,应该找到显著的扫描线。
    find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
    dev_set_color ('lime green')

    *显示寻找到的区域
    dev_display (SymbolRegions)
    
    *显示信息
    disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes','  with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 5 * 12, 12, '', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
endfor

*清除句柄
clear_bar_code_model (BarCodeHandle)


meas_thresh_abs把不是很明显的区域去掉,比较明显的提取出来

 'meas_thresh_abs':

如果扫描线放置在没有或只有非常小的灰度值动态范围的图像区域(例如,在所有灰度值接近255的白色区域),基于“meas_thresh”的边缘检测阈值将被计算得非常小。这通常会导致检测到大量假边缘。”meas_thresh_abs’用于防止此类误判。如果基于“meas_thresh”的阈值小于“meas_thresh_abs”的值,则将后者用作阈值。默认情况下,“meas_thresh_abs”设置为5.0。较大的值可能更适合于高噪声级别的图像。另一方面,在对比度非常弱的无噪图像中,此参数可能会干扰真实边缘的检测,因此可能需要将其减小,甚至通过将其设置为0.0来完全禁用。

典型值:[0.0…10.0]

默认值:5.0

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值