开启左侧

求条码识别的理论资料

[复制链接]
icework 发表于 2017-1-15 22:54:51 | 显示全部楼层 |阅读模式
小弟想研究一下条码(包括二维码和一维码)的原理,比如,如何进行条码的目标检测,图像分割,最后如何识别的
不知道哪位大神能介绍一点资料或者源码?
小弟不胜感激

绝地武士 发表于 2017-1-17 09:51:00 | 显示全部楼层
这个是HALCON10.0的代码,你可以参考下:
  1. * Example program for the usage of the bar code
  2. * reader autodiscrimination feature of HALCON.
  3. *
  4. * Create bar code reader model
  5. create_bar_code_model ([], [], BarCodeHandle)
  6. *
  7. * Initialization
  8. dev_update_var ('off')
  9. dev_update_pc ('off')
  10. dev_update_window ('off')
  11. dev_close_window ()
  12. dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
  13. set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
  14. dev_set_draw ('margin')
  15. dev_set_line_width (3)
  16. dev_set_color ('forest green')
  17. *
  18. * Define the example images to use
  19. ExampleImagesAny := ['barcode/ean13/ean1301', 'barcode/code39/code3901', 'barcode/rss14/rss14_01']
  20. ExampleImagesAmbiguous := ['barcode/mixed/barcode_mixed_01']
  21. ExampleImagesMixed := ['barcode/mixed/barcode_mixed_04', 'barcode/mixed/barcode_mixed_03',   'barcode/mixed/barcode_mixed_01']
  22. *
  23. * Use autodiscrimination to decode any of the bar code types
  24. * supported by HALCON (except PharmaCode) or determine the bar
  25. * code type of unknown bar codes
  26. for IdxExample := 0 to 1 by 1
  27.     dev_clear_window ()
  28.     if (IdxExample = 0)
  29.         CodeTypes := 'auto'
  30.         Message := 'Usage of autodiscrimination to decode'
  31.         Message[1] := 'unknown bar code types.'
  32.         Message[2] := 'In the first run we use CodeType=\''+CodeTypes+'\' to look'
  33.         Message[3] := 'for all bar code types known to HALCON'
  34.         disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  35.         disp_continue_message (WindowHandle, 'black', 'true')
  36.         stop ()
  37.     else
  38.         CodeTypes := ['EAN-13','Code 39','RSS-14']
  39.         Message := 'In the second run we look for the expected types only:'
  40.         Message[1] := sum('  ' + CodeTypes)
  41.         Message[2] := 'This reduces the decoding time and'
  42.         Message[3] := 'increases the decoding reliability.'
  43.         disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  44.         disp_continue_message (WindowHandle, 'black', 'true')
  45.         stop ()
  46.     endif
  47.     for IdxIma := 0 to |ExampleImagesAny|-1 by 1
  48.         FileName := ExampleImagesAny[IdxIma]
  49.         read_image (Image, FileName)
  50.         *
  51.         * Set display defaults
  52.         get_image_size (Image, Width, Height)
  53.         dev_set_window_extents (-1, -1, Width, Height)
  54.         dev_display (Image)
  55.         disp_message (WindowHandle, ['Looking for bar code(s) of type:', sum(' ' + CodeTypes)], 'window', 12, 12, 'black', 'true')
  56.         *
  57.         * Find and decode bar codes. Measure the time needed.
  58.         count_seconds (Start)
  59.         find_bar_code (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings)
  60.         count_seconds (Stop)
  61.         Duration := (Stop - Start) * 1000
  62.         *
  63.         * Display results and the time needed
  64.         dev_display (SymbolRegions)
  65.         get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', DecodedDataTypes)
  66.         disp_message (WindowHandle, ['Found bar code(s) in ' + Duration

  67. 3.0f' + 'ms:',' Type: ' + DecodedDataTypes + '\n Data: ' + DecodedDataStrings], 'window', 5*12, 12, 'forest green', 'true')
  68.         disp_continue_message (WindowHandle, 'black', 'true')
  69.         stop ()
  70.     endfor
  71. endfor
  72. *
  73. *
  74. * Autodiscrimination can be used to decode multiple bar code
  75. * types within one image at once.
  76. *
  77. * First we demonstrate that the bar code types list
  78. * should be confined whenever possible.
  79. *
  80. * Display information for the user:
  81. Message := 'If you have a list of bar code types that'
  82. Message[1] := 'you want to decode, you should supply only those'
  83. Message[2] := 'types to the bar code reader. In the following,'
  84. Message[3] := 'it is demonstrated that otherwise a wrong bar code'
  85. Message[4] := 'could be decoded (here: UPC-E Add-On 2)'
  86. dev_clear_window ()
  87. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  88. disp_continue_message (WindowHandle, 'black', 'true')
  89. stop ()
  90. *
  91. * For demonstration purposes we scan here, among others,
  92. * for UPC codes, too.
  93. CodeTypes := ['auto']
  94. *
  95. * Demonstrate autodiscrimination for mixed bar code types
  96. for IdxIma := 0 to |ExampleImagesAmbiguous|-1 by 1
  97.     FileName := ExampleImagesAmbiguous[IdxIma]
  98.     read_image (Image, FileName)
  99.     *
  100.     * Display image and description
  101.     get_image_size (Image, Width, Height)
  102.     dev_set_window_extents (-1, -1, Width/2, Height/2)
  103.     dev_display (Image)
  104.     disp_message (WindowHandle, ['Looking for bar code(s) of type:', sum(' ' + CodeTypes)], 'window', 12, 12, 'black', 'true')
  105.     *
  106.     * Decode mixed bar codes
  107.     find_bar_code (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings)
  108.     *
  109.     * Display decoded data and symbol region
  110.     get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', DecodedDataTypes)
  111.     area_center (SymbolRegions, Area, Rows, Columns)
  112.     for IdxResult := 0 to |DecodedDataStrings|-1 by 1
  113.         if (regexp_test (DecodedDataTypes[IdxResult], 'UPC.*') # 0)
  114.             Color := 'red'
  115.         else
  116.             Color := 'forest green'
  117.         endif
  118.         dev_set_color (Color)
  119.         select_obj (SymbolRegions, SelectedRegion, IdxResult+1)
  120.         dev_display (SelectedRegion)
  121.         disp_message (WindowHandle, DecodedDataTypes[IdxResult]+': '+DecodedDataStrings[IdxResult], 'image', Rows[IdxResult], Columns[IdxResult]-160, Color, 'true')
  122.     endfor
  123.     disp_continue_message (WindowHandle, 'black', 'true')
  124.     stop ()
  125. endfor
  126. *
  127. *
  128. * Now we decode multiple bar code types correctly
  129. *
  130. MixedScanAllExceptRSS_UPC := false
  131. if (MixedScanAllExceptRSS_UPC)
  132.     *
  133.     * We could scan for all bar codes except certain bar code
  134.     * families...
  135.     get_param_info ('find_bar_code', 'CodeType', 'value_list', AllCodeTypes)
  136.     NoRSS := '~'+regexp_select (AllCodeTypes, 'RSS.*')
  137.     NoUPC := '~'+regexp_select (AllCodeTypes, 'UPC.*')
  138.     CodeTypes := ['auto', NoRSS, NoUPC]
  139.     CodeTypesDescription := 'auto, ~RSS*, ~UPC*'
  140. else
  141.     *
  142.     * ...or (as we do here) scan only for the EAN family and
  143.     * Code 39
  144.     get_param_info ('find_bar_code', 'CodeType', 'value_list', AllCodeTypes)
  145.     AllEAN := regexp_select (AllCodeTypes, 'EAN.*')
  146.     CodeTypes := [AllEAN, 'Code 39']
  147.     CodeTypesDescription := 'EAN-13*, EAN-8*, Code 39'
  148. endif
  149. *
  150. * Display information for the user
  151. Message := 'Now we demonstrate the usage of'
  152. Message[1] := 'autodiscrimination to decode multiple'
  153. Message[2] := 'mixed bar code types within one image.'
  154. dev_clear_window ()
  155. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  156. disp_continue_message (WindowHandle, 'black', 'true')
  157. stop ()
  158. *
  159. * Demonstrate autodiscrimination for mixed bar code types
  160. for IdxIma := 0 to |ExampleImagesMixed|-1 by 1
  161.     FileName := ExampleImagesMixed[IdxIma]
  162.     read_image (Image, FileName)
  163.     *
  164.     * Display image and description
  165.     get_image_size (Image, Width, Height)
  166.     dev_set_window_extents (-1, -1, Width/2, Height/2)
  167.     dev_display (Image)
  168.     disp_message (WindowHandle, ['Looking for bar code(s) of type:', ' ' + CodeTypesDescription], 'window', 12, 12, 'black', 'true')
  169.     *
  170.     * Decode mixed bar codes
  171.     find_bar_code (Image, SymbolRegions, BarCodeHandle, CodeTypes, DecodedDataStrings)
  172.     *
  173.     * Display decoded data and symbol region
  174.     dev_set_color ('forest green')
  175.     dev_display (SymbolRegions)
  176.     get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', DecodedDataTypes)
  177.     area_center (SymbolRegions, Area, Rows, Columns)
  178.     for IdxResult := 0 to |DecodedDataStrings|-1 by 1
  179.         disp_message (WindowHandle, DecodedDataTypes[IdxResult]+': '+DecodedDataStrings[IdxResult], 'image', Rows[IdxResult], Columns[IdxResult]-160, 'forest green', 'true')
  180.     endfor
  181.     if (IdxIma # |ExampleImagesMixed|-1)
  182.         disp_continue_message (WindowHandle, 'black', 'true')
  183.         stop ()
  184.     endif
  185. endfor
  186. *
  187. * Close the bar code reader
  188. clear_bar_code_model (BarCodeHandle)
复制代码
QQ截图20170117095049.png

 楼主| icework 发表于 2017-1-18 08:43:12 | 显示全部楼层
这些都是halcon封装好的接口和调用了,没有原理性的内容呀
大神们,有原理性的资料么?
jash 发表于 2019-9-18 15:31:21 | 显示全部楼层
關於參考資料可以試試說明中的References
例如:GS1 General Specifications; Version 12; Issue 1, Jan-2012; GS1.
希望有所幫助
高级模式
B Color Image Link Quote Code Smilies

本版积分规则

快速回复 返回顶部 返回列表