这个示例程序展示了如何在严重干扰查找器模式的情况下读取ECC200符号。
在本例中,finder图案的一面或多面变形。因此,使用包含具有类似干扰的ECC200符号的一些示例图像来训练数据代码模型。然后用于查找数据代码。请注意,您也可以使用运算符将参数“finder_pattern_tolerance”设置为“high”
总代码:
*初始化图像路径和视觉设置
*更新状态设为off
dev_update_off ()
*关闭窗口
dev_close_window ()
*定义图片的路径
ImageFiles := 'datacode/ecc200/ecc200_damaged_finder_pattern_'
ImageFilesTrain := 'datacode/ecc200/ecc200_damaged_finder_pattern_training_'
ImageNum := 19
ImageTrainNum := 5
*读取图片
read_image (Image, ImageFiles + '01')
*打开自适应图片的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
*
* Display short description
*显示简短描述
Message := 'This program demonstrates how to find and decode'
Message[1] := 'ECC200 symbols that have a heavily disturbed finder pattern.'
Message[2] := 'To read these symbols successfully, some example images'
Message[3] := 'that contain ECC200 symbols with similar disturbances'
Message[4] := 'are used to train the data code reader.'
*显示信息-这个程序演示了如何查找和解码具有严重干扰的查找模式的ECC200符号。
*为了成功读取这些符号,使用一些包含具有类似干扰的ECC200符号的示例图像来训练数据代码读取器。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Step 1: Create a 2d data code model
* ----------------------------------------------------
* Create a 2d data code model of the 2d data code class
* 'Data Matrix ECC 200'.
*步骤1:创建二维数据代码模型
*创建2d数据代码类“data Matrix ECC 200”的2d数据代码模型。
create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle)
*
* Step 2: Train the model
* -------------------------------------------------------
* Train the model on some images containing ECC 200 symbols
* with disturbed finder pattern
*第二步:训练模型
*在一些包含ECC 200符号的图像上对模型进行训练,这些图像带有受干扰的查找模式
for Index := 1 to ImageTrainNum by 1
*读取图片
read_image (Image, ImageFilesTrain + Index$'.2d')
*
* Find and decode the data codes
*找到并解码数据代码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, 'train', 'all', ResultHandles, DecodedDataStrings)
*
* Display results
*显示结果
dev_display (Image)
dev_display (SymbolXLDs)
TitleMessage := 'Train on image ' + Index + ' of ' + ImageTrainNum
*显示结果
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, [], 'forest green', 'black')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
*
* Display message about the next step
*显示关于下一步的消息
*清除窗口
dev_clear_window ()
Message := 'The trained data code model is now used to find the data codes'
Message[1] := 'in a sequence of images with similar disturbances.'
*显示信息--经过训练的数据编码模型现在被用于在具有类似干扰的图像序列中寻找数据编码
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Step 3: Read the data codes
* -------------------------------------------------------
* Search and read the data codes with the trained model
* in each image and display the decoded string for each
* found data code
*3.读取数据代码
*用经过训练的模型搜索并读取数据代码在每个图像中,
*显示每个图像的解码字符串找到数据代码
for Index := 1 to ImageNum by 1
*读取图片
read_image (Image, ImageFiles + Index$'.2d')
*显示图片
dev_display (Image)
*
* Find and decode the data codes and measure the runtime
*找到并解码数据代码,测量运行时间
*计算开始时间
count_seconds (T1)
*寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
count_seconds (T2)
Time := (T2 - T1) * 1000.0
*
* Display the results
*显示结果
TitleMessage := 'Image ' + Index + ' of ' + ImageNum
ResultMessage := 'Data code found in ' + Time$'.1f' + ' ms'
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, ResultMessage, 'forest green', 'black')
*
* If no data codes are found
*如果没有找到数据代码
if (|ResultHandles| == 0)
disp_message (WindowHandle, 'No Symbol found (in ' + Time$'.1f' + ' ms )', 'window', 12, 12, 'black', 'true')
endif
*
* Deactivate the following lines to run the program without breaks
*停用以下几行以不间断地运行程序
if (Index < ImageNum)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
*
* Clear the data code model
*清除数据代码模型
clear_data_code_2d_model (DataCodeHandle)
逐段分析:
*初始化图像路径和视觉设置
*更新状态设为off
dev_update_off ()
*关闭窗口
dev_close_window ()
*定义图片的路径
ImageFiles := 'datacode/ecc200/ecc200_damaged_finder_pattern_'
ImageFilesTrain := 'datacode/ecc200/ecc200_damaged_finder_pattern_training_'
ImageNum := 19
ImageTrainNum := 5
*读取图片
read_image (Image, ImageFiles + '01')
*打开自适应图片的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
*显示简短描述
Message := 'This program demonstrates how to find and decode'
Message[1] := 'ECC200 symbols that have a heavily disturbed finder pattern.'
Message[2] := 'To read these symbols successfully, some example images'
Message[3] := 'that contain ECC200 symbols with similar disturbances'
Message[4] := 'are used to train the data code reader.'
*显示信息-这个程序演示了如何查找和解码具有严重干扰的查找模式的ECC200符号。
*为了成功读取这些符号,使用一些包含具有类似干扰的ECC200符号的示例图像来训练数据代码读器
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*步骤1:创建二维数据代码模型
*创建2d数据代码类“data Matrix ECC 200”的2d数据代码模型。
create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle)
*第二步:训练模型
*在一些包含ECC 200符号的图像上对模型进行训练,这些图像带有受干扰的查找模式
for Index := 1 to ImageTrainNum by 1
*读取图片
read_image (Image, ImageFilesTrain + Index$'.2d')
*找到并解码数据代码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, 'train', 'all', ResultHandles, DecodedDataStrings)
*显示结果
dev_display (Image)
dev_display (SymbolXLDs)
TitleMessage := 'Train on image ' + Index + ' of ' + ImageTrainNum
*显示结果
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, [], 'forest green', 'black')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
*显示关于下一步的消息
*清除窗口
dev_clear_window ()
Message := 'The trained data code model is now used to find the data codes'
Message[1] := 'in a sequence of images with similar disturbances.'
*显示信息--经过训练的数据编码模型现在被用于在具有类似干扰的图像序列中寻找数据编码
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*3.读取数据代码
*用经过训练的模型搜索并读取数据代码在每个图像中,
*显示每个图像的解码字符串找到数据代码
for Index := 1 to ImageNum by 1
*读取图片
read_image (Image, ImageFiles + Index$'.2d')
*显示图片
dev_display (Image)
*找到并解码数据代码,测量运行时间
*计算开始时间
count_seconds (T1)
*寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
count_seconds (T2)
Time := (T2 - T1) * 1000.0
*显示结果
TitleMessage := 'Image ' + Index + ' of ' + ImageNum
ResultMessage := 'Data code found in ' + Time$'.1f' + ' ms'
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, ResultMessage, 'forest green', 'black')
*清除数据代码模型
clear_data_code_2d_model (DataCodeHandle)