Halcon一维码和二维码识别

Halcon一维码和二维码识别

一.Halcon一维码识别

1.一维码的识别过程:

(1).创建条码模型create_bar_code_model创建一个通用模型,用于读取所有支持类型的条码。
(2).设置参数set_bar_code_param设置条码搜索参数,当要设置多个参数时候需要用到。
(3).搜索条形码,并解码find_bar_code得出条码字符串。
(4).可以通过get_bar_code_result得到相关结果。
(5).清除条码模型clear_bar_code_model 清除内存,识别句柄将不能使用。

2.算子参数:

(1). create_bar_code_model( : : GenParamName, GenParamValue : BarCodeHandle)

Ⅰ. GenParamName (输入可以为条形码模型调整的通用参数的名称)
默认值: []
列表值: ‘barcode_height_min’, ‘barcode_width_max’, ‘barcode_width_min’, ‘check_char’, ‘composite_code’, ‘element_size_max’, ‘element_size_min’, ‘element_size_variable’, ‘meas_thresh’, ‘meas_thresh_abs’, ‘min_code_length’, ‘min_identical_scanlines’, ‘num_scanlines’, ‘orientation’, ‘orientation_tol’, ‘persistence’, ‘quiet_zone’, ‘start_stop_tolerance’, ‘stop_after_result_num’, ‘timeout’, ‘train’, ‘upce_encodation’
Ⅱ. GenParamValue (输入可以为条形码模型调整的通用参数的值)
默认值: []
建议值: 0, 0.1, 1, 1.5, 2, 8, 32, 45, ‘present’, ‘absent’, ‘none’, ‘CC-A/B’, ‘auto’, ‘high’, ‘low’, ‘true’, ‘false’
Ⅲ. BarCodeHandle (输出用于使用和访问条形码模型的句柄)
2).set_bar_code_param( : : BarCodeHandle, GenParamName, GenParamValue : )

Ⅰ. BarCodeHandle (输入条码模型的句柄)
Ⅱ. GenParamName (输入为查找和解码条形码而应调整的通用参数的名称)
默认值: ‘element_size_min’
列表值: ‘abort’, ‘barcode_height_min’, ‘barcode_width_max’, ‘barcode_width_min’, ‘check_char’, ‘composite_code’, ‘contrast_min’, ‘element_size_max’, ‘element_size_min’, ‘element_size_variable’, ‘majority_voting’, ‘meas_thresh’, ‘meas_thresh_abs’, ‘merge_scanlines’, ‘min_code_length’, ‘min_identical_scanlines’, ‘num_scanlines’, ‘orientation’, ‘orientation_tol’, ‘persistence’, ‘quality_isoiec15416_reflectance_reference’, ‘quiet_zone’, ‘small_elements_robustness’, ‘start_stop_tolerance’, ‘stop_after_result_num’, ‘timeout’, ‘train’, ‘upce_encodation’
Ⅲ. GenParamValue (输入为查找和解码条形码而调整的通用参数的值)
默认值: 8
建议值: 0, 0.1, 1, 1.5, 2, 8, 32, 45, ‘true’, ‘false’, ‘present’, ‘absent’, ‘none’, ‘CC-A/B’, ‘auto’, ‘high’, ‘low’, ‘ucc-12’, ‘zero-suppressed’
(3).find_bar_code(Image : SymbolRegions : BarCodeHandle, CodeType : DecodedDataStrings)

