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

该示例展示了在处理存在表面变形的条形码时,设置'element_size_variable'参数为'true'的重要性。代码比较了在正常和扭曲条形码上使用该参数的解码结果,证明了在条形码弯曲时,启用该参数能成功解码。
摘要由CSDN通过智能技术生成

此示例演示如何使用条形码参数,如果存在表面变形,'element_size_variable';
为了说明参数的影响,两个解码结果对比显示。结果表明,在圆柱形表面变形,将条形码参数设置为“真”将导致成功解码


总代码:

* Initialization
dev_update_off ()
dev_close_window ()
* 
* Create two bar code model with different element_size_variable values
*创建两个具有不同元素大小变量值的条形码模型
create_bar_code_model ([], [], BarCodeHandle)
set_bar_code_param (BarCodeHandle, 'element_size_variable', 'false')


create_bar_code_model ([], [], BarCodeHandleVarSize)
set_bar_code_param (BarCodeHandleVarSize, 'element_size_variable', 'true')
CodeTypes := ['GS1 DataBar Limited','GS1 DataBar Expanded','GS1 DataBar Expanded Stacked']
* 
* Prepare graphics window
*读取图片
read_image (Image, 'barcode/gs1databar_limited/gs1databar_limited_no_deform')
*打开自适应图像大小的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
* 
* Define bar code region
*定义条形码区域---定义一些变量
DecodeRectRow := 315
DecodeRectColumn := 490
DecodeRectPhi := 0
DecodeRectLength1 := 410
DecodeRectLength2 := 200
* 
* Part 1
* Read bar code without distortions
* 
* Decode the bar code with default setting
*第一部分
*阅读条形码而不失真
*使用默认设置解码条形码
*Length1 Length2 指的是半宽半高
decode_bar_code_rectangle2 (Image, BarCodeHandle, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStrings)
get_bar_code_object (SymbolRegions, BarCodeHandle, 'all', 'symbol_regions')
* 
* Allow variable element sizes ('element_size_variable' = 'true')
decode_bar_code_rectangle2 (Image, BarCodeHandleVarSize, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStringsVarSize)
get_bar_code_object (SymbolRegionsVarSize, BarCodeHandleVarSize, 'all', 'symbol_regions')
* 
* Display results
Message := 'If the bar code is not deformed, it is found with default settings.'
Message[1] := 'Setting \'element_size_variable\' to \'true\' is not necessary.'
display_results (Image, SymbolRegions, SymbolRegionsVarSize, WindowHandle, DecodedDataStrings, DecodedDataStringsVarSize, Message)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Part 2
* Read distorted bar code
* 
read_image (Image, 'barcode/gs1databar_limited/gs1databar_limited_cylinder')
* 
* Use default setting
decode_bar_code_rectangle2 (Image, BarCodeHandle, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStrings)
get_bar_code_object (SymbolRegions, BarCodeHandle, 'all', 'symbol_regions')
* Use 'element_size_variable' = 'true'
decode_bar_code_rectangle2 (Image, BarCodeHandleVarSize, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStringsVarSize)
get_bar_code_object (SymbolRegionsVarSize, BarCodeHandleVarSize, 'all', 'symbol_regions')
* 
* Display results
Message := 'If the bar code is bended, the code will only be read with'
Message[1] := '\'element_size_variable\' set to \'true\'.'
display_results (Image, SymbolRegions, SymbolRegionsVarSize, WindowHandle, DecodedDataStrings, DecodedDataStringsVarSize, Message)
stop ()
* Cleanup memory
clear_bar_code_model (BarCodeHandleVarSize)
clear_bar_code_model (BarCodeHandle)

逐段分析:

dev_update_off ()
dev_close_window ()

*创建两个具有不同元素大小变量值的条形码模型
create_bar_code_model ([], [], BarCodeHandle)

*设置参数,并且选为false
set_bar_code_param (BarCodeHandle, 'element_size_variable', 'false')


