首页 各类条码类型读取的代码

各类条码类型读取的代码

举报
开通vip

各类条码类型读取的代码各类条码类型读取的代码 EAN-13、EAN-13 Add-On 5、EAN-8、Code39、Code128、 MSI、RSS-14、RSS-14 Stacked、RSS-14 Stacked Omnidirectional、RSS Composite、RSS Expanded、RSS Expanded Stacked、RSS Limited等类型的一维条形码读取的 代码实例 ==================================================================...

各类条码类型读取的代码
各类条码类型读取的代码 EAN-13、EAN-13 Add-On 5、EAN-8、Code39、Code128、 MSI、RSS-14、RSS-14 Stacked、RSS-14 Stacked Omnidirectional、RSS Composite、RSS Expanded、RSS Expanded Stacked、RSS Limited等类型的一维条形码读取的 代码实例 ================================================================================= * Read bar codes of type EAN-13 * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () dev_open_window (0, 0, 120, 300, 'black', WindowHandle) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_set_color ('green') dev_set_draw ('margin') dev_set_line_width (3) set_bar_code_param (BarCodeHandle, 'element_size_min', 1.5) set_bar_code_param (BarCodeHandle, 'element_size_max', 16) for I := 1 to 15 by 1 read_image (Image, 'barcode/ean13/ean13'+(I$'.2')) dev_resize_window_fit_image (Image, 0, 0, -1, -1) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'EAN-13', DecodedDataStrings) area_center (SymbolRegions, Area, Row, Column) dev_display (Image) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'image', Row-30, Column-90, 'black', 'true') disp_continue_message (WindowHandle, 'black', 'true') stop () endfor clear_bar_code_model (BarCodeHandle) ================================================================================= * Read bar code of type EAN-13 Add-On 5 * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () dev_open_window (0, 0, 120, 300, 'black', WindowHandle) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_set_color ('green') dev_set_draw ('margin') dev_set_line_width (3) set_bar_code_param (BarCodeHandle, 'element_size_min', 1.5) set_bar_code_param (BarCodeHandle, 'element_size_max', 16) read_image (Image, 'barcode/ean13addon5/ean13addon501') dev_resize_window_fit_image (Image, 0, 0, -1, -1) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'EAN-13 Add-On 5', DecodedDataStrings) area_center (SymbolRegions, Area, Row, Column) dev_display (Image) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'image', Row-30, Column-90, 'black', 'true') clear_bar_code_model (BarCodeHandle) ================================================================================= * Read bar codes of type EAN-8 * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () read_image (Image, 'barcode/ean8/ean801') dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_set_color ('green') dev_set_draw ('margin') dev_set_line_width (3) dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'EAN-8', DecodedDataStrings) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true') clear_bar_code_model (BarCodeHandle) ================================================================================= * Read bar codes of type Code 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 5 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 < 5) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor clear_bar_code_model (BarCodeHandle) ================================================================================= * Read bar codes of type Code 128 * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () dev_open_window (0, 0, 600, 600, 'black', WindowHandle) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) for I := 1 to 3 by 1 read_image (Image, 'barcode/code128/code128'+(I$'.2')) dev_resize_window_fit_image (Image, 0, 0, -1, -1) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 128', DecodedDataStrings) get_bar_code_result (BarCodeHandle, 0, 'decoded_reference', Reference) String := '' for J := 0 to strlen(DecodedDataStrings)-1 by 1 if (ord(DecodedDataStrings{J}) < 32) Char := '\\x'+ord(DecodedDataStrings{J})$'02x' else Char := DecodedDataStrings{J} endif String := String+Char endfor disp_message (WindowHandle, String, 'window', 12, 12, 'black', 'true') if (I < 3) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * clear_bar_code_model (BarCodeHandle) ================================================================================= * Read bar codes of type Codabar * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () dev_open_window (0, 0, 120, 300, 'black', WindowHandle) dev_set_color ('green') dev_set_draw ('margin') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') for I := 1 to 6 by 1 read_image (Image, 'barcode/codabar/codabar'+(I$'.2')) get_image_size (Image, Width, Height) dev_set_window_extents (0, 0, Width-1, Height-1) dev_display (Image) set_bar_code_param (BarCodeHandle, 'check_char', 'present') find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Codabar', DecodedDataStrings) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'false') LastChar := strlen(DecodedDataStrings)-1 disp_message (WindowHandle, DecodedDataStrings{0}+sum(gen_tuple_const(LastChar-1,' '))+DecodedDataStrings{LastChar}, 'window', 12, 12, 'forest green', 'false') if (I < 6) stop () endif endfor clear_bar_code_model (BarCodeHandle) ================================================================================= * Example program for decoding bar codes of type MSI * * Create Barcode reader with check character validation create_bar_code_model ('check_char', 'present', BarCodeHandle) * * Initialization dev_close_window () dev_open_window (0, 0, 320, 240, 'black', WindowHandle) dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * * Read bar codes for I := 1 to 3 by 1 read_image (Image, 'barcode/msi/msi_' + I$'.2d') dev_resize_window_fit_image (Image, 0, 0, -1, -1) dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'MSI', DecodedDataStrings) area_center (SymbolRegions, Area, Row, Column) dev_display (SymbolRegions) for IdxFound := 0 to |DecodedDataStrings|-1 by 1 disp_message (WindowHandle, DecodedDataStrings[IdxFound], 'image', Row[IdxFound]-20, Column[IdxFound]-50, 'black', 'true') endfor if (I < 3) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) ================================================================================= * RSS-14 bar code symbology * * Create Barcode reader create_bar_code_model ('element_size_min', 1.5, BarCodeHandle) * * Initialization dev_close_window () dev_open_window (0, 0, 360, 256, 'black', WindowHandle) dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * * Read bar codes for I := 1 to 2 by 1 read_image (Image, 'barcode/rss14/rss14_' + I$'.2d') dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'RSS-14', DecodedDataStrings) get_region_runs (SymbolRegions, Row, ColumnBegin, ColumnEnd) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true') if (I < 2) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) ================================================================================= * RSS-14 Stacked bar code symbology * * Create Barcode reader create_bar_code_model ([], [], BarCodeHandle) * * Initialization dev_close_window () dev_open_window (0, 0, -1, -1, 'black', WindowHandle) dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * * Read bar codes for Ind := 1 to 2 by 1 ImageName := 'barcode/rss14_stacked/rss14_stacked_'+(Ind$'.2') read_image (Image, ImageName) get_image_size (Image, Width, Height) dev_set_window_extents (-1, -1, Width, Height) dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'RSS-14 Stacked', DecodedDataStrings) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'image', 5, 5, 'black', 'true') if (Ind < 2) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) ================================================================================= * RSS-14 Stacked Omnidirectional bar code symbology * * Create Barcode reader create_bar_code_model ([], [], BarCodeHandle) * * Initialization dev_close_window () dev_open_window (0, 0, -1, -1, 'black', WindowHandle) dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * * Read bar codes for I := 1 to 2 by 1 ImageName := 'barcode/rss14_stacked_omnidir/rss14_stacked_omnidir_'+(I$'.2') read_image (Image, ImageName) get_image_size (Image, Width, Height) dev_set_window_extents (-1, -1, Width/2, Height/2) dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'RSS-14 Stacked Omnidir', DecodedDataStrings) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'image', 5, 5, 'black', 'true') if (I < 2) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) ================================================================================= * This program demonstrates the decoding of RSS bar codes with Composite component * dev_close_window () dev_open_window (0, 0, 512, 512, 'black', WindowHandle) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * ScaleWindow := 1.0 * dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) * create_bar_code_model ([], [], BarCodeHandle) set_bar_code_param (BarCodeHandle, 'composite_code', 'CC-A/B') set_bar_code_param (BarCodeHandle, 'element_size_min', 1.5) * TestParams := [] TestParams := [TestParams, 'rss14_stacked_composite_01', 'RSS-14 Stacked'] TestParams := [TestParams, 'rsslimited_composite_01', 'RSS Limited' ] TestParams := [TestParams, 'rsslimited_composite_02', 'RSS Limited' ] TestParams := [TestParams, 'rssexpanded_composite_01', 'RSS Expanded' ] * for I := 0 to |TestParams|-2 by 2 File := 'barcode/rss_composite/'+TestParams[I] CodeType := TestParams[I+1] * read_image (Image, File) * compensate for over exposed images: expand dark areas gray_erosion_shape (Image, Image, 1.5, 1.5, 'octagon') get_image_size (Image, Width, Height) dev_set_window_extents (0, 0, ScaleWindow*Width, ScaleWindow*Height) disp_message (WindowHandle, 'Barcode Type: ' + CodeType, 'image', 12, 12, 'black', 'true') * find_bar_code (Image, SymbolRegions, BarCodeHandle, CodeType, DecodedDataStrings) * get_bar_code_result (BarCodeHandle, 'all', 'decoded_strings', DecodedStrings) get_bar_code_result (BarCodeHandle, 'all', 'composite_strings', CompositeStrings) disp_message (WindowHandle, DecodedStrings + '\nComposite: ' + CompositeStrings, 'image', 36, 12, 'black', 'true') if (I < |TestParams|-2) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * clear_bar_code_model (BarCodeHandle) ================================================================================= * RSS Expanded bar code symbology * * Create Barcode reader create_bar_code_model ('element_size_min', 1.5, BarCodeHandle) * * Initialization NumImages := 2 dev_close_window () read_image (Image, 'barcode/rssexpanded/rssexpanded_01') dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * * Read bar codes for I := 1 to NumImages by 1 read_image (Image, 'barcode/rssexpanded/rssexpanded_' + I$'.2d') dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'RSS Expanded', DecodedDataStrings) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true') if (I < NumImages) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) ================================================================================= * RSS Expanded Stacked bar code symbology * * Create Barcode reader create_bar_code_model (['element_size_max','element_size_min','max_diff_orient'], [16,1.5,1.0], BarCodeHandle) * * Initialization dev_close_window () dev_open_window (0, 0, -1, -1, 'black', WindowHandle) dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') * * Read bar codes for Ind := 1 to 2 by 1 ImageName := 'barcode/rssexpanded_stacked/rssexpanded_stacked_'+(Ind$'.2') read_image (Image, ImageName) dev_resize_window_fit_image (Image, 0, 0, -1, -1) dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'RSS Expanded Stacked', DecodedDataStrings) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true') if (Ind < 2) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) ================================================================================= * RSS Limited bar code symbology * * Create Barcode reader create_bar_code_model ('element_size_min', 1.5, BarCodeHandle) * * Initialization NumImages := 2 dev_close_window () dev_open_window (0, 0, 360, 256, 'black', WindowHandle) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_color ('green') dev_set_line_width (3) * * Read bar codes for I := 1 to NumImages by 1 read_image (Image, 'barcode/rsslimited/rsslimited_' + I$'.2d') dev_display (Image) find_bar_code (Image, SymbolRegions, BarCodeHandle, 'RSS Limited', DecodedDataStrings) dev_display (SymbolRegions) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true') if (I < NumImages) disp_continue_message (WindowHandle, 'black', 'true') stop () endif endfor * * Close Barcode reader clear_bar_code_model (BarCodeHandle) Following bar code symbologies are supported: 2/5 Industrial EAN-8 RSS-14 2/5 Interleaved EAN-8 Add-On 2 RSS-14 Truncated Codabar EAN-8 Add-On 5 RSS-14 Stacked Code 39 EAN-13 RSS-14 Stacked Omnidirectional Code 93 EAN-13 Add-On 2 RSS Limited Code 128 EAN-13 Add-On 5 RSS Expanded MSI UPC-A RSS Expanded Stacked PharmaCode UPC-A Add-On 2 UPC-A Add-On 5 UPC-E UPC-E Add-On 2 UPC-E Add-On 5 Autodiscrimination describes the simultaneous decoding of multiple bar code types in one call of find_bar_code. For this purpose a tuple of bar code types is specified for the parameter CodeType. Using the generic value 'auto' all known bar code types are decoded - except 'PharmaCode' and 'MSI' because these codes don't have enough features to be reliably separated from other bar code types. The tuple can also contain bar code types with the tilde prefix (~) which won't be decoded. For example ['auto', '~EAN-8', '~EAN-8 Add-On 2', '~EAN-8 Add-On 5'] describes all bar code types without 'PharmaCode', 'MSI' and all kinds of 'EAN-8'. Please note that each additionally allowed bar code type increases the run-time of the operator. Using too many bar code types the reliability of the decoding could decrease because not all bar code types can be discriminated reliably. To improve autodiscrimination compatibility bar codes with a check character or check sum should be used. The bar code reader tries to decode the bar code types in the following order: RSS-14, RSS-14 Truncated, RSS-14 Stacked,RSS-14 Stacked Omnidirectional, RSS Limited, RSS Expanded, RSS Expanded Stacked, Code 128, EAN-13 Add-On 5, EAN-13 Add-On 2, EAN-13, UPC-A Add-On 5, UPC-A Add-On 2, UPC-A, EAN-8 Add-On 5, EAN-8 Add-On 2, EAN-8, UPC-E Add-On 5, UPC-E Add-On 2, UPC-E, Code 93, Code 39, Codabar, 2/5 Interleaved, 2/5 Industrial, MSI, PharmaCode. Therefore you should exclude at least all definitely not occuring bar code types that are scanned before the first of the bar code types you expect to find or, better, just scan for the explicit list of bar code types you expect. CodeType (input_control) string(-array) ? (string) Type of the searched bar code. Default value: 'EAN-13' List of values: '2/5 Industrial', '2/5 Interleaved', 'Codabar', 'Code 39', 'Code 93', 'Code 128', 'EAN-13', 'EAN-13 Add-On 2', 'EAN-13 Add-On 5', 'EAN-8', 'EAN-8 Add-On 2', 'EAN-8 Add-On 5', 'UPC-A', 'UPC-A Add-On 2', 'UPC-A Add-On 5', 'UPC-E', 'UPC-E Add-On 2', 'UPC-E Add-On 5', 'MSI', 'PharmaCode', 'RSS-14', 'RSS-14 Truncated', 'RSS-14 Stacked', 'RSS-14 Stacked Omnidir', 'RSS Limited', 'RSS Expanded', 'RSS Expanded Stacked', 'auto' ================================================================================= * Read bar codes of type 2/5 Industrial * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () dev_open_window (0, 0, 120, 300, 'black', WindowHandle) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (3) for I := 1 to 4 by 1 read_image (Image, 'barcode/25industrial/25industrial0'+I) get_image_size (Image, Width, Height) dev_set_window_extents (0, 0, Width-1, Height-1) dev_display (Image) dev_set_color ('green') * Read bar code, the resulting string includes the check character set_bar_code_param (BarCodeHandle, 'check_char', 'absent') find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Industrial', DecodedDataStrings) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'false') LastChar := strlen(DecodedDataStrings)-1 disp_message (WindowHandle, sum(gen_tuple_const(LastChar,' '))+DecodedDataStrings{LastChar}, 'window', 12, 12, 'forest green', 'false') stop () * Read bar code using the check character to check the result, i.e., * the check character does not belong to the returned string anymore. * If the check character is not correct, the bar code reading fails dev_set_color ('green') set_bar_code_param (BarCodeHandle, 'check_char', 'present') find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Industrial', DecodedDataStrings) disp_message (WindowHandle, DecodedDataStrings, 'window', 36, 12, 'black', 'false') dev_set_color ('magenta') if (I < 4) stop () endif endfor clear_bar_code_model (BarCodeHandle) ================================================================================= * Read bar codes of type 2/5 Interleaved * create_bar_code_model ([], [], BarCodeHandle) dev_close_window () dev_open_window (0, 0, 120, 300, 'black', WindowHandle) set_display_font (WindowHandle, 14, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (3) for I := 1 to 8 by 1 read_image (Image, 'barcode/25interleaved/25interleaved'+(I$'.2')) get_image_size (Image, Width, Height) dev_set_window_extents (0, 0, Width-1, Height-1) dev_display (Image) dev_set_color ('green') * Read bar code, the resulting string includes the check character set_bar_code_param (BarCodeHandle, 'check_char', 'absent') find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Interleaved', DecodedDataStrings) disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'false') LastChar := strlen(DecodedDataStrings)-1 disp_message (WindowHandle, sum(gen_tuple_const(LastChar,' '))+DecodedDataStrings{LastChar}, 'window', 12, 12, 'forest green', 'false') stop () * Read bar code using the check character to check the result, i.e., * the check character does not belong to the returned string anymore. * If the check character is not correct, the bar code reading fails dev_set_color ('green') set_bar_code_param (BarCodeHandle, 'check_char', 'present') find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Interleaved', DecodedDataStrings) disp_message (WindowHandle, DecodedDataStrings, 'window', 36, 12, 'black', 'false') if (I<8) stop () endif endfor clear_bar_code_model (BarCodeHandle) =================================================================================
本文档为【各类条码类型读取的代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_281650
暂无简介~
格式:doc
大小:85KB
软件:Word
页数:0
分类:互联网
上传时间:2017-09-28
浏览量:26