Ⅰ. Image (输入单通道图像) 如果图像具有缩小的域,则条形码搜索将缩小到该域。这通常会减少操作员的运行时间。但是,如果条形码未完全在域内,则无法正确解码条形码。
Ⅱ. SymbolRegions (输出成功解码的条码符号的区域)
Ⅲ. BarCodeHandle (输入条码模型的句柄)
Ⅳ. CodeType (输入搜索条码的类型)在不知条码类型时候可以使用’auto’可支持识别
列表值: ‘2/5 Industrial’, ‘2/5 Interleaved’, ‘Codabar’, ‘Code 128’, ‘Code 39’, ‘Code 93’, ‘EAN-13 Add-On 2’, ‘EAN-13 Add-On 5’, ‘EAN-13’, ‘EAN-8 Add-On 2’, ‘EAN-8 Add-On 5’, ‘EAN-8’, ‘GS1 DataBar Expanded Stacked’, ‘GS1 DataBar Expanded’, ‘GS1 DataBar Limited’, ‘GS1 DataBar Omnidir’, ‘GS1 DataBar Stacked Omnidir’, ‘GS1 DataBar Stacked’, ‘GS1 DataBar Truncated’, ‘GS1-128’, ‘MSI’, ‘PharmaCode’, ‘UPC-A Add-On 2’, ‘UPC-A Add-On 5’, ‘UPC-A’, ‘UPC-E Add-On 2’, ‘UPC-E Add-On 5’, ‘UPC-E’, ‘auto’
Ⅴ. DecodedDataStrings (输出所有成功解码的条码的数据串)
4).Cget_bar_code_result( : : BarCodeHandle, CandidateHandle, ResultName : BarCodeResults)

Ⅰ. BarCodeHandle (输入条码模型的句柄)
Ⅱ. CandidateHandle 输入分别指示需要数据的条码结果候选)一般为all
Ⅲ. ResultName (输入要返回的结果数据的名称)
Ⅳ. BarCodeResults (输出最终结果)
(5).clear_bar_code_model( : : BarCodeHandle : )

Ⅰ. BarCodeHandle (输入条码模型的句柄)

实例:

read_image (Image, 'barcode/ean13/ean1305')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*
create_bar_code_model ('element_size_min', 1.5, BarCodeHandle)
*要设置其他参数时候使用
*set_bar_code_param (BarCodeHandle, 'element_size_min', 8)
for Rot := 0 to 360 by 30
    rotate_image (Image, ImageRotate, Rot, 'weighted')
    dev_display (ImageRotate)
    get_image_size (ImageRotate, Width, Height)
    dev_set_window_extents (0, 0, Width, Height)
    find_bar_code (ImageRotate, SymbolRegions, BarCodeHandle, 'EAN-13', DecodedDataStrings)
    dev_display (SymbolRegions)
    get_bar_code_result (BarCodeHandle, 'all', 'orientation', Orientation)
    area_center (SymbolRegions, Area, Row, Col)
    gen_arrow_contour_xld (Arrow, Row + sin(rad(Orientation)) * 70, Col - cos(rad(Orientation)) * 70, Row - sin(rad(Orientation)) * 70, Col + cos(rad(Orientation)) * 70, 25, 25)
    dev_display (Arrow)
    disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true')
    if (Rot < 360)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
clear_bar_code_model (BarCodeHandle)

效果图:

Halcon一维码和二维码识别

二.Halcon二维码识别

  1. 二维码识别过程

(1).创建二维码模型create_data_code_2d_model,用于读取支持类型的二维码。
(2).设置识别二维码参数set_data_code_2d_param当要设置多个参数时候需要用到。
(3).搜索条码,并解码find_data_code_2d。
(4).清除条码模型clear_data_code_2d_model清除内存。

2.算子参数:

(1).create_data_code_2d_model( : : SymbolType, GenParamName, GenParamValue : DataCodeHandle)

