读取类型代码39的条形码
总代码:
create_bar_code_model ([], [], BarCodeHandle)
dev_close_window ()
dev_open_window (0, 0, 120, 300, 'black', WindowHandle)
dev_set_draw ('margin')
dev_set_line_width (3)
Colors := ['forest green','magenta']
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
for I := 1 to 6 by 1
read_image (Image, 'barcode/code39/code39' + (I$'.2'))
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
set_bar_code_param (BarCodeHandle, 'element_size_max', 6)
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
dev_display (Image)
dev_display (SymbolRegions)
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'symbol_regions')
get_bar_code_result (BarCodeHandle, 'all', 'decoded_strings', BarCodeResults)
for J := 0 to |DecodedDataStrings| - 1 by 1
dev_set_color (Colors[J])
select_obj (BarCodeObjects, ObjectSelected, J + 1)
dev_display (ObjectSelected)
endfor
disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, Colors, 'true')
if (I < 6)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
clear_bar_code_model (BarCodeHandle)
逐段分析:
*创建模板
create_bar_code_model ([], [], BarCodeHandle)
dev_close_window ()
dev_open_window (0, 0, 120, 300, 'black', WindowHandle)
*边缘描绘
dev_set_draw ('margin')
dev_set_line_width (3)
*定义两个颜色
Colors := ['forest green','magenta']
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*循环读取六张图片
for I := 1 to 6 by 1
*读取图片
read_image (Image, 'barcode/code39/code39' + (I$'.2'))
*设置窗口和图像适应大小
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
*设置参数
set_bar_code_param (BarCodeHandle, 'element_size_max', 6)
*找到条形码
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
dev_display (Image)
dev_display (SymbolRegions)
![](https://img-blog.csdnimg.cn/fa36277c1f9043e0a03bb3b31ac79862.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
*得到识别过程中的区域
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'symbol_regions')
*得到结果
get_bar_code_result (BarCodeHandle, 'all', 'decoded_strings', BarCodeResults)
*依次循环颜色和区域
for J := 0 to |DecodedDataStrings| - 1 by 1
dev_set_color (Colors[J])
select_obj (BarCodeObjects, ObjectSelected, J + 1)
dev_display (ObjectSelected)
endfor
*显示结果
disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, Colors, 'true')
if (I < 6)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
clear_bar_code_model (BarCodeHandle)
![](https://img-blog.csdnimg.cn/165cc88c1de44cc0900a7de1bd6e3bdc.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
'element_size_max'
基本条形码元素的最大尺寸(也称为“模块”或“窄条”,取决于特定条形码类型),即最窄条的最大宽度和特定条形码类型的空间。“element_size_max”的值以像素为单位定义。它应该足够低,这样两个相邻的条形码就不会融合成一个。另一方面,该值应足够高,以便找到完整的条形码区域。
典型值:[4.0…60.0]
值范围:[1…256]
默认值:8.0