*这个实例演示了在有表面变形的情况下,如何通过设置一维码读取器的参数’最小元素尺寸是否可变’来确保条码的正确性,
- This example demonstrates how to use the bar code parameter
- ‘element_size_variable’ if surface deformations are present.
- 为了演示这个参数的效果,两个解码结果都显示以作对比。结果显示
*在圆柱面变形形式下的条码,设置这个参数能够保证解码的正确性 - To illustrate the effect of the parameter, both decoding results
- are shown in contrast. It is shown that, under cylindrical
- surface deformation, setting the bar code parameter to ‘true’
- will lead to successful decoding.
- 初始化
- Initialization
*关闭窗体更新
dev_update_off ()
*关闭窗体
dev_close_window () - 创建两个一维码读取句柄,分别设置不同的’元素最小尺寸是否可变’
- Create two bar code model with different element_size_variable values
*创建第一个一维码读取句柄
create_bar_code_model ([], [], BarCodeHandle)
*设置’元素最小尺寸是否可变’为false,为不可变化
set_bar_code_param (BarCodeHandle, ‘element_size_variable’, ‘false’)
*创建第二个一维码读取句柄
create_bar_code_model ([], [], BarCodeHandleVarSize)
*设置’元素最小尺寸是否可变’为false,为可变化
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
*在区域内解码
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)
*右下角显示’Press F5 TO CONTINUE’
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)