Ⅰ. SymbolType (输入二维数据代码的类型)
列表值: ‘Aztec Code’, ‘Data Matrix ECC 200’, ‘DotCode’, ‘GS1 Aztec Code’, ‘GS1 DataMatrix’, ‘GS1 DotCode’, ‘GS1 QR Code’, ‘Micro QR Code’, ‘PDF417’, ‘QR Code’
Ⅱ. GenParamName (输入可以为 2D 数据代码模型调整的通用参数的名称)
默认值: []
列表值: ‘additional_levels’, ‘candidate_selection’, ‘contrast_min’, ‘contrast_tolerance’, ‘default_parameters’, ‘finder_pattern_tolerance’, ‘mirrored’, ‘model_type’, ‘module_aspect’, ‘module_aspect_max’, ‘module_aspect_min’, ‘module_gap’, ‘module_gap_max’, ‘module_gap_min’, ‘module_grid’, ‘module_size’, ‘module_size_max’, ‘module_size_min’, ‘module_width’, ‘module_width_max’, ‘module_width_min’, ‘persistence’, ‘polarity’, ‘position_pattern_min’, ‘slant_max’, ‘small_modules_robustness’, ‘strict_model’, ‘strict_quiet_zone’, ‘symbol_cols’, ‘symbol_cols_max’, ‘symbol_cols_min’, ‘symbol_rows’, ‘symbol_rows_max’, ‘symbol_rows_min’, ‘symbol_shape’, ‘symbol_size’, ‘symbol_size_max’, ‘symbol_size_min’, ‘timeout’, ‘version’, ‘version_max’, ‘version_min’
Ⅲ. GenParamValue (输入可以为 2D 数据代码模型调整的通用参数的值)
默认值: []
建议值: ‘standard_recognition’, ‘enhanced_recognition’, ‘maximum_recognition’, ‘yes’, ‘no’, ‘any’, ‘dark_on_light’, ‘light_on_dark’, ‘square’, ‘rectangle’, ‘small’, ‘big’, ‘fixed’, ‘variable’, ‘low’, ‘high’, ‘default’, ‘extensive’, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 30, 50, 70, 90, 12, 14, 16, 18, 20, 22, 24, 26, 32, 36, 40, 44, 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144
Ⅳ. DataCodeHandle (输出用于使用和访问二维数据代码模型的句柄)
(2).set_data_code_2d_param( : : DataCodeHandle, GenParamName, GenParamValue : )

Ⅰ. DataCodeHandle(输入二维数据代码模型的句柄)
Ⅱ. GenParamName(输入为 2D 数据代码调整的通用参数的名称)
默认值: ‘polarity’
列表值: ‘abort’, ‘additional_levels’, ‘candidate_selection’, ‘contrast_min’, ‘contrast_tolerance’, ‘decoding_scheme’, ‘default_parameters’, ‘discard_undecoded_candidates’, ‘finder_pattern_tolerance’, ‘format’, ‘max_allowed_error_correction’, ‘mirrored’, ‘model_type’, ‘module_aspect’, ‘module_aspect_max’, ‘module_aspect_min’, ‘module_gap’, ‘module_gap_max’, ‘module_gap_min’, ‘module_grid’, ‘module_size’, ‘module_size_max’, ‘module_size_min’, ‘module_width’, ‘module_width_max’, ‘module_width_min’, ‘persistence’, ‘polarity’, ‘position_pattern_min’, ‘quality_isoiec15415_aperture_size’, ‘quality_isoiec15415_reflectance_reference’, ‘slant_max’, ‘small_modules_robustness’, ‘strict_model’, ‘strict_quiet_zone’, ‘string_encoding’, ‘symbol_cols’, ‘symbol_cols_max’, ‘symbol_cols_min’, ‘symbol_rows’, ‘symbol_rows_max’, ‘symbol_rows_min’, ‘symbol_shape’, ‘symbol_size’, ‘symbol_size_max’, ‘symbol_size_min’, ‘timeout’, ‘trained’, ‘version’, ‘version_max’, ‘version_min’
Ⅲ. GenParamValue (输入为 2D 数据代码调整的通用参数的值)
默认值: ‘light_on_dark’
建议值: ‘standard_recognition’, ‘enhanced_recognition’, ‘maximum_recognition’, ‘yes’, ‘no’, ‘any’, ‘dark_on_light’, ‘light_on_dark’, ‘square’, ‘rectangle’, ‘small’, ‘big’, ‘fixed’, ‘variable’, ‘low’, ‘high’, ‘default’, ‘extensive’, ‘utf8’, ‘locale’, ‘raw’, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 30, 50, 70, 90, 12, 14, 16, 18, 20, 22, 24, 26, 32, 36, 40, 44, 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144
(3).find_data_code_2d(Image : SymbolXLDs : DataCodeHandle, GenParamName, GenParamValue : ResultHandles, DecodedDataStrings)

