该程序演示了如何使用标准识别、增强识别和最大识别的三种基本默认设置读取二维数据代码。
在第一步中,您可以选择要处理的符号类型。然后获得相应的图像,并为每个默认设置创建数据代码模型。在下一步中,使用每个生成的数据代码模型在相应的图像中搜索每个符号类型的数据代码,结果显示在图形窗口中。
总代码:
*初始化视觉设置
*更新状态设为off
dev_update_off ()
dev_close_window ()
*打开窗口
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_color ('green')
dev_set_line_width (3)
Message := 'This program demonstrates how to read 2d data'
Message[1] := 'codes with the following default settings:'
Message[2] := ' \'standard recognition\''
Message[3] := ' \'enhanced recognition\''
Message[4] := ' \'maximum recognition\''
Message[5] := ' '
Message[6] := 'Note that you can choose the desired symbol'
Message[7] := 'types by (un)commenting the corresponding'
Message[8] := 'lines in the code.'
*显示信息--本程序演示如何使用以下默认设置读取二维数据代码:
*标准识别、提高认识、最大识别度
*请注意,您可以通过(取消)注释代码中相应的行来选择所需的符号类型。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Step 1: Choose the symbol type
* -------------------------------------------------------
* Choose the symbol types by (un)commenting the corresponding
* lines. Note that you can choose more than one symbol type.
*第一步:选择符号类型
*通过(取消)注释相应的行来选择符号类型。请注意,您可以选择多个符号类型。
*定义型号
SymbolType := []
SymbolType := [SymbolType,'QR Code']
SymbolType := [SymbolType,'Micro QR Code']
SymbolType := [SymbolType,'PDF417']
SymbolType := [SymbolType,'Aztec Code']
SymbolType := [SymbolType,'Data Matrix ECC 200']
*
* Loop over all chosen symbol types
* -------------------------------------------------------
* Get images of the chosen symbol types, create the
* corresponding data code model with each default setting,
* read the data codes with each model and display the results
*循环所有选定的符号类型
*获取所选符号类型的图像,使用每个默认设置创建相应的数据代码模型,读取每个模型的数据代码并显示结果
*不断循环
for Index := 0 to |SymbolType| - 1 by 1
*
* Step 2 : Get image names for the current symbol type
* Ecc 200
*步骤2:获取当前符号类型的图像名称
*Ecc 200
if (SymbolType[Index] == 'Data Matrix ECC 200')
list_image_files ('datacode/ecc200', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'(ecc200_cpu_)|(ecc200_disturbed_0)')
* QR Code
elseif (SymbolType[Index] == 'QR Code')
list_image_files ('datacode/qrcode', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'qr_workpiece')
* Micro QR Code
elseif (SymbolType[Index] == 'Micro QR Code')
list_image_files ('datacode/micro_qr', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'micro_qr')
* PDF417
elseif (SymbolType[Index] == 'PDF417')
list_image_files ('datacode/pdf417', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'(pdf417_hd)|(pdf417_misc)')
* Aztec
elseif (SymbolType[Index] == 'Aztec Code')
list_image_files ('datacode/aztec', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'aztec')
endif
*
* Step 3: Create data code models
* ---------------------------------------------------
* Create a model of the current symbol type for each
* default setting standard, enhanced, and maximum.
*第3步:创建数据代码模型
*为每个符号创建当前符号类型的模型
*默认设置标准、增强和最大值。
create_data_code_2d_model (SymbolType[Index], 'default_parameters', 'standard_recognition', DataCodeHandleStandard)
create_data_code_2d_model (SymbolType[Index], 'default_parameters', 'enhanced_recognition', DataCodeHandleEnhanced)
create_data_code_2d_model (SymbolType[Index], 'default_parameters', 'maximum_recognition', DataCodeHandleMaximum)
*
* Loop over all images
* ----------------------------------------------------
* Search and read the data codes in each image and
* display the decoded string for each found data code
*循环所有图像
*搜索并读取每个图像中的数据代码
*显示每个找到的数据代码的解码字符串
NLoops := 4
for I := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[I])
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
dev_display (Image)
*
* Step 4: Read the data codes
* -------------------------------------------
* Find and decode the data codes with each
* data code model and measure the runtime
*
* Standard mode
*4.读取数据代码
*查找并解码每个数据代码模型和运行时度量
*标准模式
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleStandard, [], [], ResultHandles, DecodedDataStrings)
count_seconds (T1)
for N := 1 to NLoops by 1
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleStandard, [], [], ResultHandles, DecodedDataStrings)
endfor
count_seconds (T2)
FoundStandard := |DecodedDataStrings|
TimeStandard := 1000 * (T2 - T1) / real(NLoops)
*
* Enhanced mode
*增强模式
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleEnhanced, [], [], ResultHandles, DecodedDataStrings)
count_seconds (T1)
for N := 1 to NLoops by 1
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleEnhanced, [], [], ResultHandles, DecodedDataStrings)
endfor
count_seconds (T2)
FoundEnhanced := |DecodedDataStrings|
TimeEnhanced := 1000 * (T2 - T1) / real(NLoops)
*
* Maximum mode
*最大模式
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleMaximum, [], [], ResultHandles, DecodedDataStrings)
count_seconds (T1)
for N := 1 to NLoops by 1
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleMaximum, [], [], ResultHandles, DecodedDataStrings)
endfor
count_seconds (T2)
FoundMaximum := |DecodedDataStrings|
TimeMaximum := 1000 * (T2 - T1) / real(NLoops)
*
* Generate the message for the runtimes
* ---------------------------------------
*为运行时生成消息
ResultMessage := 'Runtime of recognition modes:'
Color := gen_tuple_const(4,'black')
* Standard
*标准
ResultMessage[1] := ' standard mode:' + TimeStandard$'7.2f' + ' ms'
if (FoundStandard == 0)
ResultMessage[1] := ResultMessage[1] + ' (no symbol found)'
Color[1] := 'red'
endif
* Enhanced
*增强
ResultMessage[2] := ' enhanced mode:' + TimeEnhanced$'7.2f' + ' ms'
if (FoundEnhanced == 0)
ResultMessage[2] := ResultMessage[2] + ' (no symbol found)'
Color[2] := 'red'
endif
* Maximum
*最大
ResultMessage[3] := ' maximum mode: ' + TimeMaximum$'7.2f' + ' ms'
if (FoundMaximum == 0)
ResultMessage[3] := ResultMessage[3] + ' (no symbol found)'
Color[3] := 'red'
endif
*
* Step 5: Display the results
*第5步:显示结果
* --------------------------------------------
TitleMessage := SymbolType[Index] + ': Image ' + (I + 1) + ' of ' + |ImageFiles|
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, ResultMessage, 'forest green', Color)
*
* Deacivate the following lines to run the program without breaks
*取消下列行以不间断地运行程序
if (I < |ImageFiles| - 1 or Index < |SymbolType| - 1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
*
* Clear the 2d data code models
*清除二维数据代码模型
clear_data_code_2d_model (DataCodeHandleStandard)
clear_data_code_2d_model (DataCodeHandleEnhanced)
clear_data_code_2d_model (DataCodeHandleMaximum)
endfor
逐段分析:
*初始化视觉设置
*更新状态设为off
dev_update_off ()
dev_close_window ()
*打开窗口
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_color ('green')
dev_set_line_width (3)
Message := 'This program demonstrates how to read 2d data'
Message[1] := 'codes with the following default settings:'
Message[2] := ' \'standard recognition\''
Message[3] := ' \'enhanced recognition\''
Message[4] := ' \'maximum recognition\''
Message[5] := ' '
Message[6] := 'Note that you can choose the desired symbol'
Message[7] := 'types by (un)commenting the corresponding'
Message[8] := 'lines in the code.'
*显示信息--本程序演示如何使用以下默认设置读取二维数据代码:
*标准识别、提高认识、最大识别度
*请注意,您可以通过(取消)注释代码中相应的行来选择所需的符号类型。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*第一步:选择符号类型
*通过(取消)注释相应的行来选择符号类型。请注意,您可以选择多个符号类型。
*定义型号
SymbolType := []
SymbolType := [SymbolType,'QR Code']
SymbolType := [SymbolType,'Micro QR Code']
SymbolType := [SymbolType,'PDF417']
SymbolType := [SymbolType,'Aztec Code']
SymbolType := [SymbolType,'Data Matrix ECC 200']
*循环所有选定的符号类型
*获取所选符号类型的图像,使用每个默认设置创建相应的数据代码模型,读取每个模型的数据代码并显示结果
*不断循环
for Index := 0 to |SymbolType| - 1 by 1
*步骤2:获取当前符号类型的图像名称Ecc 200
if (SymbolType[Index] == 'Data Matrix ECC 200')
list_image_files ('datacode/ecc200', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'(ecc200_cpu_)|(ecc200_disturbed_0)')
* QR Code
elseif (SymbolType[Index] == 'QR Code')
*遍历图片
list_image_files ('datacode/qrcode', 'default', [], ImageFiles)
*定义图片路径
ImageFiles := regexp_select(ImageFiles,'qr_workpiece')
* Micro QR Code
elseif (SymbolType[Index] == 'Micro QR Code')
list_image_files ('datacode/micro_qr', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'micro_qr')
* PDF417
elseif (SymbolType[Index] == 'PDF417')
list_image_files ('datacode/pdf417', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'(pdf417_hd)|(pdf417_misc)')
* Aztec
elseif (SymbolType[Index] == 'Aztec Code')
list_image_files ('datacode/aztec', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'aztec')
endif
*第3步:创建数据代码模型
*为每个符号创建当前符号类型的模型
*默认设置标准、增强和最大值。
create_data_code_2d_model (SymbolType[Index], 'default_parameters', 'standard_recognition', DataCodeHandleStandard)
create_data_code_2d_model (SymbolType[Index], 'default_parameters', 'enhanced_recognition', DataCodeHandleEnhanced)
create_data_code_2d_model (SymbolType[Index], 'default_parameters', 'maximum_recognition', DataCodeHandleMaximum)
e
*循环所有图像
*搜索并读取每个图像中的数据代码
*显示每个找到的数据代码的解码字符串
NLoops := 4
for I := 0 to |ImageFiles| - 1 by 1
*读取图片
read_image (Image, ImageFiles[I])
*打开自适应图片的窗口
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
*显示图片
dev_display (Image)
*4.读取数据代码
*查找并解码每个数据代码模型和运行时度量
*标准模式--寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleStandard, [], [], ResultHandles, DecodedDataStrings)
*计算开始时间
count_seconds (T1)
for N := 1 to NLoops by 1
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleStandard, [], [], ResultHandles, DecodedDataStrings)
endfor
*计算结束时间
count_seconds (T2)
FoundStandard := |DecodedDataStrings|
*计算时间
TimeStandard := 1000 * (T2 - T1) / real(NLoops)
*增强模式--寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleEnhanced, [], [], ResultHandles, DecodedDataStrings)
*计算开始时间
count_seconds (T1)
for N := 1 to NLoops by 1
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleEnhanced, [], [], ResultHandles, DecodedDataStrings)
endfor
*计算结束时间
count_seconds (T2)
FoundEnhanced := |DecodedDataStrings|
*计算时间
TimeEnhanced := 1000 * (T2 - T1) / real(NLoops)
*最大模式--寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleMaximum, [], [], ResultHandles, DecodedDataStrings)
*计算开始时间
count_seconds (T1)
for N := 1 to NLoops by 1
find_data_code_2d (Image, SymbolXLDs, DataCodeHandleMaximum, [], [], ResultHandles, DecodedDataStrings)
endfor
*计算结束时间
count_seconds (T2)
FoundMaximum := |DecodedDataStrings|
*计算时间
TimeMaximum := 1000 * (T2 - T1) / real(NLoops)
*为运行时生成消息
*识别模式的运行时间:
ResultMessage := 'Runtime of recognition modes:'
Color := gen_tuple_const(4,'black')
*标准
ResultMessage[1] := ' standard mode:' + TimeStandard$'7.2f' + ' ms'
if (FoundStandard == 0)
ResultMessage[1] := ResultMessage[1] + ' (no symbol found)'
Color[1] := 'red'
endif
*增强
ResultMessage[2] := ' enhanced mode:' + TimeEnhanced$'7.2f' + ' ms'
if (FoundEnhanced == 0)
ResultMessage[2] := ResultMessage[2] + ' (no symbol found)'
Color[2] := 'red'
endif
*最大
ResultMessage[3] := ' maximum mode: ' + TimeMaximum$'7.2f' + ' ms'
if (FoundMaximum == 0)
ResultMessage[3] := ResultMessage[3] + ' (no symbol found)'
Color[3] := 'red'
endif
*第5步:显示结果
*显示第几张图片
TitleMessage := SymbolType[Index] + ': Image ' + (I + 1) + ' of ' + |ImageFiles|
*自定义函数用来显示结果
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, ResultMessage, 'forest green', Color)
*取消下列行以不间断地运行程序
if (I < |ImageFiles| - 1 or Index < |SymbolType| - 1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
*清除二维数据代码模型
clear_data_code_2d_model (DataCodeHandleStandard)
clear_data_code_2d_model (DataCodeHandleEnhanced)
clear_data_code_2d_model (DataCodeHandleMaximum)
endfor