create_bar_code_model ([], [], BarCodeHandleVarSize)
*设置参数,并且选为true
set_bar_code_param (BarCodeHandleVarSize, 'element_size_variable', 'true')


CodeTypes := ['GS1 DataBar Limited','GS1 DataBar Expanded','GS1 DataBar Expanded Stacked']

*读取图片
read_image (Image, 'barcode/gs1databar_limited/gs1databar_limited_no_deform')

*打开自适应图像大小的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')

*定义条形码区域---定义一些变量
DecodeRectRow := 315
DecodeRectColumn := 490
DecodeRectPhi := 0
DecodeRectLength1 := 410
DecodeRectLength2 := 200


*第一部分
*阅读条形码而不失真
*使用默认设置解码条形码
*Length1 Length2 指的是半宽半高
decode_bar_code_rectangle2 (Image, BarCodeHandle, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStrings)

*获取候选区域并显示结果
get_bar_code_object (SymbolRegions, BarCodeHandle, 'all', 'symbol_regions')

*允许可变元素大小('element_size_variable'='true')
decode_bar_code_rectangle2 (Image, BarCodeHandleVarSize, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStringsVarSize)

*获取候选区域并显示结果
get_bar_code_object (SymbolRegionsVarSize, BarCodeHandleVarSize, 'all', 'symbol_regions')

*如果条形码没有变形,则会使用默认设置找到它
*没有必要将‘元素大小变量’设置为‘真’。
Message := 'If the bar code is not deformed, it is found with default settings.'
Message[1] := 'Setting \'element_size_variable\' to \'true\' is not necessary.'

*显示结果
display_results (Image, SymbolRegions, SymbolRegionsVarSize, WindowHandle, DecodedDataStrings, DecodedDataStringsVarSize, Message)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

*第二部分
*读取扭曲的条形码
read_image (Image, 'barcode/gs1databar_limited/gs1databar_limited_cylinder')

*使用默认设置
decode_bar_code_rectangle2 (Image, BarCodeHandle, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStrings)

*获取候选区域并显示结果
get_bar_code_object (SymbolRegions, BarCodeHandle, 'all', 'symbol_regions')

* Use 'element_size_variable' = 'true'
decode_bar_code_rectangle2 (Image, BarCodeHandleVarSize, CodeTypes, DecodeRectRow, DecodeRectColumn, DecodeRectPhi, DecodeRectLength1, DecodeRectLength2, DecodedDataStringsVarSize)

*获取候选区域并显示结果
get_bar_code_object (SymbolRegionsVarSize, BarCodeHandleVarSize, 'all', 'symbol_regions')

*显示结果
Message := 'If the bar code is bended, the code will only be read with'
Message[1] := '\'element_size_variable\' set to \'true\'.'
display_results (Image, SymbolRegions, SymbolRegionsVarSize, WindowHandle, DecodedDataStrings, DecodedDataStringsVarSize, Message)
stop ()

*清除句柄
clear_bar_code_model (BarCodeHandleVarSize)
clear_bar_code_model (BarCodeHandle)

 'element_size_variable':

在某些条形码图像中,给定条形码对象的最小元素大小可能不同。这些变形可能由透视投影或条形码打印表面的变形(例如瓶子上的桶变形)引起。默认情况下,条形码阅读器无法处理此类失真。然而,如果“element_size_variable”设置为“true”,条形码阅读器将尝试补偿此类失真。请注意,在某些情况下,仍然无法取消条形码图像的干扰。

参数“element_size_variable”仅适用于以下条形码类型:

GS1数据库有限公司

GS1数据库扩展

GS1数据库扩展堆栈

任何其他条形码类型不受此参数的影响。

价值观:“假”、“真”

默认值:“false”

由此例子可以得出,当条形码出现部分扭曲,'element_size_variable'参数有必要需要设置成true,可以正确得出结果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值