Ⅰ. Image (输入单通输入图像)
Ⅱ. SymbolXLDs (输出围绕成功解码的数据代码符号的 XLD 轮廓,轮廓点的顺序反映了检测符号的方向)
Ⅲ. DataCodeHandle (输入二维数据代码模型的句柄)
Ⅳ. GenParamName(输入用于控制操作员行为的(可选)参数的名称)
默认值: []
值列表:‘specific_parallelization’、’stop_after_result_num’、’symbol_search’、’train’
Ⅴ. GenParamValue (输入可选泛型参数的值)
默认值: []
建议值:‘all’, ‘model_type’, ‘symbol_size’, ‘version’, ‘module_size’, ‘small_modules_robustness’, ‘module_shape’, ‘polarity’, ‘mirrored’, ‘contrast’, ‘candidate_selection’, ‘module_grid’, ‘finder_pattern_tolerance’, ‘contrast_tolerance’, ‘additional_levels’, ‘image_proc’, ‘rudimental’, ‘default’, ‘exhaustive’, 1, 2, 3, ‘enable’, ‘disable’
Ⅵ. ResultHandles (输出所有成功解码的二维数据代码符号的句柄)
Ⅶ. DecodedDataStrings(输出图像中所有检测到的二维数据码符号的解码数据串)
(4).clear_data_code_2d_model( : : DataCodeHandle : )

Ⅰ. DataCodeHandle (输入二维数据代码模型的句柄)

实例:

dev_update_off ()
dev_close_window ()
list_image_files ('datacode/aztec', 'default', [], ImageFiles)
ImageFiles := regexp_select(ImageFiles,'(smartphone)|(ticket)|(ticket_machine)')
read_image (Image, ImageFiles[0])
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_color ('green')
stop ()
create_data_code_2d_model ('Aztec Code', [], [], DataCodeHandle)
set_data_code_2d_param (DataCodeHandle, ['module_size_min', 'module_size_max'], [3, 11])
set_data_code_2d_param (DataCodeHandle, 'module_gap', 'no')
set_data_code_2d_param (DataCodeHandle, 'polarity', 'any')
set_data_code_2d_param (DataCodeHandle, 'mirrored', 'no')
set_data_code_2d_param (DataCodeHandle, 'contrast_min', 20)
set_data_code_2d_param (DataCodeHandle, 'symbol_size_min', 19)
set_data_code_2d_param (DataCodeHandle, 'symbol_size_max', 143)
set_data_code_2d_param (DataCodeHandle, 'small_modules_robustness', 'high')
set_data_code_2d_param (DataCodeHandle, 'finder_pattern_tolerance', 'high')
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])
    dev_display (Image)
    *
    * Find and decode the data codes and measure the runtime.

    count_seconds (T1)
    find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
    count_seconds (T2)
    Time := 1000 * (T2 - T1)
    *
    * Display the results.

    TitleMessage := 'Image ' + (Index + 1) + ' of ' + |ImageFiles|
    ResultMessage := 'Data code found in ' + Time$'.1f' + ' ms'
    display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, ResultMessage, 'forest green', 'black')
    if (Index < |ImageFiles| - 1)
        dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
        stop ()
    endif
endfor
clear_data_code_2d_model (DataCodeHandle)

效果图:

Halcon一维码和二维码识别

Original: https://blog.csdn.net/qq_41234432/article/details/124501259
Author: 视觉小辰
Title: Halcon一维码和二维码识别

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/519448/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球