此示例演示如何使用条形码参数,如果存在表面变形,'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')
![](https://i-blog.csdnimg.cn/blog_migrate/cef4df8431dbc1e66a29f7bc54bd6570.png)
*定义条形码区域---定义一些变量
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 ()
![](https://i-blog.csdnimg.cn/blog_migrate/0f863581db85baa7c8cb2cf26c099b63.png)
*第二部分
*读取扭曲的条形码
read_image (Image, 'barcode/gs1databar_limited/gs1databar_limited_cylinder')
![](https://i-blog.csdnimg.cn/blog_migrate/9144f7e006f3a1c775d6c3780a4640ea.png)
*使用默认设置
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 ()
![](https://i-blog.csdnimg.cn/blog_migrate/722654550dbec815ee4b54c2d7e4fd3b.png)
*清除句柄
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,可以正确得出结果