本例显示了条形码参数'stop_after_result_num',如果已知预期条形码的数量,则使用该参数可以缩短解码时间。
总代码:
*关闭窗口
dev_close_window ()
dev_open_window (0, 0, 640, 480, 'white', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_update_off ()
*设置边缘描绘
dev_set_draw ('margin')
dev_set_line_width (2)
*
* Display an introduction
*显示介绍
Message := 'This example presents the bar code parameter\n'
Message[1] := '\'stop_after_result_num\'.\n \n'
Message[2] := 'With this parameter the decoding time can be decreased'
Message[3] := 'if the number of expected bar codes is known.\n \n'
Message[4] := 'Please refer to the reference documentation for further \nexplanations.'
*显示信息--本例显示了条形码参数'stop_after_result_num'
*如果已知预期条形码的数量,则使用该参数可以缩短解码时间。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle, 'black', 'false')
stop ()
* 创建条形码模板
create_bar_code_model ([], [], BarCodeHandle)
*
* Case 1 shows the improvement for images containing only bar
* codes of type 'GS1 DataBar Stacked' with many false candidates
*案例1显示对仅包含条形图的图像的改进
*“GS1数据库”类型的代码与许多错误的候选者堆叠在一起
StatusHeight := 180
for I := 1 to 2 by 1
*清除窗口
dev_clear_window ()
*
* read image, initialize window
*读取图像,初始化窗口
read_image (Image, 'barcode/gs1databar_stacked/gs1databar_stacked_0' + I)
get_image_size (Image, Width, Height)
*设置窗口的大小
dev_set_window_extents (-1, -1, Width, Height + StatusHeight)
dev_set_part (0, 0, Height + StatusHeight - 1, Width - 1)
dev_display (Image)
*
* run detection with the default number for decodings
* (which is practically infinite)
*使用解码的默认编号运行检测
*(实际上是无限的)
*将解码所有候选条形码
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)
*
* determine the runtime of find_bar_code
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, 'GS1 DataBar Stacked', DecodedDataStrings, Time1)
*
* run the detection and stop after the first successfully decoded
* bar code
*运行检测并在第一次成功解码条形码后停止
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 1)
*
* determine the runtime of find_bar_code
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, 'GS1 DataBar Stacked', DecodedDataStrings, Time2)
*
* show candidates (red) and decoded symbols (green)
*显示候选符号(红色)和解码符号(绿色)
get_bar_code_object (Candidates, BarCodeHandle, 'all', 'candidate_regions')
dev_set_color ('red')
dev_display (Candidates)
dev_set_color ('green')
*显示解码区域
dev_display (SymbolRegions)
*
*显示的时间
Message := 'Elapsed time \n'
Message[1] := ' all candidates(default) : ' + Time1$'7.2f' + ' ms\n'
Message[2] := ' decode only one symbol : ' + Time2$'7.2f' + ' ms\n'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
*如果是第一张图片
if (I == 1)
Message := 'If the number of expected bar codes is known in\n'
Message[1] := 'advance (here: 1) this can be set as parameter\n'
Message[2] := '\'stop_after_result_num\' in set_bar_code_param\n'
Message[3] := 'or set_bar_code_param_specific.\n\n'
Message[4] := 'Typically, the decoding time decreases in images\n'
Message[5] := 'with many false candidates.'
*显示信息--如果已知预期条形码的数量
*提前(此处:1)这可以设置为参数
*通常,图像中的解码时间会减少有很多虚假候选区域
disp_message (WindowHandle, Message, 'window', Height + 12, 12, 'black', 'false')
endif
disp_continue_message (WindowHandle, 'black', 'false')
stop ()
endfor
*
* Case 2 shows the usage of stop_after_result_num in the
* operator set_bar_code_param_specific for mixed bar code types.
*案例2显示了在
*特定于混合条形码类型的运算符集\条形码\参数。
* For each image the expected bar code types and
* their numbers are given
*对于每张图像,给出了预期的条形码类型及其编号
CodeTypes := ['Code 39','EAN-13']
NumCode39 := [2,1,3,2]
NumEAN13 := [1,1,1,1]
*
* Display an introduction
*显示介绍
dev_set_window_extents (-1, -1, 640, 480)
dev_clear_window ()
Message := 'The number of expected bar codes can be set differently'
Message[1] := 'for each type (here: ' + CodeTypes[0] + ' and ' + CodeTypes[1] + ') with the\n'
Message[2] := 'operator set_bar_code_param_specific.\n \n'
Message[3] := 'Please note that in some cases there is no speed-up'
Message[4] := 'even though stop_after_result_num has been set, e.g.\n'
Message[5] := 'in cases where the number of candidates equals the\n'
Message[6] := 'number of expected bar codes.'
*显示信息
*对于每种类型(此处:“+CodeTypes[0]+”和“+CodeTypes[1]+”)的预期条形码数量可以
*通过特定的运算符set_bar_code_param进行不同的设置。请注意,在某些情况下,
*即使在设置了stop_after_result_num,也不会加快速度,例如,候选数量等于预期条形码数量的情况
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle, 'black', 'false')
stop ()
*
*循环读取图片
for I := 1 to 4 by 1
*清除窗口
dev_clear_window ()
*
* read image, initialize window
*读取图像,初始化窗口
read_image (Image, 'barcode/mixed/barcode_mixed_0' + I)
get_image_size (Image, Width, Height)
*设置窗口大小
dev_set_window_extents (-1, -1, Width / 2, Height / 2)
dev_set_part (0, 0, Height - 1, Width - 1)
dev_display (Image)
*
* run the detection with the default number of decodings (which
* is practically infinite) for all supported bar code types
*使用默认的解码数运行检测(其中
*实际上是无限的)适用于所有受支持的条形码类型
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)
*
* determine the runtime of find_bar_code
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings, Time1)
*
* run the detection and stop after a given number of
* successfully decoded bar codes of the given type
*在给定数量的给定类型条形码成功解码后,运行检测并停止
set_bar_code_param_specific (BarCodeHandle, CodeTypes[0], 'stop_after_result_num', NumCode39[I - 1])
set_bar_code_param_specific (BarCodeHandle, CodeTypes[1], 'stop_after_result_num', NumEAN13[I - 1])
*
* determine the runtime of find_bar_code
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings, Time2)
*
* show candidates (red) and decoded symbols (green)
*显示候选符号(红色)和解码符号(绿色)
get_bar_code_object (Candidates, BarCodeHandle, 'all', 'candidate_regions')
dev_set_color ('red')
dev_display (Candidates)
dev_set_color ('green')
dev_display (SymbolRegions)
*
*显示信息--经过的时间
Message := 'Elapsed time \n'
Message[1] := ' all candidates(default) : ' + Time1$'7.2f' + ' ms\n'
Message[2] := ' decode only given number: ' + Time2$'7.2f' + ' ms\n'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
*
*释放条形码阅读器分配的内存
clear_bar_code_model (BarCodeHandle)
dev_close_window ()
逐段分析:
*关闭窗口
dev_close_window ()
dev_open_window (0, 0, 640, 480, 'white', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_update_off ()
*设置边缘描绘
dev_set_draw ('margin')
dev_set_line_width (2)
*显示介绍
Message := 'This example presents the bar code parameter\n'
Message[1] := '\'stop_after_result_num\'.\n \n'
Message[2] := 'With this parameter the decoding time can be decreased'
Message[3] := 'if the number of expected bar codes is known.\n \n'
Message[4] := 'Please refer to the reference documentation for further \nexplanations.'
*显示信息--本例显示了条形码参数'stop_after_result_num'
*如果已知预期条形码的数量,则使用该参数可以缩短解码时间。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle, 'black', 'false')
stop ()
![](https://i-blog.csdnimg.cn/blog_migrate/bbcfbe6dea132c66292f63e0a8d3e444.png)
* 创建条形码模板
create_bar_code_model ([], [], BarCodeHandle)
*案例1显示对仅包含条形图的图像的改进
*“GS1数据库”类型的代码与许多错误的候选者堆叠在一起
*开始循环读取两张图片
StatusHeight := 180
for I := 1 to 2 by 1
*清除窗口
dev_clear_window ()
*读取图像,初始化窗口
read_image (Image, 'barcode/gs1databar_stacked/gs1databar_stacked_0' + I)
get_image_size (Image, Width, Height)
*设置窗口的大小
dev_set_window_extents (-1, -1, Width, Height + StatusHeight)
dev_set_part (0, 0, Height + StatusHeight - 1, Width - 1)
dev_display (Image)
![](https://i-blog.csdnimg.cn/blog_migrate/b8a69ee491c1d5a8be5b075020f1cc37.png)
*使用解码的默认编号运行检测(实际上是无限的)
*将解码所有候选条形码
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, 'GS1 DataBar Stacked', DecodedDataStrings, Time1)
![](https://i-blog.csdnimg.cn/blog_migrate/38ae50a1050cb2f6761d3bc6b290cc7c.png)
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, 'GS1 DataBar Stacked', DecodedDataStrings, Time1)
*运行检测并在第一次成功解码条形码后停止
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 1)
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, 'GS1 DataBar Stacked', DecodedDataStrings, Time2)
*显示候选符号(红色)和解码符号(绿色)
get_bar_code_object (Candidates, BarCodeHandle, 'all', 'candidate_regions')
dev_set_color ('red')
dev_display (Candidates)
dev_set_color ('green')
*显示解码区域
dev_display (SymbolRegions)
![](https://i-blog.csdnimg.cn/blog_migrate/de982545ec8896c0b541b2f96cfbfe61.png)
*显示的时间
Message := 'Elapsed time \n'
Message[1] := ' all candidates(default) : ' + Time1$'7.2f' + ' ms\n'
Message[2] := ' decode only one symbol : ' + Time2$'7.2f' + ' ms\n'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
![](https://i-blog.csdnimg.cn/blog_migrate/ed2067b34ce48965b09bc2e6254db3d6.png)
*如果是第一张图片
if (I == 1)
Message := 'If the number of expected bar codes is known in\n'
Message[1] := 'advance (here: 1) this can be set as parameter\n'
Message[2] := '\'stop_after_result_num\' in set_bar_code_param\n'
Message[3] := 'or set_bar_code_param_specific.\n\n'
Message[4] := 'Typically, the decoding time decreases in images\n'
Message[5] := 'with many false candidates.'
*显示信息--如果已知预期条形码的数量
*提前(此处:1)这可以设置为参数
*通常,图像中的解码时间会减少有很多虚假候选区域
disp_message (WindowHandle, Message, 'window', Height + 12, 12, 'black', 'false')
endif
disp_continue_message (WindowHandle, 'black', 'false')
stop ()
endfor
![](https://i-blog.csdnimg.cn/blog_migrate/2748dd00d94f75e35347154baf42ae85.png)
![](https://i-blog.csdnimg.cn/blog_migrate/32f7c39e1087e18e583470f7a5fcad0c.png)
*对于每张图像,给出了预期的条形码类型及其编号
CodeTypes := ['Code 39','EAN-13']
NumCode39 := [2,1,3,2]
NumEAN13 := [1,1,1,1]
*显示介绍
dev_set_window_extents (-1, -1, 640, 480)
dev_clear_window ()
Message := 'The number of expected bar codes can be set differently'
Message[1] := 'for each type (here: ' + CodeTypes[0] + ' and ' + CodeTypes[1] + ') with the\n'
Message[2] := 'operator set_bar_code_param_specific.\n \n'
Message[3] := 'Please note that in some cases there is no speed-up'
Message[4] := 'even though stop_after_result_num has been set, e.g.\n'
Message[5] := 'in cases where the number of candidates equals the\n'
Message[6] := 'number of expected bar codes.'
*显示信息
*对于每种类型(此处:“+CodeTypes[0]+”和“+CodeTypes[1]+”)的预期条形码数量可以
*通过特定的运算符set_bar_code_param进行不同的设置。请注意,在某些情况下,
*即使在设置了stop_after_result_num,也不会加快速度,例如,候选数量等于预期条形码数量的情况
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle, 'black', 'false')
stop ()
![](https://i-blog.csdnimg.cn/blog_migrate/83488b541e24af7feedfcaec4bf0033c.png)
*循环读取图片
for I := 1 to 4 by 1
*清除窗口
dev_clear_window ()
*读取图像,初始化窗口
read_image (Image, 'barcode/mixed/barcode_mixed_0' + I)
get_image_size (Image, Width, Height)
*设置窗口大小
dev_set_window_extents (-1, -1, Width / 2, Height / 2)
dev_set_part (0, 0, Height - 1, Width - 1)
dev_display (Image)
![](https://i-blog.csdnimg.cn/blog_migrate/65f363155f1062ebef1cad7818c8db1b.png)
*使用默认的解码数运行检测(其中
*实际上是无限的)适用于所有受支持的条形码类型
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings, Time1)
![](https://i-blog.csdnimg.cn/blog_migrate/7c1c0aebcbca42c5f855a777d83c1720.png)
*在给定数量的给定类型条形码成功解码后,运行检测并停止
set_bar_code_param_specific (BarCodeHandle, CodeTypes[0], 'stop_after_result_num', NumCode39[I - 1])
set_bar_code_param_specific (BarCodeHandle, CodeTypes[1], 'stop_after_result_num', NumEAN13[I - 1])
*确定查找条形码的运行时间
find_bar_code_timing (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings, Time2)
*显示候选符号(红色)和解码符号(绿色)
get_bar_code_object (Candidates, BarCodeHandle, 'all', 'candidate_regions')
dev_set_color ('red')
dev_display (Candidates)
dev_set_color ('green')
dev_display (SymbolRegions)
![](https://i-blog.csdnimg.cn/blog_migrate/900137fb2d50bfeae6cad83f1d7fd5ea.png)
*显示信息--经过的时间
Message := 'Elapsed time \n'
Message[1] := ' all candidates(default) : ' + Time1$'7.2f' + ' ms\n'
Message[2] := ' decode only given number: ' + Time2$'7.2f' + ' ms\n'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
![](https://i-blog.csdnimg.cn/blog_migrate/bd4951cc56fc55415d21ebf6e46f9c5f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6c2fb74aa56b609bc603e51dd0487fe5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0216baa42e7bda275b637616fdcdd9cc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3f0a08d74e3650b52d2cdb59829b8799.png)
*释放条形码阅读器分配的内存
clear_bar_code_model (BarCodeHandle)
dev_close_window ()