此示例演示如何使用条形码参数“barcode_height_min”和“barcode_width_min”用于缩小检测到的候选区域的数量,在这些候选区域中搜索可能的条形码。如果条形码类型、编码字符数等因素在整个应用过程中保持不变,则特别建议使用此选项。然后,手动调整这些参数可以提高速度和鲁棒性。为了说明参数的效果,在设置每个参数之前和之后显示检测到的候选区域。结果表明,当手动调整参数时,潜在候选区域的数量减少。
总代码:
* Initialization
dev_update_off ()
dev_close_window ()
read_image (Image, 'barcode/code39/code3906')
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_draw ('margin')
dev_set_color ('green')
* 定义变量名
MinWidth := 280
MinHeight := 60
*显示描述
* Display a description
Message := 'This example demonstrates how to use the bar code'
Message[1] := 'parameters \'barcode_height_min\' and \'barcode_width_min\''
Message[2] := 'to narrow the number of detected candidate regions in'
Message[3] := 'which the bar codes are searched for.'
*显示信息
*此示例演示如何使用条形码参数
*“barcode_height_min”和“barcode_width_min”用于缩小检测到的候选区域的数量,
*在这些候选区域中搜索可能的条形码。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Create a bar code model
*创建条形码模型
create_bar_code_model ([], [], BarCodeHandle)
dev_display (Image)
* Adjust the minimal widths of the bar code elements
* and find the bar code
*调整条形码元素的最小宽度并找到条形码
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
*
* Get all candidate regions
*获取所有候选区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*
* Display all candidate regions
*显示所有候选区域
dev_set_colored (12)
*显示图片
dev_display (Image)
dev_display (BarCodeObjects)
Message := 'Candidate regions with default settings'
*显示信息--具有默认设置的候选区域
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
Message := 'Adjusting the parameters \'barcode_width_min\' and'
Message[1] := '\'barcode_height_min\' to decrease the number of'
Message[2] := 'found candidate regions and thus to increase the'
Message[3] := 'robustness of the application.'
*显示信息--
*调整参数'barcode_width_min\'和'barcode_height_min\'
*减少找到的候选区域的数量,从而增加应用程序的健壮性
disp_message (WindowHandle, Message, 'window', 40, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Minimal bar code width
* -----------------------------
* Set the minimal bar code width and search for bar codes again
*最小条形码宽度
*设置最小条形码宽度,然后再次搜索条形码
set_bar_code_param (BarCodeHandle, 'barcode_width_min', MinWidth)
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
*
* Get all candidate regions
*获取所有候选区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*
* Display the results
*显示结果
dev_display (Image)
dev_display (BarCodeObjects)
Message := 'Candidate regions with adjusted parameter:'
Message[1] := ' \'barcode_width_min\' = ' + MinWidth
*显示信息
*消息:='参数已调整的候选区域:'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Minimal bar code height
* -------------------------
* Set the minimal bar code height and search for bar codes again
*最小条形码高度
*设置最小条形码高度,然后再次搜索条形码
set_bar_code_param (BarCodeHandle, 'barcode_height_min', MinHeight)
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
*
* Get all candidate regions
*获取所有候选区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*
* Display the results
*显示结果
dev_display (Image)
dev_display (BarCodeObjects)
Message := 'Candidate region with adjusted parameters:'
Message[1] := ' \'barcode_width_min\' = ' + MinWidth
Message[2] := ' \'barcode_height_min\' = ' + MinHeight
**显示信息
*消息:='参数已调整的候选区域:'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Display the symbol region and the decoded string
*显示符号区域和解码字符串
dev_display (Image)
dev_set_color ('red')
dev_display (BarCodeObjects)
dev_set_color ('lime green')
dev_display (SymbolRegions)
*显示信息--使用调整后的参数进行搜索
disp_message (WindowHandle, 'Search with adjusted parameters', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 40, 12, 'black', 'true')
disp_message (WindowHandle, ['Candidate regions','Symbol region'], 'window', 170, 12, ['red','lime green'], 'true')
*
* Clear the bar code model
clear_bar_code_model (BarCodeHandle)
逐段分析:
*初始化
dev_update_off ()
dev_close_window ()
*读取图片
read_image (Image, 'barcode/code39/code3906')
*打开适应窗口的的图片
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_draw ('margin')
dev_set_color ('green')
*显示图片
dev_display (Image)
* 定义变量名
MinWidth := 280
MinHeight := 60
*显示描述
Message := 'This example demonstrates how to use the bar code'
Message[1] := 'parameters \'barcode_height_min\' and \'barcode_width_min\''
Message[2] := 'to narrow the number of detected candidate regions in'
Message[3] := 'which the bar codes are searched for.'
*显示信息
*此示例演示如何使用条形码参数
*“barcode_height_min”和“barcode_width_min”用于缩小检测到的候选区域的数量,
*在这些候选区域中搜索可能的条形码。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*创建条形码模型
create_bar_code_model ([], [], BarCodeHandle)
*调整条形码元素的最小宽度并找到条形码
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
*获取所有候选区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*显示所有候选区域
dev_set_colored (12)
*显示图片
dev_display (Image)
*显示候选区域
dev_display (BarCodeObjects)
*显示信息--具有默认设置的候选区域
Message := 'Candidate regions with default settings'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
Message := 'Adjusting the parameters \'barcode_width_min\' and'
Message[1] := '\'barcode_height_min\' to decrease the number of'
Message[2] := 'found candidate regions and thus to increase the'
Message[3] := 'robustness of the application.'
*显示信息--
*调整参数'barcode_width_min\'和'barcode_height_min\'
*减少找到的候选区域的数量,从而增加应用程序的健壮性
disp_message (WindowHandle, Message, 'window', 40, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*最小条形码宽度,设置最小条形码宽度,然后再次搜索条形码
set_bar_code_param (BarCodeHandle, 'barcode_width_min', MinWidth)
*寻找条形码
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
*获取所有候选区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*显示结果
dev_display (Image)
dev_display (BarCodeObjects)
Message := 'Candidate regions with adjusted parameter:'
Message[1] := ' \'barcode_width_min\' = ' + MinWidth
*显示信息
*消息:='参数已调整的候选区域:'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*最小条形码高度
*设置最小条形码高度,然后再次搜索条形码
set_bar_code_param (BarCodeHandle, 'barcode_height_min', MinHeight)
*寻找条形码
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
*获取所有候选区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*显示结果
dev_display (Image)
dev_display (BarCodeObjects)
Message := 'Candidate region with adjusted parameters:'
Message[1] := ' \'barcode_width_min\' = ' + MinWidth
Message[2] := ' \'barcode_height_min\' = ' + MinHeight
**显示信息
*消息:='参数已调整的候选区域:'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*显示符号区域和解码字符串
dev_display (Image)
dev_set_color ('red')
*显示候选区域
dev_display (BarCodeObjects)
dev_set_color ('lime green')
*显示条形码区域
dev_display (SymbolRegions)
*显示信息--使用调整后的参数进行搜索
disp_message (WindowHandle, 'Search with adjusted parameters', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 40, 12, 'black', 'true')
disp_message (WindowHandle, ['Candidate regions','Symbol region'], 'window', 170, 12, ['red','lime green'], 'true')
*释放条形码阅读器分配的内存
clear_bar_code_model (BarCodeHandle)